@travetto/web 8.0.0-alpha.0 → 8.0.0-alpha.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/web",
3
- "version": "8.0.0-alpha.0",
3
+ "version": "8.0.0-alpha.10",
4
4
  "type": "module",
5
5
  "description": "Declarative support for creating Web Applications",
6
6
  "keywords": [
@@ -26,18 +26,18 @@
26
26
  "directory": "module/web"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^8.0.0-alpha.0",
30
- "@travetto/context": "^8.0.0-alpha.0",
31
- "@travetto/di": "^8.0.0-alpha.0",
32
- "@travetto/registry": "^8.0.0-alpha.0",
33
- "@travetto/runtime": "^8.0.0-alpha.0",
34
- "@travetto/schema": "^8.0.0-alpha.0",
29
+ "@travetto/config": "^8.0.0-alpha.9",
30
+ "@travetto/context": "^8.0.0-alpha.9",
31
+ "@travetto/di": "^8.0.0-alpha.9",
32
+ "@travetto/registry": "^8.0.0-alpha.9",
33
+ "@travetto/runtime": "^8.0.0-alpha.9",
34
+ "@travetto/schema": "^8.0.0-alpha.9",
35
35
  "find-my-way": "^9.5.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@travetto/cli": "^8.0.0-alpha.0",
39
- "@travetto/test": "^8.0.0-alpha.0",
40
- "@travetto/transformer": "^8.0.0-alpha.0"
38
+ "@travetto/cli": "^8.0.0-alpha.14",
39
+ "@travetto/test": "^8.0.0-alpha.9",
40
+ "@travetto/transformer": "^8.0.0-alpha.4"
41
41
  },
42
42
  "peerDependenciesMeta": {
43
43
  "@travetto/transformer": {
package/src/context.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AsyncContextValue, type AsyncContext } from '@travetto/context';
2
- import { Inject, Injectable } from '@travetto/di';
2
+ import { Inject, Injectable, PostConstruct } from '@travetto/di';
3
3
  import { RuntimeError, castTo, type Class } from '@travetto/runtime';
4
4
 
5
5
  import { WebRequest } from './types/request.ts';
@@ -20,7 +20,8 @@ export class WebAsyncContext {
20
20
  return this.#request.get()!;
21
21
  }
22
22
 
23
- postConstruct(): void {
23
+ @PostConstruct()
24
+ exposeContext(): void {
24
25
  this.registerSource(WebRequest, () => this.#request.get());
25
26
  }
26
27
 
@@ -12,6 +12,6 @@ import { ControllerRegistryIndex } from '../registry/registry-index.ts';
12
12
  export function Controller(path: string) {
13
13
  return function <T>(cls: Class<T>): void {
14
14
  ControllerRegistryIndex.getForRegister(cls).register({ basePath: path, class: cls, });
15
- DependencyRegistryIndex.getForRegister(cls).registerClass();
15
+ DependencyRegistryIndex.registerClass(cls);
16
16
  };
17
17
  }
@@ -1,4 +1,4 @@
1
- import { Injectable, Inject, DependencyRegistryIndex } from '@travetto/di';
1
+ import { Injectable, Inject, DependencyRegistryIndex, PostConstruct } from '@travetto/di';
2
2
  import { Config } from '@travetto/config';
3
3
  import { toConcrete } from '@travetto/runtime';
4
4
  import { Ignore } from '@travetto/schema';
@@ -63,7 +63,8 @@ export class BodyInterceptor implements WebInterceptor<WebBodyConfig> {
63
63
  @Inject()
64
64
  config: WebBodyConfig;
65
65
 
66
- async postConstruct(): Promise<void> {
66
+ @PostConstruct()
67
+ async loadParsers(): Promise<void> {
67
68
  // Load all the parser types
68
69
  const instances = await DependencyRegistryIndex.getInstances(toConcrete<BodyContentParser>());
69
70
  for (const instance of instances) {
@@ -1,4 +1,4 @@
1
- import { Injectable, Inject } from '@travetto/di';
1
+ import { Injectable, Inject, PostConstruct } from '@travetto/di';
2
2
  import { Config } from '@travetto/config';
3
3
  import { Secret } from '@travetto/schema';
4
4
  import { type AsyncContext, AsyncContextValue } from '@travetto/context';
@@ -78,7 +78,8 @@ export class CookieInterceptor implements WebInterceptor<CookieConfig> {
78
78
  @Inject()
79
79
  context: AsyncContext;
80
80
 
81
- postConstruct(): void {
81
+ @PostConstruct()
82
+ exposeContext(): void {
82
83
  this.webAsyncContext.registerSource(CookieJar, () => this.#cookieJar.get());
83
84
  this.keyGrip ??= new KeyGrip(this.config.keys ?? []);
84
85
  }
@@ -58,7 +58,7 @@ function combineEndpointConfigs(controller: ControllerConfig, base: EndpointConf
58
58
  function computeParameterLocation(endpoint: EndpointConfig, param: SchemaParameterConfig): EndpointParamLocation {
59
59
  const name = param?.name;
60
60
  if (!SchemaRegistryIndex.has(param.type)) {
61
- if ((param.type === String || param.type === Number) && name && endpoint.path.includes(`:${name}`)) {
61
+ if ((param.type === String || param.type === Number) && name && endpoint.fullPath.includes(`:${name}`)) {
62
62
  return 'path';
63
63
  } else if (param.binary) {
64
64
  return 'body';
@@ -74,10 +74,10 @@ export class ControllerRegistryIndex implements RegistryIndex {
74
74
  * @param target Controller class
75
75
  */
76
76
  bindContextParamsOnPostConstruct(cls: Class): void {
77
- DependencyRegistryIndex.registerClassMetadata(cls, {
78
- postConstruct: {
79
- ContextParam: (instance: ClassInstance) => this.#bindContextParams(instance)
80
- }
77
+ const bind = (instance: ClassInstance): Promise<void> => this.#bindContextParams(instance);
78
+ DependencyRegistryIndex.registerPostConstruct(cls, {
79
+ operation(this: ClassInstance): Promise<void> { return bind(this); },
80
+ priority: 100
81
81
  });
82
82
  }
83
83
 
@@ -1,5 +1,5 @@
1
1
  import { type Class, toConcrete } from '@travetto/runtime';
2
- import { DependencyRegistryIndex, Injectable } from '@travetto/di';
2
+ import { DependencyRegistryIndex, Injectable, PostConstruct } from '@travetto/di';
3
3
  import { ControllerRegistryIndex } from '@travetto/web';
4
4
 
5
5
  import type { ControllerConfig, EndpointConfig } from '../registry/types.ts';
@@ -34,7 +34,8 @@ export abstract class BaseWebRouter implements WebRouter {
34
34
  /**
35
35
  * Initialize router, encapsulating common patterns for standard router setup
36
36
  */
37
- async postConstruct(): Promise<void> {
37
+ @PostConstruct()
38
+ async registerRoutes(): Promise<void> {
38
39
 
39
40
  this.#interceptors = await DependencyRegistryIndex.getInstances(toConcrete<WebInterceptor>());
40
41
  this.#interceptors = EndpointUtil.orderInterceptors(this.#interceptors);
@@ -98,4 +98,12 @@ export class TestController {
98
98
  notFound() {
99
99
  throw new RuntimeError('Uh-oh', { category: 'general' });
100
100
  }
101
+ }
102
+
103
+ @Controller('/users/:userId')
104
+ class ParentParamController {
105
+ @Get('/')
106
+ async getUser(userId: string) {
107
+ return { userId };
108
+ }
101
109
  }
@@ -168,4 +168,10 @@ export abstract class StandardWebServerSuite extends BaseWebSuite {
168
168
  const response = await this.request<{ path: string }>({ context: { httpMethod: 'GET', path: '/test/fun/1/2/3/4' } });
169
169
  assert(response.body?.path === '1/2/3/4');
170
170
  }
171
+
172
+ @Test()
173
+ async testInheritedPathParam() {
174
+ const response = await this.request<{ userId: string }>({ context: { httpMethod: 'GET', path: '/users/1234' } });
175
+ assert(response.body?.userId === '1234');
176
+ }
171
177
  }