@adonisjs/http-server 8.0.0-next.9 → 8.1.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.
Files changed (50) hide show
  1. package/build/chunk-B2GA45YG.js +35 -0
  2. package/build/define_config-t7GL92UR.js +5470 -0
  3. package/build/factories/http_context.d.ts +10 -4
  4. package/build/factories/main.d.ts +2 -2
  5. package/build/factories/main.js +328 -345
  6. package/build/factories/request.d.ts +4 -4
  7. package/build/factories/response.d.ts +4 -4
  8. package/build/factories/router.d.ts +1 -1
  9. package/build/factories/server_factory.d.ts +1 -1
  10. package/build/factories/url_builder_factory.d.ts +3 -3
  11. package/build/helpers-XD4_pfkD.js +108 -0
  12. package/build/helpers-aa47NQc6.js +1426 -0
  13. package/build/index.d.ts +2 -2
  14. package/build/index.js +330 -373
  15. package/build/src/client/helpers.d.ts +37 -0
  16. package/build/src/client/types.d.ts +194 -0
  17. package/build/src/client/url_builder.d.ts +15 -0
  18. package/build/src/client/url_builder.js +131 -0
  19. package/build/src/cookies/client.d.ts +28 -5
  20. package/build/src/cookies/drivers/encrypted.d.ts +1 -1
  21. package/build/src/cookies/drivers/signed.d.ts +1 -1
  22. package/build/src/cookies/parser.d.ts +1 -1
  23. package/build/src/cookies/serializer.d.ts +2 -2
  24. package/build/src/debug.d.ts +14 -1
  25. package/build/src/define_config.d.ts +19 -1
  26. package/build/src/define_middleware.d.ts +19 -3
  27. package/build/src/errors.d.ts +60 -5
  28. package/build/src/exception_handler.d.ts +28 -8
  29. package/build/src/helpers.d.ts +5 -17
  30. package/build/src/helpers.js +4 -24
  31. package/build/src/http_context/main.d.ts +67 -17
  32. package/build/src/qs.d.ts +17 -3
  33. package/build/src/redirect.d.ts +22 -3
  34. package/build/src/request.d.ts +12 -5
  35. package/build/src/response.d.ts +5 -5
  36. package/build/src/response_status.d.ts +14 -0
  37. package/build/src/router/main.d.ts +6 -2
  38. package/build/src/router/route.d.ts +130 -32
  39. package/build/src/router/signed_url_builder.d.ts +1 -1
  40. package/build/src/server/main.d.ts +6 -6
  41. package/build/src/types/main.js +2 -0
  42. package/build/src/types/request.d.ts +2 -1
  43. package/build/src/types/response.d.ts +6 -1
  44. package/build/src/types/route.d.ts +3 -27
  45. package/build/src/types/url_builder.d.ts +2 -140
  46. package/build/src/utils.d.ts +71 -6
  47. package/package.json +57 -48
  48. package/build/chunk-CVZAIRWJ.js +0 -1222
  49. package/build/chunk-JD6QW4NQ.js +0 -4428
  50. package/build/src/router/url_builder.d.ts +0 -9
@@ -1,6 +1,6 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  import { IncomingMessage, ServerResponse } from 'node:http';
3
- import { Request } from '../src/request.ts';
3
+ import { HttpRequest } from '../src/request.ts';
4
4
  import { type RequestConfig } from '../src/types/request.ts';
5
5
  type FactoryParameters = {
6
6
  url: string;
@@ -14,7 +14,7 @@ type FactoryParameters = {
14
14
  * Request factory is used to generate request class instances for
15
15
  * testing
16
16
  */
17
- export declare class RequestFactory {
17
+ export declare class HttpRequestFactory {
18
18
  #private;
19
19
  /**
20
20
  * Merge factory params
@@ -24,6 +24,6 @@ export declare class RequestFactory {
24
24
  /**
25
25
  * Create request
26
26
  */
27
- create(): Request;
27
+ create(): HttpRequest;
28
28
  }
29
29
  export {};
@@ -1,6 +1,6 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  import { IncomingMessage, ServerResponse } from 'node:http';
3
- import { Response } from '../src/response.ts';
3
+ import { HttpResponse } from '../src/response.ts';
4
4
  import { type Router } from '../src/router/main.ts';
5
5
  import { type ResponseConfig } from '../src/types/response.ts';
6
6
  type FactoryParameters = {
@@ -14,7 +14,7 @@ type FactoryParameters = {
14
14
  * Response factory is used to generate response class instances for
15
15
  * testing
16
16
  */
17
- export declare class ResponseFactory {
17
+ export declare class HttpResponseFactory {
18
18
  #private;
19
19
  /**
20
20
  * Merge factory params
@@ -24,6 +24,6 @@ export declare class ResponseFactory {
24
24
  /**
25
25
  * Create response class instance
26
26
  */
27
- create(): Response;
27
+ create(): HttpResponse;
28
28
  }
29
29
  export {};
@@ -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 { Router } from '../src/router/main.ts';
4
4
  type FactoryParameters = {
@@ -1,6 +1,6 @@
1
1
  import { Logger } from '@adonisjs/logger';
2
2
  import { Emitter } from '@adonisjs/events';
3
- import type { Encryption } from '@adonisjs/encryption';
3
+ import type { Encryption } from '@boringnode/encryption';
4
4
  import type { Application } from '@adonisjs/application';
5
5
  import { Server } from '../src/server/main.ts';
6
6
  import type { ServerConfig } from '../src/types/server.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 '../src/router/main.ts';
3
3
  import { type LookupList } from '../src/types/url_builder.ts';
4
4
  type FactoryParameters = {
@@ -19,8 +19,8 @@ export declare class URLBuilderFactory<Routes extends LookupList> {
19
19
  * Create URL builder helpers
20
20
  */
21
21
  create(): {
22
- urlFor: import("../src/types/url_builder.ts").UrlFor<Routes>;
23
- signedUrlFor: import("../src/types/url_builder.ts").UrlFor<Routes, import("../src/types/url_builder.ts").SignedURLOptions>;
22
+ urlFor: import("../src/client/types.ts").UrlFor<Routes>;
23
+ signedUrlFor: import("../src/client/types.ts").UrlFor<Routes, import("../src/types/url_builder.ts").SignedURLOptions>;
24
24
  };
25
25
  }
26
26
  export {};
@@ -0,0 +1,108 @@
1
+ //#region src/client/helpers.ts
2
+ /**
3
+ * Finds a route by its identifier across domains.
4
+ *
5
+ * Searches for routes by name, pattern, or controller reference. When no domain
6
+ * is specified, searches across all domains. Supports legacy lookup strategies
7
+ * for backwards compatibility.
8
+ *
9
+ * @param domainsRoutes - Object mapping domain names to route arrays
10
+ * @param routeIdentifier - Route name, pattern, or controller reference to find
11
+ * @param domain - Optional domain to limit search scope
12
+ * @param method - Optional HTTP method to filter routes
13
+ * @param disableLegacyLookup - Whether to disable pattern and controller lookup
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const route = findRoute(routes, 'users.show', 'api', 'GET')
18
+ * const route2 = findRoute(routes, '/users/:id', undefined, 'GET')
19
+ * ```
20
+ */
21
+ function findRoute(domainsRoutes, routeIdentifier, domain, method, disableLegacyLookup) {
22
+ /**
23
+ * Search for route in all the domains when no domain name is
24
+ * mentioned.
25
+ */
26
+ if (!domain) {
27
+ let route = null;
28
+ for (const routeDomain of Object.keys(domainsRoutes)) {
29
+ route = findRoute(domainsRoutes, routeIdentifier, routeDomain, method, disableLegacyLookup);
30
+ if (route) break;
31
+ }
32
+ return route;
33
+ }
34
+ const routes = domainsRoutes[domain];
35
+ if (!routes) return null;
36
+ /**
37
+ * Pattern and controller are supported for legacy reasons. However
38
+ * the URL builder only works with names
39
+ */
40
+ const lookupByPattern = !disableLegacyLookup;
41
+ const lookupByController = !disableLegacyLookup;
42
+ return routes.find((route) => {
43
+ if (method && !route.methods.includes(method)) return false;
44
+ if (route.name === routeIdentifier || lookupByPattern && route.pattern === routeIdentifier) return true;
45
+ if (lookupByController && route.handler && typeof route.handler === "object") return "reference" in route.handler && route.handler.reference === routeIdentifier;
46
+ return false;
47
+ }) || null;
48
+ }
49
+ /**
50
+ * Makes URL for a given route pattern using its parsed tokens. The
51
+ * tokens could be generated using the "parseRoute" method.
52
+ *
53
+ * @param pattern - The route pattern
54
+ * @param tokens - Array of parsed route tokens
55
+ * @param searchParamsStringifier - Function to stringify query parameters
56
+ * @param params - Route parameters as array or object
57
+ * @param options - URL options
58
+ * @returns {string} The generated URL
59
+ */
60
+ function createURL(pattern, tokens, searchParamsStringifier, params, options) {
61
+ const uriSegments = [];
62
+ const paramsArray = Array.isArray(params) ? params : null;
63
+ const paramsObject = !Array.isArray(params) ? params ?? {} : {};
64
+ let paramsIndex = 0;
65
+ for (const token of tokens) {
66
+ /**
67
+ * Static param
68
+ */
69
+ if (token.type === 0) {
70
+ uriSegments.push(token.val === "/" ? "" : `${token.val}${token.end}`);
71
+ continue;
72
+ }
73
+ /**
74
+ * Wildcard param. It will always be the last param, hence we will provide
75
+ * it all the remaining values
76
+ */
77
+ if (token.type === 2) {
78
+ const values = paramsArray ? paramsArray.slice(paramsIndex) : paramsObject["*"];
79
+ if (!Array.isArray(values) || !values.length) throw new Error(`Cannot make URL for "${pattern}". Invalid value provided for the wildcard param`);
80
+ uriSegments.push(`${values.join("/")}${token.end}`);
81
+ break;
82
+ }
83
+ const paramName = token.val;
84
+ const value = paramsArray ? paramsArray[paramsIndex] : paramsObject[paramName];
85
+ const isDefined = value !== void 0 && value !== null;
86
+ /**
87
+ * Required param
88
+ */
89
+ if (token.type === 1 && !isDefined) throw new Error(`Cannot make URL for "${pattern}". Missing value for the "${paramName}" param`);
90
+ if (isDefined) uriSegments.push(`${value}${token.end}`);
91
+ paramsIndex++;
92
+ }
93
+ let URI = `/${uriSegments.join("/")}`;
94
+ /**
95
+ * Prefix base URL
96
+ */
97
+ if (options?.prefixUrl) URI = `${options?.prefixUrl.replace(/\/$/, "")}${URI}`;
98
+ /**
99
+ * Append query string
100
+ */
101
+ if (options?.qs) {
102
+ const queryString = searchParamsStringifier(options?.qs);
103
+ URI = queryString ? `${URI}?${queryString}` : URI;
104
+ }
105
+ return URI;
106
+ }
107
+ //#endregion
108
+ export { findRoute as n, createURL as t };