@travetto/web 7.0.0-rc.4 → 7.0.0-rc.6

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
@@ -13,9 +13,9 @@ npm install @travetto/web
13
13
  yarn add @travetto/web
14
14
  ```
15
15
 
16
- The module provides a declarative API for creating and describing a Web application. Since the framework is declarative, decorators are used to configure almost everything. The general layout of an application is a collection of [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L11)s that employ some combination of [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)s to help manage which functionality is executed before the [Endpoint](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L14) code, within the [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L11). This module will look at:
16
+ The module provides a declarative API for creating and describing a Web application. Since the framework is declarative, decorators are used to configure almost everything. The general layout of an application is a collection of [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L12)s that employ some combination of [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)s to help manage which functionality is executed before the [Endpoint](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L14) code, within the [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L12). This module will look at:
17
17
  * Request/Response Pattern
18
- * Defining a [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L11)
18
+ * Defining a [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L12)
19
19
  * Defining an [Endpoint](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L14)
20
20
  * Using a [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)
21
21
  * Creating a Custom [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)
@@ -91,7 +91,7 @@ export class WebResponse<B = unknown> extends BaseWebMessage<B, WebResponseConte
91
91
  These objects do not represent the underlying sockets provided by various http servers, but in fact are simple wrappers that track the flow through the call stack of the various [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15)s and the [Endpoint](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L14) handler. One of the biggest departures here, is that the response is not an entity that is passed around from call-site to call-site, but is is solely a return-value. This doesn't mean the return value has to be static and pre-allocated, on the contrary streams are still supported. The difference here is that the streams/asynchronous values will be consumed until the response is sent back to the user. The [CompressInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/compress.ts#L44) is a good reference for transforming a [WebResponse](https://github.com/travetto/travetto/tree/main/module/web/src/types/response.ts#L3) that can either be a stream or a fixed value.
92
92
 
93
93
  ## Defining a Controller
94
- To start, we must define a [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L11), which is only allowed on classes. Controllers can be configured with:
94
+ To start, we must define a [@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L12), which is only allowed on classes. Controllers can be configured with:
95
95
  * `path` - The required context path the controller will operate atop
96
96
  * `title` - The definition of the controller
97
97
  * `description` - High level description fo the controller
@@ -378,7 +378,7 @@ Out of the box, the web framework comes with a few interceptors, and more are co
378
378
  1. global - Intended to run outside of the request flow - [AsyncContextInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/context.ts#L13)
379
379
  1. terminal - Handles once request and response are finished building - [LoggingInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/logging.ts#L28), [RespondInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/respond.ts#L12)
380
380
  1. pre-request - Prepares the request for running - [TrustProxyInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/trust-proxy.ts#L23)
381
- 1. request - Handles inbound request, validation, and body preparation - [DecompressInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/decompress.ts#L53), [AcceptInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/accept.ts#L33), [BodyInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/body.ts#L58), [CookieInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/cookie.ts#L60)
381
+ 1. request - Handles inbound request, validation, and body preparation - [DecompressInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/decompress.ts#L53), [AcceptInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/accept.ts#L33), [BodyInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/body.ts#L57), [CookieInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/cookie.ts#L60)
382
382
  1. response - Prepares outbound response - [CompressInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/compress.ts#L44), [CorsInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/cors.ts#L51), [EtagInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/etag.ts#L43), [CacheControlInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/cache-control.ts#L23)
383
383
  1. application - Lives outside of the general request/response behavior, [Web Auth](https://github.com/travetto/travetto/tree/main/module/auth-web#readme "Web authentication integration support for the Travetto framework") uses this for login and logout flows.
384
384
 
@@ -504,7 +504,7 @@ export class CookieConfig implements CookieSetOptions {
504
504
  ```
505
505
 
506
506
  #### BodyInterceptor
507
- [BodyInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/body.ts#L58) handles the inbound request, and converting the body payload into an appropriate format.
507
+ [BodyInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/interceptor/body.ts#L57) handles the inbound request, and converting the body payload into an appropriate format.
508
508
 
509
509
  **Code: Body Config**
510
510
  ```typescript
@@ -675,11 +675,11 @@ export class AlowDenyController {
675
675
  ```
676
676
 
677
677
  The resolution logic is as follows:
678
- * Check the resolved [Endpoint](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L14)/[@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L11) overrides to see if an interceptor is explicitly allowed or disallowed
678
+ * Check the resolved [Endpoint](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/endpoint.ts#L14)/[@Controller](https://github.com/travetto/travetto/tree/main/module/web/src/decorator/controller.ts#L12) overrides to see if an interceptor is explicitly allowed or disallowed
679
679
  * Default to `applies()` logic for all available interceptors
680
680
 
681
681
  ## Creating a Custom WebInterceptor
682
- Additionally it may be desirable to create a custom interceptor. Interceptors can be registered with the [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.") by implementing the [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15) interface and adding an [@Injectable](https://github.com/travetto/travetto/tree/main/module/di/src/decorator.ts#L15) decorator. A simple logging interceptor:
682
+ Additionally it may be desirable to create a custom interceptor. Interceptors can be registered with the [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.") by implementing the [WebInterceptor](https://github.com/travetto/travetto/tree/main/module/web/src/types/interceptor.ts#L15) interface and adding an [@Injectable](https://github.com/travetto/travetto/tree/main/module/di/src/decorator.ts#L16) decorator. A simple logging interceptor:
683
683
 
684
684
  **Code: Defining a new Interceptor**
685
685
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/web",
3
- "version": "7.0.0-rc.4",
3
+ "version": "7.0.0-rc.6",
4
+ "type": "module",
4
5
  "description": "Declarative support for creating Web Applications",
5
6
  "keywords": [
6
7
  "web",
@@ -25,18 +26,18 @@
25
26
  "directory": "module/web"
26
27
  },
27
28
  "dependencies": {
28
- "@travetto/config": "^7.0.0-rc.3",
29
- "@travetto/context": "^7.0.0-rc.3",
30
- "@travetto/di": "^7.0.0-rc.3",
31
- "@travetto/registry": "^7.0.0-rc.3",
32
- "@travetto/runtime": "^7.0.0-rc.3",
33
- "@travetto/schema": "^7.0.0-rc.3",
29
+ "@travetto/config": "^7.0.0-rc.5",
30
+ "@travetto/context": "^7.0.0-rc.5",
31
+ "@travetto/di": "^7.0.0-rc.5",
32
+ "@travetto/registry": "^7.0.0-rc.5",
33
+ "@travetto/runtime": "^7.0.0-rc.5",
34
+ "@travetto/schema": "^7.0.0-rc.5",
34
35
  "find-my-way": "^9.3.0"
35
36
  },
36
37
  "peerDependencies": {
37
- "@travetto/cli": "^7.0.0-rc.3",
38
- "@travetto/test": "^7.0.0-rc.3",
39
- "@travetto/transformer": "^7.0.0-rc.3"
38
+ "@travetto/cli": "^7.0.0-rc.5",
39
+ "@travetto/test": "^7.0.0-rc.5",
40
+ "@travetto/transformer": "^7.0.0-rc.4"
40
41
  },
41
42
  "peerDependenciesMeta": {
42
43
  "@travetto/transformer": {
@@ -6,6 +6,7 @@ import { ControllerRegistryIndex } from '../registry/registry-index.ts';
6
6
  /**
7
7
  * Decorator to register a new web controller
8
8
  * @augments `@travetto/schema:Schema`
9
+ * @example opt-in
9
10
  * @kind decorator
10
11
  */
11
12
  export function Controller(path: string) {
@@ -50,7 +50,6 @@ export class WebBodyConfig {
50
50
  _limit: number | undefined;
51
51
  }
52
52
 
53
-
54
53
  /**
55
54
  * Verifies content length, decodes character encodings, and parses body input string via the content type
56
55
  */
@@ -52,7 +52,6 @@ export class DecompressConfig {
52
52
  @Injectable()
53
53
  export class DecompressInterceptor implements WebInterceptor<DecompressConfig> {
54
54
 
55
-
56
55
  static async decompress(headers: WebHeaders, input: Buffer | Readable, config: DecompressConfig): Promise<typeof input> {
57
56
  const encoding: WebDecompressEncoding | 'identity' = castTo(headers.getList('Content-Encoding')?.[0]) ?? 'identity';
58
57
 
@@ -10,7 +10,6 @@ export interface WebMessageInit<B = unknown, C = unknown> {
10
10
  body?: B;
11
11
  }
12
12
 
13
-
14
13
  export interface WebMessage<B = unknown, C = unknown> {
15
14
  readonly context: C;
16
15
  readonly headers: WebHeaders;
@@ -55,7 +55,6 @@ export class WebCommonUtil {
55
55
  return edgeMap;
56
56
  }
57
57
 
58
-
59
58
  /**
60
59
  * Build matcher
61
60
  */
@@ -11,7 +11,6 @@ import { EndpointConfig, ControllerConfig, EndpointParameterConfig, EndpointFunc
11
11
  import { ControllerRegistryIndex } from '../registry/registry-index.ts';
12
12
  import { WebCommonUtil } from './common.ts';
13
13
 
14
-
15
14
  const WebQueryExpandedSymbol = Symbol();
16
15
 
17
16
  /**
@@ -80,7 +79,6 @@ export class EndpointUtil {
80
79
  ]);
81
80
  }
82
81
 
83
-
84
82
  /**
85
83
  * Extract parameter value from request
86
84
  * @param request The request
@@ -111,7 +109,7 @@ export class EndpointUtil {
111
109
  if (param.extract) {
112
110
  return param.extract(request, param);
113
111
  } else if (param.location === 'query') {
114
- // TODO: Revisit this logic?
112
+ // TODO: Revisit the prefix logic/structure in general
115
113
  const withQuery: typeof request & { [WebQueryExpandedSymbol]?: Record<string, unknown> } = request;
116
114
  const query = withQuery[WebQueryExpandedSymbol] ??= BindUtil.expandPaths(request.context.httpQuery ?? {});
117
115
  if (param.prefix) { // Has a prefix provided
@@ -225,7 +223,6 @@ export class EndpointUtil {
225
223
  return castTo(result);
226
224
  }
227
225
 
228
-
229
226
  /**
230
227
  * Get bound endpoints, honoring the conditional status
231
228
  */
@@ -268,7 +265,6 @@ export class EndpointUtil {
268
265
  .map(([endpoint,]) => endpoint);
269
266
  }
270
267
 
271
-
272
268
  /**
273
269
  * Order interceptors
274
270
  */