@travetto/web-rpc 6.0.2 → 7.0.0-rc.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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ npm install @travetto/web-rpc
13
13
  yarn add @travetto/web-rpc
14
14
  ```
15
15
 
16
- This module allows for a highly focused scenario, of supporting RPC operations within a [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative api for Web Applications with support for the dependency injection.") application. The module takes care of producing the appropriate handler for the RPC commands along with the ability to generate the appropriate client to be used to interact with the RPC functionality. The generated client uses Proxy-based objects, along with [Typescript](https://typescriptlang.org) magic to create a dynamic client that does not rely on generating a lot of code.
16
+ This module allows for a highly focused scenario, of supporting RPC operations within a [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications") application. The module takes care of producing the appropriate handler for the RPC commands along with the ability to generate the appropriate client to be used to interact with the RPC functionality. The generated client uses Proxy-based objects, along with [Typescript](https://typescriptlang.org) magic to create a dynamic client that does not rely on generating a lot of code.
17
17
 
18
18
  ## CLI - web:rpc-client
19
19
  The library will create the RPC client in one of three flavors: fetch, fetch + node, angular.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/web-rpc",
3
- "version": "6.0.2",
3
+ "version": "7.0.0-rc.0",
4
4
  "description": "RPC support for a Web Application",
5
5
  "keywords": [
6
6
  "web",
@@ -26,9 +26,9 @@
26
26
  "directory": "module/web-rpc"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^6.0.0",
30
- "@travetto/schema": "^6.0.0",
31
- "@travetto/web": "^6.0.2"
29
+ "@travetto/config": "^7.0.0-rc.0",
30
+ "@travetto/schema": "^7.0.0-rc.0",
31
+ "@travetto/web": "^7.0.0-rc.0"
32
32
  },
33
33
  "travetto": {
34
34
  "displayName": "Web RPC Support"
package/src/controller.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Inject } from '@travetto/di';
2
2
  import { Any, AppError, Util } from '@travetto/runtime';
3
+ import { IsPrivate } from '@travetto/schema';
3
4
  import {
4
- HeaderParam, Controller, Undocumented, ExcludeInterceptors, ControllerRegistry,
5
+ HeaderParam, Controller, ExcludeInterceptors, ControllerRegistryIndex,
5
6
  WebAsyncContext, Body, EndpointUtil, BodyInterceptor, Post, WebCommonUtil,
6
7
  RespondInterceptor, DecompressInterceptor, Get
7
8
  } from '@travetto/web';
@@ -13,7 +14,7 @@ import {
13
14
  val instanceof RespondInterceptor ||
14
15
  val.category === 'global'
15
16
  ))
16
- @Undocumented()
17
+ @IsPrivate()
17
18
  export class WebRpcController {
18
19
 
19
20
  @Inject()
@@ -32,7 +33,7 @@ export class WebRpcController {
32
33
  */
33
34
  @Post('/:target')
34
35
  async onRequest(target: string, @HeaderParam('X-TRV-RPC-INPUTS') paramInput?: string, @Body() body?: Any): Promise<unknown> {
35
- const endpoint = ControllerRegistry.getEndpointById(target);
36
+ const endpoint = ControllerRegistryIndex.getEndpointConfigById(target);
36
37
 
37
38
  if (!endpoint || !endpoint.filter) {
38
39
  throw new AppError('Unknown endpoint', { category: 'notfound' });
@@ -48,7 +49,7 @@ export class WebRpcController {
48
49
  } else if (Array.isArray(body)) { // Params passed via body
49
50
  params = body;
50
51
 
51
- const bodyParamIdx = endpoint.params.findIndex((x) => x.location === 'body');
52
+ const bodyParamIdx = endpoint.parameters.findIndex((x) => x.location === 'body');
52
53
  if (bodyParamIdx >= 0) { // Re-assign body
53
54
  request.body = params[bodyParamIdx];
54
55
  }
@@ -58,7 +59,7 @@ export class WebRpcController {
58
59
  params = [];
59
60
  }
60
61
 
61
- const final = endpoint.params.map((x, i) => (x.location === 'body' && paramInput) ? EndpointUtil.MissingParamSymbol : params[i]);
62
+ const final = endpoint.parameters.map((x, i) => (x.location === 'body' && paramInput) ? EndpointUtil.MissingParamSymbol : params[i]);
62
63
  WebCommonUtil.setRequestParams(request, final);
63
64
 
64
65
  // Dispatch
package/src/service.ts CHANGED
@@ -2,14 +2,16 @@ import path from 'node:path';
2
2
  import fs from 'node:fs/promises';
3
3
 
4
4
  import { Inject, Injectable } from '@travetto/di';
5
- import { ControllerRegistry } from '@travetto/web';
5
+ import { ControllerRegistryIndex } from '@travetto/web';
6
6
  import { Runtime, RuntimeIndex } from '@travetto/runtime';
7
7
  import { ManifestModuleUtil } from '@travetto/manifest';
8
+ import { Registry } from '@travetto/registry';
9
+ import { SchemaRegistryIndex } from '@travetto/schema';
8
10
 
9
11
  import { clientFactory } from '../support/client/rpc.ts';
10
12
  import { WebRpcClient, WebRpcConfig } from './config.ts';
11
13
 
12
- @Injectable({ autoCreate: !Runtime.production })
14
+ @Injectable({ autoInject: !Runtime.production })
13
15
  export class WebRpcClientGeneratorService {
14
16
 
15
17
  @Inject()
@@ -21,16 +23,16 @@ export class WebRpcClientGeneratorService {
21
23
  if (!this.config.clients.length || !Runtime.dynamic) {
22
24
  return;
23
25
  }
24
- ControllerRegistry.on(() => this.render());
26
+ Registry.onClassChange(() => this.render(), ControllerRegistryIndex);
25
27
  }
26
28
 
27
29
  async #getClasses(relativeTo: string): Promise<{ name: string, import: string }[]> {
28
- return ControllerRegistry.getClasses()
30
+ return ControllerRegistryIndex.getClasses()
29
31
  .filter(x => {
30
32
  const entry = RuntimeIndex.getEntry(Runtime.getSourceFile(x));
31
33
  return entry && entry.role === 'std';
32
34
  })
33
- .filter(x => ControllerRegistry.get(x).documented !== false)
35
+ .filter(x => SchemaRegistryIndex.getConfig(x).private !== true)
34
36
  .map(x => {
35
37
  const imp = ManifestModuleUtil.withOutputExtension(Runtime.getImport(x));
36
38
  const base = Runtime.workspaceRelative(RuntimeIndex.manifest.build.typesFolder);
@@ -2,8 +2,8 @@ import path from 'node:path';
2
2
 
3
3
  import { Env } from '@travetto/runtime';
4
4
  import { CliCommand, CliCommandShape, CliValidationResultError } from '@travetto/cli';
5
- import { DependencyRegistry } from '@travetto/di';
6
- import { RootRegistry } from '@travetto/registry';
5
+ import { DependencyRegistryIndex } from '@travetto/di';
6
+ import { Registry } from '@travetto/registry';
7
7
  import { Ignore } from '@travetto/schema';
8
8
 
9
9
  import type { WebRpcClient } from '../src/config.ts';
@@ -24,7 +24,7 @@ export class CliWebRpcCommand implements CliCommandShape {
24
24
  }
25
25
 
26
26
  get #service(): Promise<WebRpcClientGeneratorService> {
27
- return RootRegistry.init().then(() => DependencyRegistry.getInstance(WebRpcClientGeneratorService));
27
+ return Registry.init().then(() => DependencyRegistryIndex.getInstance(WebRpcClientGeneratorService));
28
28
  }
29
29
 
30
30
  async main(type: WebRpcClient['type'] | 'config', output?: string): Promise<void> {
@@ -25,6 +25,8 @@ export type RpcRequest = {
25
25
  timeout?: number;
26
26
  retriesOnConnectFailure?: number;
27
27
  path?: string;
28
+ controller?: string;
29
+ endpoint?: string;
28
30
  };
29
31
  url: URL | string;
30
32
  consumeJSON?: <T>(text?: unknown) => (T | Promise<T>);
@@ -72,7 +74,9 @@ function buildRequest<T extends RequestInit>(base: T, controller: string, endpoi
72
74
  return {
73
75
  ...base,
74
76
  method: 'POST',
75
- path: `${controller}:${endpoint}`
77
+ path: `${controller}:${endpoint}`,
78
+ controller,
79
+ endpoint
76
80
  };
77
81
  }
78
82