@travetto/web 6.0.2 → 6.0.3

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <!-- Please modify https://github.com/travetto/travetto/tree/main/module/web/DOC.tsx and execute "npx trv doc" to rebuild -->
3
3
  # Web API
4
4
 
5
- ## Declarative support creating for Web Applications
5
+ ## Declarative support for creating Web Applications
6
6
 
7
7
  **Install: @travetto/web**
8
8
  ```bash
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/web",
3
- "version": "6.0.2",
4
- "description": "Declarative support creating for Web Applications",
3
+ "version": "6.0.3",
4
+ "description": "Declarative support for creating Web Applications",
5
5
  "keywords": [
6
6
  "web",
7
7
  "decorators",
@@ -25,18 +25,18 @@
25
25
  "directory": "module/web"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/config": "^6.0.0",
29
- "@travetto/context": "^6.0.0",
30
- "@travetto/di": "^6.0.0",
31
- "@travetto/registry": "^6.0.0",
32
- "@travetto/runtime": "^6.0.0",
33
- "@travetto/schema": "^6.0.0",
28
+ "@travetto/config": "^6.0.1",
29
+ "@travetto/context": "^6.0.1",
30
+ "@travetto/di": "^6.0.1",
31
+ "@travetto/registry": "^6.0.1",
32
+ "@travetto/runtime": "^6.0.1",
33
+ "@travetto/schema": "^6.0.1",
34
34
  "find-my-way": "^9.3.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "@travetto/cli": "^6.0.0",
38
- "@travetto/test": "^6.0.1",
39
- "@travetto/transformer": "^6.0.0"
37
+ "@travetto/cli": "^6.0.1",
38
+ "@travetto/test": "^6.0.2",
39
+ "@travetto/transformer": "^6.0.1"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
42
  "@travetto/transformer": {
@@ -15,7 +15,7 @@ export class WebHeaders extends Headers {
15
15
 
16
16
  if (o && !passed) {
17
17
  for (const [k, v] of (Array.isArray(o) ? o : Object.entries(o))) {
18
- if (v !== undefined && v !== null) {
18
+ if (v !== undefined && v !== null && !k.startsWith(':')) {
19
19
  this.append(k, castTo(v));
20
20
  }
21
21
  }
@@ -24,13 +24,13 @@ const ERROR_CATEGORY_STATUS: Record<ErrorCategory, number> = {
24
24
  unavailable: 503,
25
25
  };
26
26
 
27
- export class WebCommonUtil {
28
- static #unitMapping: Record<string, number> = {
29
- kb: 2 ** 10,
30
- mb: 2 ** 20,
31
- gb: 2 ** 30,
32
- };
27
+ const UNIT_MAPPING: Record<string, number> = {
28
+ kb: 2 ** 10,
29
+ mb: 2 ** 20,
30
+ gb: 2 ** 30,
31
+ };
33
32
 
33
+ export class WebCommonUtil {
34
34
  static #convert(rule: string): RegExp {
35
35
  const core = (rule.endsWith('/*') || !rule.includes('/')) ?
36
36
  `${rule.replace(/[/].{0,20}$/, '')}\/.*` : rule;
@@ -148,6 +148,6 @@ export class WebCommonUtil {
148
148
  return input;
149
149
  }
150
150
  const [, num, unit] = input.toLowerCase().split(/(\d+)/);
151
- return parseInt(num, 10) * (this.#unitMapping[unit] ?? 1);
151
+ return parseInt(num, 10) * (UNIT_MAPPING[unit] ?? 1);
152
152
  }
153
153
  }
package/src/util/net.ts CHANGED
@@ -58,4 +58,18 @@ export class NetUtil {
58
58
 
59
59
  return useIPv4 ? '0.0.0.0' : '::';
60
60
  }
61
+
62
+ /**
63
+ * Free a port if it is in use, typically used to resolve port conflicts.
64
+ * @param err The error that may indicate a port conflict
65
+ * @returns Returns true if the port was freed, false if not handled
66
+ */
67
+ static async freePortOnConflict(err: unknown): Promise<boolean> {
68
+ if (NetUtil.isPortUsedError(err) && typeof err.port === 'number') {
69
+ await NetUtil.freePort(err.port);
70
+ return true;
71
+ } else {
72
+ return false;
73
+ }
74
+ }
61
75
  }
@@ -64,30 +64,11 @@ export class WebTestDispatchUtil {
64
64
  return response;
65
65
  }
66
66
 
67
- static async toFetchRequestInit(request: WebRequest): Promise<{ init: RequestInit, path: string }> {
68
- const { context: { httpQuery: query, httpMethod: method, path }, headers } = request;
69
-
70
- let q = '';
71
- if (query && Object.keys(query).length) {
72
- const pairs = Object.fromEntries(Object.entries(query).map(([k, v]) => [k, v === null || v === undefined ? '' : `${v}`] as const));
73
- q = `?${new URLSearchParams(pairs).toString()}`;
67
+ static buildPath(request: WebRequest): string {
68
+ const params = new URLSearchParams();
69
+ for (const [k, v] of Object.entries(request.context.httpQuery ?? {})) {
70
+ params.set(k, v === null || v === undefined ? '' : `${v}`);
74
71
  }
75
-
76
- const finalPath = `${path}${q}`;
77
-
78
- const body: RequestInit['body'] =
79
- WebBodyUtil.isRaw(request.body) ?
80
- await toBuffer(request.body) :
81
- castTo(request.body);
82
-
83
- return { path: finalPath, init: { headers, method, body } };
84
- }
85
-
86
- static async fromFetchResponse(response: Response): Promise<WebResponse> {
87
- return new WebResponse({
88
- body: Buffer.from(await response.arrayBuffer()),
89
- context: { httpStatusCode: response.status },
90
- headers: response.headers
91
- });
72
+ return [request.context.path, params.toString()].join('?').replace(/[?]$/, '');
92
73
  }
93
74
  }
@@ -18,7 +18,7 @@ export class WebTestConfig implements ConfigSource {
18
18
  cookie: { secure: false },
19
19
  trustProxy: { ips: ['*'] },
20
20
  http: {
21
- ssl: { active: false },
21
+ tls: false,
22
22
  port: -1,
23
23
  },
24
24
  etag: {