@adonisjs/http-server 7.6.1 → 8.0.0-next.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/chunk-ASX56VAK.js +76 -0
- package/build/{chunk-7AGINHO3.js → chunk-VYBTM3NC.js} +1025 -607
- package/build/client.cjs +232 -0
- package/build/client.d.cts +258 -0
- package/build/client.d.ts +258 -0
- package/build/client.js +229 -0
- package/build/factories/http_server.d.ts +1 -1
- package/build/factories/main.d.ts +3 -3
- package/build/factories/main.js +89 -89
- package/build/factories/request.d.ts +1 -1
- package/build/factories/response.d.ts +2 -2
- package/build/factories/url_builder_factory.d.ts +25 -0
- package/build/index.d.ts +3 -2
- package/build/index.js +25 -23
- package/build/src/client/main.d.ts +3 -0
- package/build/src/client/router.d.ts +68 -0
- package/build/src/client/types.d.ts +181 -0
- package/build/src/client/url_builder.d.ts +13 -0
- package/build/src/cookies/client.d.ts +2 -2
- package/build/src/cookies/parser.d.ts +2 -2
- package/build/src/cookies/serializer.d.ts +7 -1
- package/build/src/define_middleware.d.ts +3 -2
- package/build/src/{exceptions.d.ts → errors.d.ts} +13 -1
- package/build/src/exception_handler.d.ts +2 -2
- package/build/src/helpers.d.ts +51 -15
- package/build/src/helpers.js +18 -0
- package/build/src/http_context/main.d.ts +3 -3
- package/build/src/qs.d.ts +3 -3
- package/build/src/redirect.d.ts +3 -2
- package/build/src/request.d.ts +10 -9
- package/build/src/response.d.ts +1 -1
- package/build/src/router/brisk.d.ts +4 -3
- package/build/src/router/executor.d.ts +2 -2
- package/build/src/router/factories/use_return_value.d.ts +6 -1
- package/build/src/router/group.d.ts +4 -4
- package/build/src/router/{lookup_store → legacy}/url_builder.d.ts +20 -4
- package/build/src/router/main.d.ts +52 -12
- package/build/src/router/resource.d.ts +4 -3
- package/build/src/router/route.d.ts +3 -2
- package/build/src/router/signed_url_builder.d.ts +14 -0
- package/build/src/router/store.d.ts +3 -2
- package/build/src/server/factories/middleware_handler.d.ts +3 -3
- package/build/src/server/factories/{final_handler.d.ts → route_finder.d.ts} +2 -2
- package/build/src/server/main.d.ts +7 -3
- package/build/src/tracing_channels.d.ts +23 -0
- package/build/src/types/main.d.ts +7 -7
- package/build/src/types/main.js +0 -1
- package/build/src/types/middleware.d.ts +34 -1
- package/build/src/types/request.d.ts +4 -0
- package/build/src/types/response.d.ts +1 -1
- package/build/src/types/route.d.ts +50 -51
- package/build/src/types/server.d.ts +1 -1
- package/build/src/types/tracing_channels.d.ts +6 -0
- package/build/src/utils.d.ts +28 -0
- package/package.json +60 -48
- package/build/chunk-7AGINHO3.js.map +0 -1
- package/build/factories/main.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/src/router/lookup_store/main.d.ts +0 -48
- package/build/src/router/lookup_store/route_finder.d.ts +0 -25
- package/build/src/router/parser.d.ts +0 -5
- package/build/src/types/base.d.ts +0 -19
- package/build/src/types/main.js.map +0 -1
package/build/factories/main.js
CHANGED
|
@@ -6,16 +6,11 @@ import {
|
|
|
6
6
|
Router,
|
|
7
7
|
Server,
|
|
8
8
|
defineConfig
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-VYBTM3NC.js";
|
|
10
|
+
import "../chunk-ASX56VAK.js";
|
|
10
11
|
|
|
11
|
-
// factories/
|
|
12
|
-
import {
|
|
13
|
-
import { LoggerFactory } from "@adonisjs/logger/factories";
|
|
14
|
-
|
|
15
|
-
// factories/request.ts
|
|
16
|
-
import { Socket } from "node:net";
|
|
17
|
-
import proxyAddr from "proxy-addr";
|
|
18
|
-
import { IncomingMessage, ServerResponse } from "node:http";
|
|
12
|
+
// factories/router.ts
|
|
13
|
+
import { AppFactory } from "@adonisjs/application/factories";
|
|
19
14
|
import { EncryptionFactory } from "@adonisjs/encryption/factories";
|
|
20
15
|
|
|
21
16
|
// factories/qs_parser_factory.ts
|
|
@@ -51,7 +46,43 @@ var QsParserFactory = class {
|
|
|
51
46
|
}
|
|
52
47
|
};
|
|
53
48
|
|
|
49
|
+
// factories/router.ts
|
|
50
|
+
var RouterFactory = class {
|
|
51
|
+
#parameters = {};
|
|
52
|
+
/**
|
|
53
|
+
* Returns an instance of the application class
|
|
54
|
+
*/
|
|
55
|
+
#getApp() {
|
|
56
|
+
return this.#parameters.app || new AppFactory().create(new URL("./app/", import.meta.url));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns an instance of the encryptor to encrypt
|
|
60
|
+
* signed URLs
|
|
61
|
+
*/
|
|
62
|
+
#createEncryption() {
|
|
63
|
+
return this.#parameters.encryption || new EncryptionFactory().create();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Merge factory params
|
|
67
|
+
*/
|
|
68
|
+
merge(params) {
|
|
69
|
+
Object.assign(this.#parameters, params);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create router instance
|
|
74
|
+
*/
|
|
75
|
+
create() {
|
|
76
|
+
return new Router(this.#getApp(), this.#createEncryption(), new QsParserFactory().create());
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
54
80
|
// factories/request.ts
|
|
81
|
+
import { Socket } from "net";
|
|
82
|
+
import proxyAddr from "proxy-addr";
|
|
83
|
+
import { randomUUID } from "crypto";
|
|
84
|
+
import { IncomingMessage, ServerResponse } from "http";
|
|
85
|
+
import { EncryptionFactory as EncryptionFactory2 } from "@adonisjs/encryption/factories";
|
|
55
86
|
var RequestFactory = class {
|
|
56
87
|
#parameters = {};
|
|
57
88
|
/**
|
|
@@ -63,6 +94,9 @@ var RequestFactory = class {
|
|
|
63
94
|
trustProxy: proxyAddr.compile("loopback"),
|
|
64
95
|
subdomainOffset: 2,
|
|
65
96
|
generateRequestId: false,
|
|
97
|
+
createRequestId() {
|
|
98
|
+
return randomUUID();
|
|
99
|
+
},
|
|
66
100
|
...this.#parameters.config
|
|
67
101
|
};
|
|
68
102
|
}
|
|
@@ -90,7 +124,7 @@ var RequestFactory = class {
|
|
|
90
124
|
* signed URLs
|
|
91
125
|
*/
|
|
92
126
|
#createEncryption() {
|
|
93
|
-
return this.#parameters.encryption || new
|
|
127
|
+
return this.#parameters.encryption || new EncryptionFactory2().create();
|
|
94
128
|
}
|
|
95
129
|
/**
|
|
96
130
|
* Merge factory params
|
|
@@ -115,44 +149,9 @@ var RequestFactory = class {
|
|
|
115
149
|
};
|
|
116
150
|
|
|
117
151
|
// factories/response.ts
|
|
118
|
-
import { Socket as Socket2 } from "
|
|
119
|
-
import { IncomingMessage as IncomingMessage2, ServerResponse as ServerResponse2 } from "
|
|
152
|
+
import { Socket as Socket2 } from "net";
|
|
153
|
+
import { IncomingMessage as IncomingMessage2, ServerResponse as ServerResponse2 } from "http";
|
|
120
154
|
import { EncryptionFactory as EncryptionFactory3 } from "@adonisjs/encryption/factories";
|
|
121
|
-
|
|
122
|
-
// factories/router.ts
|
|
123
|
-
import { AppFactory } from "@adonisjs/application/factories";
|
|
124
|
-
import { EncryptionFactory as EncryptionFactory2 } from "@adonisjs/encryption/factories";
|
|
125
|
-
var RouterFactory = class {
|
|
126
|
-
#parameters = {};
|
|
127
|
-
/**
|
|
128
|
-
* Returns an instance of the application class
|
|
129
|
-
*/
|
|
130
|
-
#getApp() {
|
|
131
|
-
return this.#parameters.app || new AppFactory().create(new URL("./app/", import.meta.url));
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Returns an instance of the encryptor to encrypt
|
|
135
|
-
* signed URLs
|
|
136
|
-
*/
|
|
137
|
-
#createEncryption() {
|
|
138
|
-
return this.#parameters.encryption || new EncryptionFactory2().create();
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Merge factory params
|
|
142
|
-
*/
|
|
143
|
-
merge(params) {
|
|
144
|
-
Object.assign(this.#parameters, params);
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Create router instance
|
|
149
|
-
*/
|
|
150
|
-
create() {
|
|
151
|
-
return new Router(this.#getApp(), this.#createEncryption(), new QsParserFactory().create());
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// factories/response.ts
|
|
156
155
|
var ResponseFactory = class {
|
|
157
156
|
#parameters = {};
|
|
158
157
|
/**
|
|
@@ -220,47 +219,6 @@ var ResponseFactory = class {
|
|
|
220
219
|
}
|
|
221
220
|
};
|
|
222
221
|
|
|
223
|
-
// factories/http_context.ts
|
|
224
|
-
var HttpContextFactory = class {
|
|
225
|
-
#parameters = {};
|
|
226
|
-
/**
|
|
227
|
-
* Returns the request class instance
|
|
228
|
-
*/
|
|
229
|
-
#createRequest() {
|
|
230
|
-
return this.#parameters.request || new RequestFactory().create();
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Returns the response class instance
|
|
234
|
-
*/
|
|
235
|
-
#createResponse() {
|
|
236
|
-
return this.#parameters.response || new ResponseFactory().create();
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Returns an instance of the logger class
|
|
240
|
-
*/
|
|
241
|
-
#createLogger() {
|
|
242
|
-
return this.#parameters.logger || new LoggerFactory().create();
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Merge factory params
|
|
246
|
-
*/
|
|
247
|
-
merge(params) {
|
|
248
|
-
Object.assign(this.#parameters, params);
|
|
249
|
-
return this;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Create request
|
|
253
|
-
*/
|
|
254
|
-
create() {
|
|
255
|
-
return new HttpContext(
|
|
256
|
-
this.#createRequest(),
|
|
257
|
-
this.#createResponse(),
|
|
258
|
-
this.#createLogger(),
|
|
259
|
-
new Container().createResolver()
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
|
|
264
222
|
// factories/server_factory.ts
|
|
265
223
|
import { Logger } from "@adonisjs/logger";
|
|
266
224
|
import { Emitter } from "@adonisjs/events";
|
|
@@ -319,6 +277,49 @@ var ServerFactory = class {
|
|
|
319
277
|
);
|
|
320
278
|
}
|
|
321
279
|
};
|
|
280
|
+
|
|
281
|
+
// factories/http_context.ts
|
|
282
|
+
import { Container } from "@adonisjs/fold";
|
|
283
|
+
import { LoggerFactory } from "@adonisjs/logger/factories";
|
|
284
|
+
var HttpContextFactory = class {
|
|
285
|
+
#parameters = {};
|
|
286
|
+
/**
|
|
287
|
+
* Returns the request class instance
|
|
288
|
+
*/
|
|
289
|
+
#createRequest() {
|
|
290
|
+
return this.#parameters.request || new RequestFactory().create();
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Returns the response class instance
|
|
294
|
+
*/
|
|
295
|
+
#createResponse() {
|
|
296
|
+
return this.#parameters.response || new ResponseFactory().create();
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Returns an instance of the logger class
|
|
300
|
+
*/
|
|
301
|
+
#createLogger() {
|
|
302
|
+
return this.#parameters.logger || new LoggerFactory().create();
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Merge factory params
|
|
306
|
+
*/
|
|
307
|
+
merge(params) {
|
|
308
|
+
Object.assign(this.#parameters, params);
|
|
309
|
+
return this;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Create request
|
|
313
|
+
*/
|
|
314
|
+
create() {
|
|
315
|
+
return new HttpContext(
|
|
316
|
+
this.#createRequest(),
|
|
317
|
+
this.#createResponse(),
|
|
318
|
+
this.#createLogger(),
|
|
319
|
+
new Container().createResolver()
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
322
323
|
export {
|
|
323
324
|
HttpContextFactory,
|
|
324
325
|
QsParserFactory,
|
|
@@ -327,4 +328,3 @@ export {
|
|
|
327
328
|
RouterFactory,
|
|
328
329
|
ServerFactory
|
|
329
330
|
};
|
|
330
|
-
//# sourceMappingURL=main.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Encryption } from '@adonisjs/encryption';
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
3
|
import { Request } from '../src/request.js';
|
|
4
|
-
import { RequestConfig } from '../src/types/request.js';
|
|
4
|
+
import { type RequestConfig } from '../src/types/request.js';
|
|
5
5
|
type FactoryParameters = {
|
|
6
6
|
url: string;
|
|
7
7
|
method: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Encryption } from '@adonisjs/encryption';
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
3
|
import { Response } from '../src/response.js';
|
|
4
|
-
import { Router } from '../src/router/main.js';
|
|
5
|
-
import { ResponseConfig } from '../src/types/response.js';
|
|
4
|
+
import { type Router } from '../src/router/main.js';
|
|
5
|
+
import { type ResponseConfig } from '../src/types/response.js';
|
|
6
6
|
type FactoryParameters = {
|
|
7
7
|
req: IncomingMessage;
|
|
8
8
|
res: ServerResponse;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Encryption } from '@adonisjs/encryption';
|
|
2
|
+
import type { Router } from '../src/router/main.ts';
|
|
3
|
+
import { type LookupList } from '../src/client/types.ts';
|
|
4
|
+
type FactoryParameters = {
|
|
5
|
+
router: Router;
|
|
6
|
+
encryption: Encryption;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* URLBuilderFactory is used to create route and signed route helpers
|
|
10
|
+
*/
|
|
11
|
+
export declare class URLBuilderFactory<Routes extends LookupList> {
|
|
12
|
+
#private;
|
|
13
|
+
/**
|
|
14
|
+
* Merge factory params
|
|
15
|
+
*/
|
|
16
|
+
merge(params: Partial<FactoryParameters>): this;
|
|
17
|
+
/**
|
|
18
|
+
* Create URL builder helpers
|
|
19
|
+
*/
|
|
20
|
+
create(): {
|
|
21
|
+
urlFor: import("../src/client/types.ts").UrlFor<Routes>;
|
|
22
|
+
signedUrlFor: import("../src/client/types.ts").UrlFor<Routes, import("../src/client/types.ts").SignedURLOptions>;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export {};
|
package/build/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
export * as errors from './src/errors.js';
|
|
1
2
|
export { Request } from './src/request.js';
|
|
2
3
|
export { Response } from './src/response.js';
|
|
3
|
-
export { ResponseStatus } from './src/response_status.js';
|
|
4
4
|
export { Redirect } from './src/redirect.js';
|
|
5
5
|
export { Server } from './src/server/main.js';
|
|
6
6
|
export { Router } from './src/router/main.js';
|
|
7
7
|
export { Route } from './src/router/route.js';
|
|
8
|
-
export * as errors from './src/exceptions.js';
|
|
9
8
|
export { BriskRoute } from './src/router/brisk.js';
|
|
10
9
|
export { RouteGroup } from './src/router/group.js';
|
|
11
10
|
export { defineConfig } from './src/define_config.js';
|
|
12
11
|
export { CookieClient } from './src/cookies/client.js';
|
|
13
12
|
export { HttpContext } from './src/http_context/main.js';
|
|
14
13
|
export { RouteResource } from './src/router/resource.js';
|
|
14
|
+
export { ResponseStatus } from './src/response_status.js';
|
|
15
15
|
export { ExceptionHandler } from './src/exception_handler.js';
|
|
16
|
+
export * as tracingChannels from './src/tracing_channels.js';
|
package/build/index.js
CHANGED
|
@@ -15,10 +15,13 @@ import {
|
|
|
15
15
|
RouteResource,
|
|
16
16
|
Router,
|
|
17
17
|
Server,
|
|
18
|
+
canWriteResponseBody,
|
|
18
19
|
defineConfig,
|
|
19
|
-
|
|
20
|
-
parseRange
|
|
21
|
-
|
|
20
|
+
errors_exports,
|
|
21
|
+
parseRange,
|
|
22
|
+
tracing_channels_exports
|
|
23
|
+
} from "./chunk-VYBTM3NC.js";
|
|
24
|
+
import "./chunk-ASX56VAK.js";
|
|
22
25
|
|
|
23
26
|
// src/exception_handler.ts
|
|
24
27
|
import is from "@sindresorhus/is";
|
|
@@ -149,9 +152,9 @@ var ExceptionHandler = class extends Macroable {
|
|
|
149
152
|
*/
|
|
150
153
|
async renderErrorAsJSON(error, ctx) {
|
|
151
154
|
if (this.isDebuggingEnabled(ctx)) {
|
|
152
|
-
const {
|
|
153
|
-
const json = await new Youch(
|
|
154
|
-
ctx.response.status(error.status).send(json
|
|
155
|
+
const { Youch } = await import("youch");
|
|
156
|
+
const json = await new Youch().toJSON(error);
|
|
157
|
+
ctx.response.status(error.status).send(json);
|
|
155
158
|
return;
|
|
156
159
|
}
|
|
157
160
|
ctx.response.status(error.status).send({ message: error.message });
|
|
@@ -161,9 +164,9 @@ var ExceptionHandler = class extends Macroable {
|
|
|
161
164
|
*/
|
|
162
165
|
async renderErrorAsJSONAPI(error, ctx) {
|
|
163
166
|
if (this.isDebuggingEnabled(ctx)) {
|
|
164
|
-
const {
|
|
165
|
-
const json = await new Youch(
|
|
166
|
-
ctx.response.status(error.status).send(json
|
|
167
|
+
const { Youch } = await import("youch");
|
|
168
|
+
const json = await new Youch().toJSON(error);
|
|
169
|
+
ctx.response.status(error.status).send(json);
|
|
167
170
|
return;
|
|
168
171
|
}
|
|
169
172
|
ctx.response.status(error.status).send({
|
|
@@ -180,9 +183,18 @@ var ExceptionHandler = class extends Macroable {
|
|
|
180
183
|
* Renders an error to HTML response
|
|
181
184
|
*/
|
|
182
185
|
async renderErrorAsHTML(error, ctx) {
|
|
186
|
+
const statusPages = this.#expandStatusPages();
|
|
187
|
+
if (this.renderStatusPages && statusPages[error.status]) {
|
|
188
|
+
const statusPageResponse = await statusPages[error.status](error, ctx);
|
|
189
|
+
if (canWriteResponseBody(statusPageResponse, ctx)) {
|
|
190
|
+
return ctx.response.safeStatus(error.status).send(statusPageResponse);
|
|
191
|
+
}
|
|
192
|
+
return statusPageResponse;
|
|
193
|
+
}
|
|
183
194
|
if (this.isDebuggingEnabled(ctx)) {
|
|
184
|
-
const {
|
|
185
|
-
const html = await new Youch(
|
|
195
|
+
const { Youch } = await import("youch");
|
|
196
|
+
const html = await new Youch().toHTML(error, {
|
|
197
|
+
request: ctx.request.request,
|
|
186
198
|
cspNonce: "nonce" in ctx.response ? ctx.response.nonce : void 0
|
|
187
199
|
});
|
|
188
200
|
ctx.response.status(error.status).send(html);
|
|
@@ -288,16 +300,6 @@ var ExceptionHandler = class extends Macroable {
|
|
|
288
300
|
if (httpError.code === "E_VALIDATION_ERROR" && "messages" in httpError) {
|
|
289
301
|
return this.renderValidationError(httpError, ctx);
|
|
290
302
|
}
|
|
291
|
-
const statusPages = this.#expandStatusPages();
|
|
292
|
-
if (this.renderStatusPages && statusPages[httpError.status]) {
|
|
293
|
-
const statusPageResponse = await statusPages[httpError.status](httpError, ctx);
|
|
294
|
-
if (statusPageResponse !== void 0 && // Return value is explicitly defined
|
|
295
|
-
!ctx.response.hasLazyBody && // Lazy body is not set
|
|
296
|
-
statusPageResponse !== ctx.response) {
|
|
297
|
-
return ctx.response.safeStatus(httpError.status).send(statusPageResponse);
|
|
298
|
-
}
|
|
299
|
-
return statusPageResponse;
|
|
300
|
-
}
|
|
301
303
|
return this.renderError(httpError, ctx);
|
|
302
304
|
}
|
|
303
305
|
};
|
|
@@ -316,6 +318,6 @@ export {
|
|
|
316
318
|
Router,
|
|
317
319
|
Server,
|
|
318
320
|
defineConfig,
|
|
319
|
-
|
|
321
|
+
errors_exports as errors,
|
|
322
|
+
tracing_channels_exports as tracingChannels
|
|
320
323
|
};
|
|
321
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types shared with the client. These should never import other types
|
|
3
|
+
*/
|
|
4
|
+
import { type Prettify } from '@poppinss/utils/types';
|
|
5
|
+
/**
|
|
6
|
+
* Options accepted by "url" and "route" helper methods
|
|
7
|
+
*/
|
|
8
|
+
export type URLOptions = {
|
|
9
|
+
qs?: Record<string, any>;
|
|
10
|
+
prefixUrl?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Options accepted by "signedUrl" and "signedRoute" helper methods
|
|
14
|
+
*/
|
|
15
|
+
export type SignedURLOptions = URLOptions & {
|
|
16
|
+
expiresIn?: string | number;
|
|
17
|
+
purpose?: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Returns params for a route identifier
|
|
21
|
+
*/
|
|
22
|
+
export 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']] ? [
|
|
23
|
+
identifier: Identifier,
|
|
24
|
+
params?: Routes[Method][Identifier]['params'] | Routes[Method][Identifier]['paramsTuple'],
|
|
25
|
+
options?: Options
|
|
26
|
+
] : [
|
|
27
|
+
identifier: Identifier,
|
|
28
|
+
params: Routes[Method][Identifier]['params'] | Routes[Method][Identifier]['paramsTuple'],
|
|
29
|
+
options?: Options
|
|
30
|
+
]> : never;
|
|
31
|
+
/**
|
|
32
|
+
* Shape of a route param matcher
|
|
33
|
+
*/
|
|
34
|
+
export type RouteMatcher = {
|
|
35
|
+
match?: RegExp;
|
|
36
|
+
cast?: (value: string) => any;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Route token stored by matchit library
|
|
40
|
+
*/
|
|
41
|
+
export type MatchItRouteToken = RouteMatcher & {
|
|
42
|
+
old: string;
|
|
43
|
+
type: 0 | 1 | 2 | 3;
|
|
44
|
+
val: string;
|
|
45
|
+
end: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Representation of route shared with the client
|
|
49
|
+
*/
|
|
50
|
+
export type ClientRouteJSON = {
|
|
51
|
+
/**
|
|
52
|
+
* A unique name for the route
|
|
53
|
+
*/
|
|
54
|
+
name?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Route URI pattern
|
|
57
|
+
*/
|
|
58
|
+
pattern: string;
|
|
59
|
+
/**
|
|
60
|
+
* HTTP methods, the route responds to.
|
|
61
|
+
*/
|
|
62
|
+
methods: string[];
|
|
63
|
+
/**
|
|
64
|
+
* Route domain
|
|
65
|
+
*/
|
|
66
|
+
domain: string;
|
|
67
|
+
/**
|
|
68
|
+
* Reference to the route handler
|
|
69
|
+
*/
|
|
70
|
+
handler: {
|
|
71
|
+
reference?: any;
|
|
72
|
+
} | Function;
|
|
73
|
+
/**
|
|
74
|
+
* Tokens to be used to construct the route URL
|
|
75
|
+
*/
|
|
76
|
+
tokens: MatchItRouteToken[];
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* LookupList type is used by the URLBuilder to provide
|
|
80
|
+
* type-safety when creating URLs.
|
|
81
|
+
*
|
|
82
|
+
* There is no runtime property that matches this type. Its
|
|
83
|
+
* purely for type-inference.
|
|
84
|
+
*/
|
|
85
|
+
export type LookupList = {
|
|
86
|
+
[method: string]: {
|
|
87
|
+
[identifier: string]: {
|
|
88
|
+
paramsTuple?: [...any[]];
|
|
89
|
+
params?: {
|
|
90
|
+
[name: string]: any;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The urlFor helper is used to make URLs for pre-existing known routes. You can
|
|
97
|
+
* make a URL using the route name, route pattern, or the route controller
|
|
98
|
+
* reference (depends upon enabled lookupStrategies)
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* urlFor('users.show', [1]) // /users/1
|
|
102
|
+
*
|
|
103
|
+
* // Lookup inside a specific domain
|
|
104
|
+
* urlFor('blog.adonisjs.com@posts.show', [1]) // /posts/1
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export type UrlFor<Routes extends LookupList, Options extends any = URLOptions> = (<Identifier extends keyof Routes['ALL'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'ALL', Identifier, Options>) => string) & {
|
|
108
|
+
/**
|
|
109
|
+
* Make URL for a GET route. An error will be raised if the route doesn't
|
|
110
|
+
* exist.
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* urlFor.get('users.show', [1]) // { method: 'get', url: '/users/1' }
|
|
114
|
+
* urlFor.get('users.store', [1]) // Error: Route not found GET@users/store
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
get<RouteIdentifier extends keyof Routes['GET'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'GET', RouteIdentifier, Options>): {
|
|
118
|
+
method: 'get';
|
|
119
|
+
url: string;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Make URL for a POST route. An error will be raised if the route doesn't
|
|
123
|
+
* exist.
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* urlFor.post('users.store') // { method: 'post', url: '/users' }
|
|
127
|
+
* urlFor.post('users.show', [1]) // Error: Route not found POST@users.show
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
post<RouteIdentifier extends keyof Routes['POST'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'POST', RouteIdentifier, Options>): {
|
|
131
|
+
method: 'post';
|
|
132
|
+
url: string;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Make URL for a PUT route. An error will be raised if the route doesn't
|
|
136
|
+
* exist.
|
|
137
|
+
*
|
|
138
|
+
* ```ts
|
|
139
|
+
* urlFor.put('users.update', [1]) // { method: 'put', url: '/users/1' }
|
|
140
|
+
* urlFor.put('users.show', [1]) // Error: Route not found PUT@users.show
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
put<RouteIdentifier extends keyof Routes['PUT'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'PUT', RouteIdentifier, Options>): {
|
|
144
|
+
method: 'put';
|
|
145
|
+
url: string;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Make URL for a PATCH route. An error will be raised if the route doesn't
|
|
149
|
+
* exist.
|
|
150
|
+
*
|
|
151
|
+
* ```ts
|
|
152
|
+
* urlFor.put('users.update', [1]) // { method: 'patch', url: '/users/1' }
|
|
153
|
+
* urlFor.put('users.show', [1]) // Error: Route not found PATCH@users.show
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
patch<RouteIdentifier extends keyof Routes['PATCH'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'PATCH', RouteIdentifier, Options>): {
|
|
157
|
+
method: 'patch';
|
|
158
|
+
url: string;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Make URL for a DELETE route. An error will be raised if the route doesn't
|
|
162
|
+
* exist.
|
|
163
|
+
*
|
|
164
|
+
* ```ts
|
|
165
|
+
* urlFor.delete('users.destroy', [1]) // { method: 'delete', url: '/users/1' }
|
|
166
|
+
* urlFor.delete('users.show', [1]) // Error: Route not found DELETE@users.show
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
delete<RouteIdentifier extends keyof Routes['DELETE'] & string>(...[identifier, params, options]: RouteBuilderArguments<Routes, 'DELETE', RouteIdentifier, Options>): {
|
|
170
|
+
method: 'delete';
|
|
171
|
+
url: string;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Make URL for a custom route method. An error will be raised if the route doesn't
|
|
175
|
+
* exist for the same method.
|
|
176
|
+
*/
|
|
177
|
+
method<Method extends keyof Routes & string, RouteIdentifier extends keyof Routes[Method] & string>(method: Method, ...[identifier, params, options]: RouteBuilderArguments<Routes, Method, RouteIdentifier, Options>): {
|
|
178
|
+
method: Method;
|
|
179
|
+
url: string;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type RouterClient } from './router.ts';
|
|
2
|
+
import { type UrlFor, type LookupList, type URLOptions, type ClientRouteJSON, type MatchItRouteToken } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Makes URL for a given route pattern. The route pattern could be an
|
|
5
|
+
* identifier or an array of tokens.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createURL(identifier: string, tokens: Pick<MatchItRouteToken, 'val' | 'type' | 'end'>[], searchParamsStringifier: (qs: Record<string, any>) => string, params?: any[] | {
|
|
8
|
+
[param: string]: any;
|
|
9
|
+
}, options?: URLOptions): string;
|
|
10
|
+
/**
|
|
11
|
+
* Creates the URLBuilder helper
|
|
12
|
+
*/
|
|
13
|
+
export declare function createUrlBuilder<Routes extends LookupList>(router: RouterClient<ClientRouteJSON>, searchParamsStringifier: (qs: Record<string, any>) => string): UrlFor<Routes>;
|
|
@@ -17,7 +17,7 @@ export declare class CookieClient {
|
|
|
17
17
|
/**
|
|
18
18
|
* Encode a key value pair to be sent in the cookie header
|
|
19
19
|
*/
|
|
20
|
-
encode(_: string, value: any): string | null;
|
|
20
|
+
encode(_: string, value: any, stringify?: boolean): string | null;
|
|
21
21
|
/**
|
|
22
22
|
* Unsign a signed cookie value
|
|
23
23
|
*/
|
|
@@ -29,7 +29,7 @@ export declare class CookieClient {
|
|
|
29
29
|
/**
|
|
30
30
|
* Decode an encoded cookie value
|
|
31
31
|
*/
|
|
32
|
-
decode(_: string, value: string): any;
|
|
32
|
+
decode(_: string, value: string, stringified?: boolean): any;
|
|
33
33
|
/**
|
|
34
34
|
* Parse response cookie
|
|
35
35
|
*/
|
|
@@ -14,10 +14,10 @@ export declare class CookieParser {
|
|
|
14
14
|
constructor(cookieHeader: string, encryption: Encryption);
|
|
15
15
|
/**
|
|
16
16
|
* Attempts to decode a cookie by the name. When calling this method,
|
|
17
|
-
* you are assuming that the cookie was just
|
|
17
|
+
* you are assuming that the cookie was just stringified in the first
|
|
18
18
|
* place and not signed or encrypted.
|
|
19
19
|
*/
|
|
20
|
-
decode(key: string,
|
|
20
|
+
decode(key: string, stringified?: boolean): any | null;
|
|
21
21
|
/**
|
|
22
22
|
* Attempts to unsign a cookie by the name. When calling this method,
|
|
23
23
|
* you are assuming that the cookie was signed in the first place.
|