@adonisjs/http-server 8.0.0-next.12 → 8.0.0-next.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.
Files changed (39) hide show
  1. package/build/define_config-Dh5SpqNg.js +2446 -0
  2. package/build/factories/http_context.d.ts +4 -4
  3. package/build/factories/main.d.ts +2 -2
  4. package/build/factories/main.js +163 -347
  5. package/build/factories/request.d.ts +4 -4
  6. package/build/factories/response.d.ts +4 -4
  7. package/build/factories/router.d.ts +1 -1
  8. package/build/factories/server_factory.d.ts +1 -1
  9. package/build/factories/url_builder_factory.d.ts +1 -1
  10. package/build/helpers-C_2HouOe.js +52 -0
  11. package/build/helpers-oKG4uNSM.js +686 -0
  12. package/build/index.d.ts +2 -2
  13. package/build/index.js +157 -375
  14. package/build/src/client/url_builder.js +3 -12
  15. package/build/src/cookies/client.d.ts +1 -1
  16. package/build/src/cookies/drivers/encrypted.d.ts +1 -1
  17. package/build/src/cookies/drivers/signed.d.ts +1 -1
  18. package/build/src/cookies/parser.d.ts +1 -1
  19. package/build/src/cookies/serializer.d.ts +1 -1
  20. package/build/src/debug.d.ts +1 -1
  21. package/build/src/exception_handler.d.ts +7 -0
  22. package/build/src/helpers.d.ts +1 -1
  23. package/build/src/helpers.js +3 -26
  24. package/build/src/http_context/main.d.ts +7 -7
  25. package/build/src/qs.d.ts +1 -1
  26. package/build/src/redirect.d.ts +2 -2
  27. package/build/src/request.d.ts +2 -2
  28. package/build/src/response.d.ts +5 -5
  29. package/build/src/router/main.d.ts +1 -1
  30. package/build/src/router/signed_url_builder.d.ts +1 -1
  31. package/build/src/server/main.d.ts +6 -6
  32. package/build/src/types/main.js +1 -0
  33. package/build/src/types/response.d.ts +6 -1
  34. package/build/url_builder-piNQy-CF.js +114 -0
  35. package/package.json +24 -22
  36. package/build/chunk-2QM3D5BN.js +0 -87
  37. package/build/chunk-77CSRFCU.js +0 -131
  38. package/build/chunk-L2UOVWDK.js +0 -4441
  39. package/build/chunk-QDK57QGB.js +0 -1176
@@ -1,8 +1,8 @@
1
1
  import Macroable from '@poppinss/macroable';
2
2
  import type { Logger } from '@adonisjs/logger';
3
3
  import { type ContainerResolver } from '@adonisjs/fold';
4
- import type { Request } from '../request.ts';
5
- import type { Response } from '../response.ts';
4
+ import type { HttpRequest } from '../request.ts';
5
+ import type { HttpResponse } from '../response.ts';
6
6
  import type { RouteJSON } from '../types/route.ts';
7
7
  /**
8
8
  * HTTP context encapsulates all properties and services for a given HTTP request.
@@ -23,8 +23,8 @@ import type { RouteJSON } from '../types/route.ts';
23
23
  * ```
24
24
  */
25
25
  export declare class HttpContext extends Macroable {
26
- request: Request;
27
- response: Response;
26
+ request: HttpRequest;
27
+ response: HttpResponse;
28
28
  logger: Logger;
29
29
  containerResolver: ContainerResolver<any>;
30
30
  /**
@@ -103,12 +103,12 @@ export declare class HttpContext extends Macroable {
103
103
  /**
104
104
  * Creates a new HttpContext instance
105
105
  *
106
- * @param {Request} request - The HTTP request instance
107
- * @param {Response} response - The HTTP response instance
106
+ * @param {HttpRequest} request - The HTTP request instance
107
+ * @param {HttpResponse} response - The HTTP response instance
108
108
  * @param {Logger} logger - The logger instance
109
109
  * @param {ContainerResolver<any>} containerResolver - The IoC container resolver
110
110
  */
111
- constructor(request: Request, response: Response, logger: Logger, containerResolver: ContainerResolver<any>);
111
+ constructor(request: HttpRequest, response: HttpResponse, logger: Logger, containerResolver: ContainerResolver<any>);
112
112
  /**
113
113
  * A helper to see top level properties on the context object
114
114
  */
package/build/src/qs.d.ts CHANGED
@@ -29,7 +29,7 @@ export declare class Qs {
29
29
  * @param value - Query string to parse (e.g., "foo=bar&baz=qux")
30
30
  * @returns Parsed object representation of the query string
31
31
  */
32
- parse: (value: string) => import("qs").ParsedQs;
32
+ parse: (value: string) => import("@poppinss/qs").ParsedQs;
33
33
  /**
34
34
  * Converts a JavaScript object into a query string using the configured options
35
35
  * @param value - Object to convert to query string
@@ -1,7 +1,7 @@
1
1
  import type { IncomingMessage } from 'node:http';
2
2
  import type { Qs } from './qs.ts';
3
- import type { Response } from './response.ts';
4
3
  import type { Router } from './router/main.ts';
4
+ import type { HttpResponse } from './response.ts';
5
5
  import type { RoutesList, LookupList, URLOptions, GetRoutesForMethod, RouteBuilderArguments } from './types/url_builder.ts';
6
6
  /**
7
7
  * Provides a fluent API for constructing HTTP redirect responses.
@@ -34,7 +34,7 @@ export declare class Redirect {
34
34
  * @param router - AdonisJS router instance
35
35
  * @param qs - Query string parser instance
36
36
  */
37
- constructor(request: IncomingMessage, response: Response, router: Router, qs: Qs);
37
+ constructor(request: IncomingMessage, response: HttpResponse, router: Router, qs: Qs);
38
38
  /**
39
39
  * Sets a custom HTTP status code for the redirect response
40
40
  * @param statusCode - HTTP status code to use (e.g., 301, 302, 307)
@@ -1,5 +1,5 @@
1
1
  import Macroable from '@poppinss/macroable';
2
- import type { Encryption } from '@adonisjs/encryption';
2
+ import type { Encryption } from '@boringnode/encryption';
3
3
  import { type ServerResponse, type IncomingMessage, type IncomingHttpHeaders } from 'node:http';
4
4
  import type { Qs } from './qs.ts';
5
5
  import { type RequestConfig } from './types/request.ts';
@@ -13,7 +13,7 @@ import type { HttpContext } from './http_context/main.ts';
13
13
  * You can access the original [IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
14
14
  * using `request.request` property.
15
15
  */
16
- export declare class Request extends Macroable {
16
+ export declare class HttpRequest extends Macroable {
17
17
  #private;
18
18
  /** Native Node.js incoming message instance */
19
19
  request: IncomingMessage;
@@ -1,5 +1,5 @@
1
1
  import Macroable from '@poppinss/macroable';
2
- import type { Encryption } from '@adonisjs/encryption';
2
+ import type { Encryption } from '@boringnode/encryption';
3
3
  import { type ServerResponse, type IncomingMessage } from 'node:http';
4
4
  import type { Qs } from './qs.ts';
5
5
  import { Redirect } from './redirect.ts';
@@ -19,7 +19,7 @@ import type { CastableHeader, CookieOptions, ResponseConfig, ResponseStream } fr
19
19
  * response.download('/path/to/file.pdf')
20
20
  * ```
21
21
  */
22
- export declare class Response extends Macroable {
22
+ export declare class HttpResponse extends Macroable {
23
23
  #private;
24
24
  request: IncomingMessage;
25
25
  response: ServerResponse;
@@ -46,7 +46,7 @@ export declare class Response extends Macroable {
46
46
  /**
47
47
  * The readable stream instance configured for the response
48
48
  */
49
- get outgoingStream(): import("stream").Readable | undefined;
49
+ get outgoingStream(): ResponseStream | undefined;
50
50
  /**
51
51
  * Configuration for file streaming including path and etag generation flag
52
52
  */
@@ -159,14 +159,14 @@ export declare class Response extends Macroable {
159
159
  * @param key - Header name
160
160
  * @returns The header value
161
161
  */
162
- getHeader(key: string): import("http").OutgoingHttpHeader | undefined;
162
+ getHeader(key: string): import("node:http").OutgoingHttpHeader | undefined;
163
163
  /**
164
164
  * Gets all response headers as an object
165
165
  *
166
166
  * @returns Object containing all headers
167
167
  */
168
168
  getHeaders(): {
169
- [x: string]: import("http").OutgoingHttpHeader | undefined;
169
+ [x: string]: import("node:http").OutgoingHttpHeader | undefined;
170
170
  accept?: string | string[] | undefined;
171
171
  "accept-charset"?: string | string[] | undefined;
172
172
  "accept-encoding"?: string | string[] | undefined;
@@ -1,4 +1,4 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  import type { Application } from '@adonisjs/application';
3
3
  import type { Constructor, LazyImport } from '@poppinss/utils/types';
4
4
  import type { Qs } from '../qs.ts';
@@ -1,4 +1,4 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  import { type Router } from './main.ts';
3
3
  import { type UrlFor, type LookupList, type SignedURLOptions } from '../types/url_builder.ts';
4
4
  /**
@@ -1,6 +1,6 @@
1
1
  import type { Logger } from '@adonisjs/logger';
2
2
  import type { LazyImport } from '@poppinss/utils/types';
3
- import type { Encryption } from '@adonisjs/encryption';
3
+ import type { Encryption } from '@boringnode/encryption';
4
4
  import type { Server as HttpsServer } from 'node:https';
5
5
  import type { Application } from '@adonisjs/application';
6
6
  import type { EmitterLike } from '@adonisjs/events/types';
@@ -8,9 +8,9 @@ import { type ContainerResolver } from '@adonisjs/fold';
8
8
  import type { ServerResponse, IncomingMessage, Server as HttpServer } from 'node:http';
9
9
  import type { MiddlewareAsClass, ParsedGlobalMiddleware } from '../types/middleware.ts';
10
10
  import type { ServerConfig, HttpServerEvents, ErrorHandlerAsAClass, TestingMiddlewarePipeline } from '../types/server.ts';
11
- import { Request } from '../request.ts';
12
- import { Response } from '../response.ts';
11
+ import { HttpRequest } from '../request.ts';
13
12
  import { Router } from '../router/main.ts';
13
+ import { HttpResponse } from '../response.ts';
14
14
  import { HttpContext } from '../http_context/main.ts';
15
15
  /**
16
16
  * The Server class provides the core HTTP server implementation for AdonisJS.
@@ -105,7 +105,7 @@ export declare class Server {
105
105
  * @param res - Node.js ServerResponse
106
106
  * @returns New Request instance
107
107
  */
108
- createRequest(req: IncomingMessage, res: ServerResponse): Request;
108
+ createRequest(req: IncomingMessage, res: ServerResponse): HttpRequest;
109
109
  /**
110
110
  * Creates a Response instance from Node.js request/response objects
111
111
  *
@@ -113,7 +113,7 @@ export declare class Server {
113
113
  * @param res - Node.js ServerResponse
114
114
  * @returns New Response instance
115
115
  */
116
- createResponse(req: IncomingMessage, res: ServerResponse): Response;
116
+ createResponse(req: IncomingMessage, res: ServerResponse): HttpResponse;
117
117
  /**
118
118
  * Creates an HttpContext instance with request-specific logger
119
119
  *
@@ -122,7 +122,7 @@ export declare class Server {
122
122
  * @param resolver - Container resolver for dependency injection
123
123
  * @returns New HttpContext instance
124
124
  */
125
- createHttpContext(request: Request, response: Response, resolver: ContainerResolver<any>): HttpContext;
125
+ createHttpContext(request: HttpRequest, response: HttpResponse, resolver: ContainerResolver<any>): HttpContext;
126
126
  /**
127
127
  * Gets the list of registered global middleware
128
128
  *
@@ -0,0 +1 @@
1
+ export {};
@@ -30,6 +30,11 @@ export type CastableHeader = string | number | boolean | string[] | number[] | b
30
30
  * Configuration options for HTTP response handling and processing
31
31
  */
32
32
  export type ResponseConfig = {
33
+ /**
34
+ * Define a custom serializer to serialize the response body
35
+ * to a JSON string
36
+ */
37
+ serializeJSON(payload: unknown): string | undefined;
33
38
  /**
34
39
  * Whether or not to generate etags for responses. Etags can be
35
40
  * enabled/disabled when sending response as well.
@@ -51,4 +56,4 @@ export type ResponseConfig = {
51
56
  /**
52
57
  * A readable stream that can be piped to the response stream method
53
58
  */
54
- export type ResponseStream = Readable;
59
+ export type ResponseStream = Readable | ReadableStream<any>;
@@ -0,0 +1,114 @@
1
+ import { n as findRoute, t as createURL } from "./helpers-C_2HouOe.js";
2
+ function createUrlBuilder(routesLoader, searchParamsStringifier) {
3
+ let domainsList;
4
+ let domainsRoutes;
5
+ function createUrlForRoute(identifier, params, options, method) {
6
+ if (!domainsRoutes) {
7
+ domainsRoutes = typeof routesLoader === "function" ? routesLoader() : routesLoader;
8
+ if (!domainsRoutes || typeof domainsRoutes !== "object") throw new Error(`Cannot construct routes. Expected the value to be an object, instead received ${typeof domainsRoutes}`);
9
+ if (!domainsList) domainsList = Object.keys(domainsRoutes).filter((domain$1) => domain$1 !== "root");
10
+ }
11
+ const domain = domainsList.find((name) => identifier.startsWith(`${name}@`));
12
+ const routeIdentifier = domain ? identifier.replace(/* @__PURE__ */ new RegExp(`^${domain}@`), "") : identifier;
13
+ const route = findRoute(domainsRoutes, routeIdentifier, domain, method, true);
14
+ if (!route) {
15
+ if (method) throw new Error(`Cannot lookup route "${routeIdentifier}" for method "${method}"`);
16
+ throw new Error(`Cannot lookup route "${routeIdentifier}"`);
17
+ }
18
+ return createURL(route.name ?? route.pattern, route.tokens, searchParamsStringifier, params, options);
19
+ }
20
+ const urlFor = function route(...[identifier, params, options]) {
21
+ return createUrlForRoute(identifier, params, options);
22
+ };
23
+ urlFor.get = function urlForMethodGet(...[identifier, params, options]) {
24
+ const method = "GET";
25
+ const url = createUrlForRoute(identifier, params, options, method);
26
+ return {
27
+ url,
28
+ method,
29
+ toString() {
30
+ return url;
31
+ },
32
+ form: {
33
+ action: url,
34
+ method
35
+ }
36
+ };
37
+ };
38
+ urlFor.post = function urlForMethodPost(...[identifier, params, options]) {
39
+ const method = "POST";
40
+ const url = createUrlForRoute(identifier, params, options, method);
41
+ return {
42
+ url,
43
+ method,
44
+ toString() {
45
+ return url;
46
+ },
47
+ form: {
48
+ action: url,
49
+ method
50
+ }
51
+ };
52
+ };
53
+ urlFor.put = function urlForMethodPut(...[identifier, params, options]) {
54
+ const method = "PUT";
55
+ const url = createUrlForRoute(identifier, params, options, method);
56
+ return {
57
+ url,
58
+ method,
59
+ toString() {
60
+ return url;
61
+ },
62
+ form: {
63
+ action: url,
64
+ method
65
+ }
66
+ };
67
+ };
68
+ urlFor.patch = function urlForMethodPatch(...[identifier, params, options]) {
69
+ const method = "PATCH";
70
+ const url = createUrlForRoute(identifier, params, options, method);
71
+ return {
72
+ url,
73
+ method,
74
+ toString() {
75
+ return url;
76
+ },
77
+ form: {
78
+ action: url,
79
+ method
80
+ }
81
+ };
82
+ };
83
+ urlFor.delete = function urlForMethodDelete(...[identifier, params, options]) {
84
+ const method = "DELETE";
85
+ const url = createUrlForRoute(identifier, params, options, method);
86
+ return {
87
+ url,
88
+ method,
89
+ toString() {
90
+ return url;
91
+ },
92
+ form: {
93
+ action: url,
94
+ method
95
+ }
96
+ };
97
+ };
98
+ urlFor.method = function urlForCustomMethod(method, ...[identifier, params, options]) {
99
+ const url = createUrlForRoute(identifier, params, options, method);
100
+ return {
101
+ url,
102
+ method,
103
+ toString() {
104
+ return url;
105
+ },
106
+ form: {
107
+ action: url,
108
+ method
109
+ }
110
+ };
111
+ };
112
+ return urlFor;
113
+ }
114
+ export { createUrlBuilder as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/http-server",
3
- "version": "8.0.0-next.12",
3
+ "version": "8.0.0-next.14",
4
4
  "description": "AdonisJS HTTP server with support packed with Routing and Cookies",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "test": "cross-env NODE_DEBUG=adonisjs:http c8 npm run quick:test",
25
25
  "typecheck": "tsc --noEmit",
26
26
  "precompile": "npm run lint",
27
- "compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
27
+ "compile": "tsdown && tsc --emitDeclarationOnly --declaration",
28
28
  "build": "npm run compile",
29
29
  "prebenchmark": "npm run build",
30
30
  "benchmark": "node benchmarks/index.js",
@@ -44,13 +44,13 @@
44
44
  "license": "MIT",
45
45
  "devDependencies": {
46
46
  "@adonisjs/application": "^9.0.0-next.4",
47
- "@adonisjs/encryption": "^7.0.0-next.1",
48
47
  "@adonisjs/eslint-config": "^3.0.0-next.1",
49
48
  "@adonisjs/events": "^10.1.0-next.2",
50
49
  "@adonisjs/fold": "^11.0.0-next.2",
51
50
  "@adonisjs/logger": "^7.1.0-next.0",
52
51
  "@adonisjs/prettier-config": "^1.4.5",
53
52
  "@adonisjs/tsconfig": "^2.0.0-next.0",
53
+ "@boringnode/encryption": "^0.2.2",
54
54
  "@fastify/middie": "^9.0.3",
55
55
  "@japa/assert": "^4.1.1",
56
56
  "@japa/expect-type": "^2.0.3",
@@ -58,7 +58,7 @@
58
58
  "@japa/runner": "^4.4.0",
59
59
  "@japa/snapshot": "^2.0.9",
60
60
  "@poppinss/ts-exec": "^1.4.1",
61
- "@release-it/conventional-changelog": "^10.0.1",
61
+ "@release-it/conventional-changelog": "^10.0.3",
62
62
  "@types/accepts": "^1.3.7",
63
63
  "@types/content-disposition": "^0.5.9",
64
64
  "@types/destroy": "^1.0.3",
@@ -67,30 +67,30 @@
67
67
  "@types/fresh": "^0.5.3",
68
68
  "@types/fs-extra": "^11.0.4",
69
69
  "@types/mime-types": "^3.0.1",
70
- "@types/node": "^24.8.1",
70
+ "@types/node": "^25.0.0",
71
71
  "@types/on-finished": "^2.3.5",
72
72
  "@types/pem": "^1.14.4",
73
73
  "@types/proxy-addr": "^2.0.3",
74
- "@types/qs": "^6.14.0",
75
74
  "@types/supertest": "^6.0.3",
76
75
  "@types/type-is": "^1.6.7",
77
76
  "@types/vary": "^1.1.3",
78
- "@vinejs/vine": "^4.0.0",
77
+ "@vinejs/vine": "^4.2.0",
78
+ "accepts": "^1.3.8",
79
79
  "autocannon": "^8.0.0",
80
80
  "c8": "^10.1.3",
81
81
  "cross-env": "^10.1.0",
82
- "eslint": "^9.38.0",
83
- "fastify": "^5.6.1",
82
+ "eslint": "^9.39.1",
83
+ "fastify": "^5.6.2",
84
84
  "fs-extra": "^11.3.2",
85
85
  "get-port": "^7.1.0",
86
86
  "http-status-codes": "^2.3.0",
87
87
  "pem": "^1.14.8",
88
- "prettier": "^3.6.2",
88
+ "prettier": "^3.7.4",
89
89
  "reflect-metadata": "^0.2.2",
90
- "release-it": "^19.0.5",
90
+ "release-it": "^19.1.0",
91
91
  "supertest": "^7.1.4",
92
- "tsup": "^8.5.0",
93
- "typedoc": "^0.28.14",
92
+ "tsdown": "^0.17.2",
93
+ "typedoc": "^0.28.15",
94
94
  "typescript": "^5.9.3",
95
95
  "youch": "^4.1.0-beta.11"
96
96
  },
@@ -98,29 +98,28 @@
98
98
  "@poppinss/macroable": "^1.1.0",
99
99
  "@poppinss/matchit": "^3.2.0",
100
100
  "@poppinss/middleware": "^3.2.6",
101
- "@poppinss/utils": "^7.0.0-next.3",
102
- "@sindresorhus/is": "^7.1.0",
103
- "accepts": "^1.3.8",
104
- "content-disposition": "^0.5.4",
105
- "cookie": "^1.0.2",
101
+ "@poppinss/qs": "^6.15.0",
102
+ "@poppinss/utils": "^7.0.0-next.4",
103
+ "@sindresorhus/is": "^7.1.1",
104
+ "content-disposition": "^1.0.1",
105
+ "cookie-es": "^2.0.0",
106
106
  "destroy": "^1.2.0",
107
107
  "encodeurl": "^2.0.0",
108
108
  "etag": "^1.8.1",
109
109
  "fresh": "^0.5.2",
110
- "mime-types": "^3.0.1",
110
+ "mime-types": "^3.0.2",
111
111
  "on-finished": "^2.4.1",
112
112
  "proxy-addr": "^2.0.7",
113
- "qs": "^6.14.0",
114
113
  "tmp-cache": "^1.1.0",
115
114
  "type-is": "^2.0.1",
116
115
  "vary": "^1.1.2"
117
116
  },
118
117
  "peerDependencies": {
119
118
  "@adonisjs/application": "^9.0.0-next.4",
120
- "@adonisjs/encryption": "^7.0.0-next.1",
121
119
  "@adonisjs/events": "^10.1.0-next.2",
122
120
  "@adonisjs/fold": "^11.0.0-next.2",
123
121
  "@adonisjs/logger": "^7.1.0-next.0",
122
+ "@boringnode/encryption": "^0.2.2",
124
123
  "youch": "^4.1.0-beta.11"
125
124
  },
126
125
  "peerDependenciesMeta": {
@@ -177,7 +176,7 @@
177
176
  ]
178
177
  },
179
178
  "prettier": "@adonisjs/prettier-config",
180
- "tsup": {
179
+ "tsdown": {
181
180
  "entry": [
182
181
  "./index.ts",
183
182
  "./src/helpers.ts",
@@ -188,7 +187,10 @@
188
187
  "outDir": "./build",
189
188
  "clean": true,
190
189
  "format": "esm",
190
+ "minify": "dce-only",
191
+ "fixedExtension": false,
191
192
  "dts": false,
193
+ "treeshake": false,
192
194
  "sourcemap": false,
193
195
  "target": "esnext"
194
196
  }
@@ -1,87 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/client/helpers.ts
8
- function findRoute(domainsRoutes, routeIdentifier, domain, method, disableLegacyLookup) {
9
- if (!domain) {
10
- let route = null;
11
- for (const routeDomain of Object.keys(domainsRoutes)) {
12
- route = findRoute(domainsRoutes, routeIdentifier, routeDomain, method, disableLegacyLookup);
13
- if (route) {
14
- break;
15
- }
16
- }
17
- return route;
18
- }
19
- const routes = domainsRoutes[domain];
20
- if (!routes) {
21
- return null;
22
- }
23
- const lookupByName = true;
24
- const lookupByPattern = !disableLegacyLookup;
25
- const lookupByController = !disableLegacyLookup;
26
- return routes.find((route) => {
27
- if (method && !route.methods.includes(method)) {
28
- return false;
29
- }
30
- if (lookupByName && route.name === routeIdentifier || lookupByPattern && route.pattern === routeIdentifier) {
31
- return true;
32
- }
33
- if (lookupByController && route.handler && typeof route.handler === "object") {
34
- return "reference" in route.handler && route.handler.reference === routeIdentifier;
35
- }
36
- return false;
37
- }) || null;
38
- }
39
- function createURL(pattern, tokens, searchParamsStringifier, params, options) {
40
- const uriSegments = [];
41
- const paramsArray = Array.isArray(params) ? params : null;
42
- const paramsObject = !Array.isArray(params) ? params ?? {} : {};
43
- let paramsIndex = 0;
44
- for (const token of tokens) {
45
- if (token.type === 0) {
46
- uriSegments.push(token.val === "/" ? "" : `${token.val}${token.end}`);
47
- continue;
48
- }
49
- if (token.type === 2) {
50
- const values = paramsArray ? paramsArray.slice(paramsIndex) : paramsObject["*"];
51
- if (!Array.isArray(values) || !values.length) {
52
- throw new Error(
53
- `Cannot make URL for "${pattern}". Invalid value provided for the wildcard param`
54
- );
55
- }
56
- uriSegments.push(`${values.join("/")}${token.end}`);
57
- break;
58
- }
59
- const paramName = token.val;
60
- const value = paramsArray ? paramsArray[paramsIndex] : paramsObject[paramName];
61
- const isDefined = value !== void 0 && value !== null;
62
- if (token.type === 1 && !isDefined) {
63
- throw new Error(
64
- `Cannot make URL for "${pattern}". Missing value for the "${paramName}" param`
65
- );
66
- }
67
- if (isDefined) {
68
- uriSegments.push(`${value}${token.end}`);
69
- }
70
- paramsIndex++;
71
- }
72
- let URI = `/${uriSegments.join("/")}`;
73
- if (options?.prefixUrl) {
74
- URI = `${options?.prefixUrl.replace(/\/$/, "")}${URI}`;
75
- }
76
- if (options?.qs) {
77
- const queryString = searchParamsStringifier(options?.qs);
78
- URI = queryString ? `${URI}?${queryString}` : URI;
79
- }
80
- return URI;
81
- }
82
-
83
- export {
84
- __export,
85
- findRoute,
86
- createURL
87
- };
@@ -1,131 +0,0 @@
1
- import {
2
- createURL,
3
- findRoute
4
- } from "./chunk-2QM3D5BN.js";
5
-
6
- // src/client/url_builder.ts
7
- function createUrlBuilder(routesLoader, searchParamsStringifier) {
8
- let domainsList;
9
- let domainsRoutes;
10
- function createUrlForRoute(identifier, params, options, method) {
11
- if (!domainsRoutes) {
12
- domainsRoutes = typeof routesLoader === "function" ? routesLoader() : routesLoader;
13
- }
14
- if (!domainsList) {
15
- domainsList = Object.keys(domainsRoutes).filter((domain2) => domain2 !== "root");
16
- }
17
- const domain = domainsList.find((name) => identifier.startsWith(`${name}@`));
18
- const routeIdentifier = domain ? identifier.replace(new RegExp(`^${domain}@`), "") : identifier;
19
- const route = findRoute(domainsRoutes, routeIdentifier, domain, method, true);
20
- if (!route) {
21
- if (method) {
22
- throw new Error(`Cannot lookup route "${routeIdentifier}" for method "${method}"`);
23
- }
24
- throw new Error(`Cannot lookup route "${routeIdentifier}"`);
25
- }
26
- return createURL(
27
- route.name ?? route.pattern,
28
- route.tokens,
29
- searchParamsStringifier,
30
- params,
31
- options
32
- );
33
- }
34
- const urlFor = function route(...[identifier, params, options]) {
35
- return createUrlForRoute(identifier, params, options);
36
- };
37
- urlFor.get = function urlForMethodGet(...[identifier, params, options]) {
38
- const method = "GET";
39
- const url = createUrlForRoute(identifier, params, options, method);
40
- return {
41
- url,
42
- method,
43
- toString() {
44
- return url;
45
- },
46
- form: {
47
- action: url,
48
- method
49
- }
50
- };
51
- };
52
- urlFor.post = function urlForMethodPost(...[identifier, params, options]) {
53
- const method = "POST";
54
- const url = createUrlForRoute(identifier, params, options, method);
55
- return {
56
- url,
57
- method,
58
- toString() {
59
- return url;
60
- },
61
- form: {
62
- action: url,
63
- method
64
- }
65
- };
66
- };
67
- urlFor.put = function urlForMethodPut(...[identifier, params, options]) {
68
- const method = "PUT";
69
- const url = createUrlForRoute(identifier, params, options, method);
70
- return {
71
- url,
72
- method,
73
- toString() {
74
- return url;
75
- },
76
- form: {
77
- action: url,
78
- method
79
- }
80
- };
81
- };
82
- urlFor.patch = function urlForMethodPatch(...[identifier, params, options]) {
83
- const method = "PATCH";
84
- const url = createUrlForRoute(identifier, params, options, method);
85
- return {
86
- url,
87
- method,
88
- toString() {
89
- return url;
90
- },
91
- form: {
92
- action: url,
93
- method
94
- }
95
- };
96
- };
97
- urlFor.delete = function urlForMethodDelete(...[identifier, params, options]) {
98
- const method = "DELETE";
99
- const url = createUrlForRoute(identifier, params, options, method);
100
- return {
101
- url,
102
- method,
103
- toString() {
104
- return url;
105
- },
106
- form: {
107
- action: url,
108
- method
109
- }
110
- };
111
- };
112
- urlFor.method = function urlForCustomMethod(method, ...[identifier, params, options]) {
113
- const url = createUrlForRoute(identifier, params, options, method);
114
- return {
115
- url,
116
- method,
117
- toString() {
118
- return url;
119
- },
120
- form: {
121
- action: url,
122
- method
123
- }
124
- };
125
- };
126
- return urlFor;
127
- }
128
-
129
- export {
130
- createUrlBuilder
131
- };