@oox/client 1.0.0 → 1.0.2

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/proxy.js ADDED
@@ -0,0 +1,30 @@
1
+ import { rpc } from './keepalive-connection.js';
2
+ /**
3
+ * 为了不重复创建Proxy,这个对象用于保存各个RPC服务的各个属性Proxy
4
+ */
5
+ const rpcServiceAttrMap = Object.create(null);
6
+ export function proxy(name, action = '') {
7
+ return new Proxy(function () { }, {
8
+ get(target, key) {
9
+ if (typeof key !== 'string')
10
+ return undefined;
11
+ const attrKey = action ? action + '.' + key : key;
12
+ const attrKeyPath = name + '.' + attrKey;
13
+ if (attrKeyPath in rpcServiceAttrMap) {
14
+ // 不重复创建Proxy
15
+ return rpcServiceAttrMap[attrKeyPath];
16
+ }
17
+ const attrProxy = proxy(name, attrKey);
18
+ rpcServiceAttrMap[attrKeyPath] = attrProxy;
19
+ return attrProxy;
20
+ },
21
+ has(target, key) {
22
+ if (typeof key !== 'string')
23
+ return false;
24
+ return true;
25
+ },
26
+ apply(target, thisArg, args) {
27
+ return rpc(name, action, args);
28
+ }
29
+ });
30
+ }
package/types/app.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface ReturnsBody<T = any> {
9
9
  stack?: string;
10
10
  };
11
11
  }
12
- export declare const eventHub: EventEmitter<any>;
12
+ export declare const eventHub: EventEmitter<[never]>;
13
13
  /**
14
14
  * the kvMethods is all actions refs [has bind this]
15
15
  */
package/types/config.d.ts CHANGED
@@ -11,4 +11,5 @@ export declare class Config implements ConfigInterface {
11
11
  id: string;
12
12
  name: string;
13
13
  }
14
+ export declare const config: Config;
14
15
  export {};
@@ -16,3 +16,10 @@ export declare class Context extends AppContext {
16
16
  constructor(context?: Partial<Context>);
17
17
  toJSON?(): {} & this;
18
18
  }
19
+ export declare function setGenTraceIdFunction(fn: () => string): void;
20
+ /**
21
+ * 生成随机不重复id
22
+ */
23
+ export declare function genTraceId(): string;
24
+ export declare function genContext(context?: Context): Context;
25
+ export declare function getContext(): Context;
package/types/index.d.ts CHANGED
@@ -1,23 +1,7 @@
1
- import { Context } from "./context.js";
2
- import { Config } from './config.js';
3
- import { KeepAliveConnection, KeepAliveNativeConnection } from "./keepalive-connection.js";
4
- export declare const config: Config;
5
- export declare function setGenTraceIdFunction(fn: () => string): void;
6
- /**
7
- * 生成随机不重复id
8
- */
9
- export declare function genTraceId(): string;
10
- export declare function genContext(context?: Context): Context;
11
- export declare function getContext(): Context;
12
- export declare function addKeepAliveConnection(connection: KeepAliveConnection<KeepAliveNativeConnection>): void;
13
- export declare function removeKeepAliveConnection(connection: KeepAliveConnection<KeepAliveNativeConnection>): void;
14
- export declare function removeKeepAliveConnection(name: string, id: string): void;
15
- export declare function setLoadBalancePolicy(policy: (name: string) => KeepAliveConnection<KeepAliveNativeConnection>): void;
16
- export declare function rpc(appName: string, action: string, params: any[], context?: Context): Promise<any>;
17
- export declare function rpc(connection: KeepAliveConnection<KeepAliveNativeConnection>, action: string, params: any[], context?: Context): Promise<any>;
18
1
  export * from './app.js';
19
- export * from './context.js';
20
2
  export * from './config.js';
21
- export * as logger from './logger.js';
3
+ export * from './context.js';
22
4
  export * from './keepalive-connection.js';
23
5
  export * from './keepalive-connection-sample.js';
6
+ export * as logger from './logger.js';
7
+ export * from './proxy.js';
@@ -1,6 +1,6 @@
1
+ import { ReturnsBody } from './app.js';
1
2
  import { Context, KeepAliveRPCContext } from './context.js';
2
3
  import { KeepAliveConnection, KeepAliveConnectionData, KeepAliveNativeConnection, KeepAliveConnectionAdapter, KeepAliveSyncConnectionsQuery } from './keepalive-connection.js';
3
- import { ReturnsBody } from './index.js';
4
4
  export interface SampleKeepAliveNativeConnection extends KeepAliveNativeConnection {
5
5
  connected: boolean;
6
6
  connect?(): void;
@@ -101,4 +101,10 @@ export declare class KeepAliveConnectionStore<T extends KeepAliveNativeConnectio
101
101
  export declare const keepAliveConnectionAdapters: Map<string, KeepAliveConnectionAdapter<KeepAliveNativeConnection>>;
102
102
  export declare const keepAliveConnections: KeepAliveConnectionStore<KeepAliveNativeConnection>;
103
103
  export declare const enabledKeepAliveConnections: KeepAliveConnectionStore<KeepAliveNativeConnection>;
104
+ export declare function addKeepAliveConnection(connection: KeepAliveConnection<KeepAliveNativeConnection>): void;
105
+ export declare function removeKeepAliveConnection(connection: KeepAliveConnection<KeepAliveNativeConnection>): void;
106
+ export declare function removeKeepAliveConnection(name: string, id: string): void;
107
+ export declare function setLoadBalancePolicy(policy: (name: string) => KeepAliveConnection<KeepAliveNativeConnection>): void;
108
+ export declare function rpc(appName: string, action: string, params: any[], context?: Context): Promise<any>;
109
+ export declare function rpc(connection: KeepAliveConnection<KeepAliveNativeConnection>, action: string, params: any[], context?: Context): Promise<any>;
104
110
  export {};
@@ -0,0 +1 @@
1
+ export declare function proxy(name: string, action?: string): () => void;