@adonisjs/http-server 5.7.2 → 5.8.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.
@@ -350,6 +350,7 @@ declare module '@ioc:Adonis/Core/Route' {
350
350
  qs?: Record<string, any>;
351
351
  domain?: string;
352
352
  prefixUrl?: string;
353
+ disableRouteLookup?: boolean;
353
354
  } & Record<string, any>;
354
355
  /**
355
356
  * Options for making a signed url
@@ -518,6 +519,11 @@ declare module '@ioc:Adonis/Core/Route' {
518
519
  * Generate url for the given route
519
520
  */
520
521
  make(identifier: string): string;
522
+ /**
523
+ * Disable route lookup and consider identifier
524
+ * as the route pattern
525
+ */
526
+ disableRouteLookup(): this;
521
527
  /**
522
528
  * Generate signed url for the given route
523
529
  */
@@ -47,7 +47,7 @@ class BriskRoute extends macroable_1.Macroable {
47
47
  if (this.route) {
48
48
  throw new utils_1.Exception(`\`Route.${invokedBy}\` and \`${this.invokedBy}\` cannot be called together`, 500, 'E_MULTIPLE_BRISK_HANDLERS');
49
49
  }
50
- this.route = new Route_1.Route(this.pattern, methods || ['HEAD', 'GET'], handler, this.globalMatchers);
50
+ this.route = new Route_1.Route(this.pattern, methods || ['GET', 'HEAD'], handler, this.globalMatchers);
51
51
  this.invokedBy = invokedBy;
52
52
  return this.route;
53
53
  }
@@ -14,6 +14,11 @@ export declare class UrlBuilder implements UrlBuilderContract {
14
14
  * A custom query string to append to the URL
15
15
  */
16
16
  private queryString;
17
+ /**
18
+ * A boolean to know if the route should be looked
19
+ * up inside the route store or not
20
+ */
21
+ private lookupRoute;
17
22
  /**
18
23
  * A baseUrl to prefix to the endpoint
19
24
  */
@@ -36,6 +41,11 @@ export declare class UrlBuilder implements UrlBuilderContract {
36
41
  * Prefix a custom url to the final URI
37
42
  */
38
43
  prefixUrl(url: string): this;
44
+ /**
45
+ * Disable route lookup. Calling this method considers
46
+ * the "identifier" as the route pattern
47
+ */
48
+ disableRouteLookup(): this;
39
49
  /**
40
50
  * Append query string to the final URI
41
51
  */
@@ -26,6 +26,11 @@ class UrlBuilder {
26
26
  * A custom query string to append to the URL
27
27
  */
28
28
  this.queryString = {};
29
+ /**
30
+ * A boolean to know if the route should be looked
31
+ * up inside the route store or not
32
+ */
33
+ this.lookupRoute = true;
29
34
  }
30
35
  /**
31
36
  * Processes the pattern against the params
@@ -105,6 +110,14 @@ class UrlBuilder {
105
110
  this.baseUrl = url;
106
111
  return this;
107
112
  }
113
+ /**
114
+ * Disable route lookup. Calling this method considers
115
+ * the "identifier" as the route pattern
116
+ */
117
+ disableRouteLookup() {
118
+ this.lookupRoute = false;
119
+ return this;
120
+ }
108
121
  /**
109
122
  * Append query string to the final URI
110
123
  */
@@ -129,16 +142,28 @@ class UrlBuilder {
129
142
  * Generate url for the given route identifier
130
143
  */
131
144
  make(identifier) {
132
- const route = this.findRouteOrFail(identifier);
133
- const url = this.processPattern(route.pattern);
145
+ let url;
146
+ if (this.lookupRoute) {
147
+ const route = this.findRouteOrFail(identifier);
148
+ url = this.processPattern(route.pattern);
149
+ }
150
+ else {
151
+ url = this.processPattern(identifier);
152
+ }
134
153
  return this.suffixQueryString(this.baseUrl ? `${this.baseUrl}${url}` : url);
135
154
  }
136
155
  /**
137
156
  * Generate url for the given route identifier
138
157
  */
139
158
  makeSigned(identifier, options) {
140
- const route = this.findRouteOrFail(identifier);
141
- const url = this.processPattern(route.pattern);
159
+ let url;
160
+ if (this.lookupRoute) {
161
+ const route = this.findRouteOrFail(identifier);
162
+ url = this.processPattern(route.pattern);
163
+ }
164
+ else {
165
+ url = this.processPattern(identifier);
166
+ }
142
167
  /*
143
168
  * Making the signature from the qualified url. We do not prefix the domain when
144
169
  * making signature, since it just makes the signature big.
@@ -62,11 +62,11 @@ class RouteResource extends macroable_1.Macroable {
62
62
  const fullUrl = `${resourceTokens
63
63
  .map((token) => `${token}/:${helpers_1.string.snakeCase((0, pluralize_1.singular)(token))}_id`)
64
64
  .join('/')}/${mainResource}`;
65
- this.makeRoute(fullUrl, ['HEAD', 'GET'], 'index');
66
- this.makeRoute(`${fullUrl}/create`, ['HEAD', 'GET'], 'create');
65
+ this.makeRoute(fullUrl, ['GET', 'HEAD'], 'index');
66
+ this.makeRoute(`${fullUrl}/create`, ['GET', 'HEAD'], 'create');
67
67
  this.makeRoute(fullUrl, ['POST'], 'store');
68
- this.makeRoute(`${this.shallow ? mainResource : fullUrl}/:id`, ['HEAD', 'GET'], 'show');
69
- this.makeRoute(`${this.shallow ? mainResource : fullUrl}/:id/edit`, ['HEAD', 'GET'], 'edit');
68
+ this.makeRoute(`${this.shallow ? mainResource : fullUrl}/:id`, ['GET', 'HEAD'], 'show');
69
+ this.makeRoute(`${this.shallow ? mainResource : fullUrl}/:id/edit`, ['GET', 'HEAD'], 'edit');
70
70
  this.makeRoute(`${this.shallow ? mainResource : fullUrl}/:id`, ['PUT', 'PATCH'], 'update');
71
71
  this.makeRoute(`${this.shallow ? mainResource : fullUrl}/:id`, ['DELETE'], 'destroy');
72
72
  }
@@ -100,7 +100,7 @@ class Router {
100
100
  * Define `GET` route
101
101
  */
102
102
  get(pattern, handler) {
103
- return this.route(pattern, ['HEAD', 'GET'], handler);
103
+ return this.route(pattern, ['GET', 'HEAD'], handler);
104
104
  }
105
105
  /**
106
106
  * Define `POST` route
@@ -327,6 +327,7 @@ class Router {
327
327
  normalizedOptions.params && builder.params(normalizedOptions.params);
328
328
  normalizedOptions.qs && builder.qs(normalizedOptions.qs);
329
329
  normalizedOptions.prefixUrl && builder.prefixUrl(normalizedOptions.prefixUrl);
330
+ normalizedOptions.disableRouteLookup && builder.disableRouteLookup();
330
331
  return builder.make(routeIdentifier);
331
332
  }
332
333
  /**
@@ -341,6 +342,7 @@ class Router {
341
342
  normalizedOptions.params && builder.params(normalizedOptions.params);
342
343
  normalizedOptions.qs && builder.qs(normalizedOptions.qs);
343
344
  normalizedOptions.prefixUrl && builder.prefixUrl(normalizedOptions.prefixUrl);
345
+ normalizedOptions.disableRouteLookup && builder.disableRouteLookup();
344
346
  return builder.makeSigned(routeIdentifier, normalizedOptions);
345
347
  }
346
348
  }
@@ -48,6 +48,7 @@ export declare function normalizeMakeUrlOptions(params?: any[] | MakeUrlOptions,
48
48
  qs: any;
49
49
  domain: string | undefined;
50
50
  prefixUrl: string | undefined;
51
+ disableRouteLookup: boolean;
51
52
  };
52
53
  /**
53
54
  * Normalizes the make signed url options by allowing params to appear on
@@ -60,6 +61,7 @@ export declare function normalizeMakeSignedUrlOptions(params?: any[] | MakeSigne
60
61
  prefixUrl: string | undefined;
61
62
  expiresIn: any;
62
63
  purpose: any;
64
+ disableRouteLookup: boolean;
63
65
  };
64
66
  /**
65
67
  * Wraps `fs.stat` to promise interface.
@@ -143,13 +143,14 @@ function normalizeMakeUrlOptions(params, options) {
143
143
  const qs = options.qs || params['qs'];
144
144
  const domain = options.domain;
145
145
  const prefixUrl = options.prefixUrl;
146
+ const disableRouteLookup = options.disableRouteLookup || false;
146
147
  /**
147
148
  * Using legacy options
148
149
  */
149
150
  onIntersect(params, ['prefixDomain', 'domainParams', 'qs', 'params'], () => {
150
151
  process.emitWarning('DeprecationWarning', 'You are using legacy the API of the "Route.makeUrl". We recommend reading the docs and use the latest API');
151
152
  });
152
- return { params: normalizedParams, qs, domain, prefixUrl };
153
+ return { params: normalizedParams, qs, domain, prefixUrl, disableRouteLookup };
153
154
  }
154
155
  exports.normalizeMakeUrlOptions = normalizeMakeUrlOptions;
155
156
  /**
@@ -168,13 +169,14 @@ function normalizeMakeSignedUrlOptions(params, options) {
168
169
  const purpose = options.purpose || params['purpose'];
169
170
  const domain = options.domain;
170
171
  const prefixUrl = options.prefixUrl;
172
+ const disableRouteLookup = options.disableRouteLookup || false;
171
173
  /**
172
174
  * Using legacy options
173
175
  */
174
176
  onIntersect(params, ['prefixDomain', 'domainParams', 'qs', 'params', 'purpose', 'expiresIn'], () => {
175
177
  process.emitWarning('DeprecationWarning', 'You are using legacy the API of the "Route.makeSignedUrl". We recommend reading the docs and use the latest API');
176
178
  });
177
- return { params: normalizedParams, qs, domain, prefixUrl, expiresIn, purpose };
179
+ return { params: normalizedParams, qs, domain, prefixUrl, expiresIn, purpose, disableRouteLookup };
178
180
  }
179
181
  exports.normalizeMakeSignedUrlOptions = normalizeMakeSignedUrlOptions;
180
182
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/http-server",
3
- "version": "5.7.2",
3
+ "version": "5.8.0",
4
4
  "description": "AdonisJS HTTP server with support packed with Routing and Cookies",
5
5
  "main": "build/providers/HttpServerProvider.js",
6
6
  "files": [
@@ -36,15 +36,15 @@
36
36
  "author": "virk,adonisjs",
37
37
  "license": "MIT",
38
38
  "devDependencies": {
39
- "@adonisjs/application": "^5.2.0",
40
- "@adonisjs/encryption": "^4.0.7",
39
+ "@adonisjs/application": "^5.2.1",
40
+ "@adonisjs/encryption": "^4.0.8",
41
41
  "@adonisjs/mrm-preset": "^5.0.3",
42
- "@adonisjs/require-ts": "^2.0.10",
43
- "@japa/assert": "^1.3.2",
44
- "@japa/run-failed-tests": "^1.0.6",
45
- "@japa/runner": "^2.0.5",
46
- "@japa/spec-reporter": "^1.1.11",
47
- "@poppinss/dev-utils": "^2.0.2",
42
+ "@adonisjs/require-ts": "^2.0.11",
43
+ "@japa/assert": "^1.3.3",
44
+ "@japa/run-failed-tests": "^1.0.7",
45
+ "@japa/runner": "^2.0.6",
46
+ "@japa/spec-reporter": "^1.1.12",
47
+ "@poppinss/dev-utils": "^2.0.3",
48
48
  "@types/cookie": "^0.4.1",
49
49
  "@types/ms": "^0.7.31",
50
50
  "@types/node": "^17.0.23",
@@ -52,28 +52,28 @@
52
52
  "@types/proxy-addr": "^2.0.0",
53
53
  "@types/qs": "^6.9.7",
54
54
  "@types/supertest": "^2.0.12",
55
- "autocannon": "^7.8.0",
55
+ "autocannon": "^7.8.1",
56
56
  "commitizen": "^4.2.4",
57
57
  "cross-env": "^7.0.3",
58
58
  "cz-conventional-changelog": "^3.3.0",
59
59
  "del-cli": "^4.0.1",
60
- "eslint": "^8.11.0",
60
+ "eslint": "^8.12.0",
61
61
  "eslint-config-prettier": "^8.5.0",
62
62
  "eslint-plugin-adonis": "^2.1.0",
63
63
  "eslint-plugin-prettier": "^4.0.0",
64
64
  "fastify": "^3.27.4",
65
- "github-label-sync": "^2.0.2",
65
+ "github-label-sync": "^2.2.0",
66
66
  "http-status-codes": "^2.2.0",
67
67
  "husky": "^7.0.4",
68
68
  "middie": "^6.0.0",
69
69
  "mrm": "^4.0.0",
70
70
  "np": "^7.6.1",
71
71
  "pem": "^1.14.6",
72
- "prettier": "^2.6.0",
72
+ "prettier": "^2.6.2",
73
73
  "reflect-metadata": "^0.1.13",
74
74
  "supertest": "^6.2.2",
75
75
  "ts-node": "^10.7.0",
76
- "typescript": "^4.6.2"
76
+ "typescript": "^4.6.3"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "@adonisjs/application": "^5.0.0",
@@ -98,9 +98,9 @@
98
98
  },
99
99
  "dependencies": {
100
100
  "@poppinss/matchit": "^3.1.2",
101
- "@poppinss/utils": "^4.0.2",
101
+ "@poppinss/utils": "^4.0.3",
102
102
  "accepts": "^1.3.8",
103
- "co-compose": "^7.0.1",
103
+ "co-compose": "^7.0.2",
104
104
  "content-disposition": "^0.5.4",
105
105
  "cookie": "^0.4.2",
106
106
  "destroy": "^1.2.0",
@@ -108,7 +108,7 @@
108
108
  "etag": "^1.8.1",
109
109
  "fresh": "^0.5.2",
110
110
  "haye": "^3.0.0",
111
- "macroable": "^7.0.0",
111
+ "macroable": "^7.0.1",
112
112
  "mime-types": "^2.1.35",
113
113
  "ms": "^2.1.3",
114
114
  "on-finished": "^2.4.1",