@zimi/remote 0.2.1-alpha.5 → 0.2.1-alpha.7

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/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { Remote, isRemoteAdaptorData } from './remote';
2
- export type { AdaptorPackageData, Adaptor } from './adaptor';
2
+ export type { Adaptor, AdaptorCallback, AdaptorPackageData } from './adaptor';
3
3
  export { RemoteError, RemoteNotFoundError, RemoteTimeoutError, response, } from './response';
4
4
  export { createIframeAdaptor } from './adaptors/iframe';
5
5
  export { createHttpAdaptor, remoteEventManager } from './adaptors/http';
6
+ export type { ToFunc } from './remoteValue/type';
6
7
  export { remoteValue } from './remoteValue/remoteValue';
7
8
  export { exposeToRemote } from './remoteValue/exposeToRemote';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEtD,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,GACT,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEtD,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,GACT,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA"}
@@ -4,6 +4,7 @@ type RemoteValueProps = Pick<AdaptorPackageData, 'deviceId' | 'targetDeviceId'>
4
4
  globalName: string;
5
5
  adaptor: Adaptor;
6
6
  timeoutMs?: number;
7
+ log?: boolean;
7
8
  };
8
9
  /**
9
10
  * @example
@@ -5,10 +5,13 @@ function noop() {
5
5
  function geneProxy(paths, props) {
6
6
  return new Proxy(noop, {
7
7
  apply(target, thisArg, argArray) {
8
- const { adaptor, globalName, timeoutMs = 30000, ...restProps } = props;
8
+ const { adaptor, globalName, timeoutMs = 30000, log = false, ...restProps } = props;
9
9
  const randomStr = Math.random().toString(36).slice(2);
10
10
  const name = `__REMOTE_VALUE_REQ__${globalName}`;
11
11
  const responseName = `__REMOTE_VALUE_RES__${[globalName, ...paths].join('.')}-${randomStr}`;
12
+ if (log) {
13
+ console.log(`[remoteValue] [${restProps.deviceId}] 正在访问远端 [${restProps.targetDeviceId}] 的变量: "${[globalName, ...paths].join('.')}"`);
14
+ }
12
15
  return new Promise((resolve, reject) => {
13
16
  let timer;
14
17
  const callback = (e) => {
@@ -1 +1 @@
1
- {"version":3,"file":"remoteValue.js","sourceRoot":"","sources":["../../src/remoteValue/remoteValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAY,MAAM,aAAa,CAAA;AAIvE,SAAS,IAAI;IACX,OAAO;AACT,CAAC;AAWD,SAAS,SAAS,CAAmB,KAAe,EAAE,KAAuB;IAC3E,OAAO,IAAI,KAAK,CAAY,IAA4B,EAAE;QACxD,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ;YAC7B,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,GAAG,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CAAC,CAAA;QACrD,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CAAmB,KAAuB;IACnE,OAAO,SAAS,CAAI,EAAE,EAAE,KAAK,CAAC,CAAA;AAChC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zimi/remote",
3
3
  "license": "MIT",
4
- "version": "0.2.1-alpha.5",
4
+ "version": "0.2.1-alpha.7",
5
5
  "author": "xiaomingTang",
6
6
  "description": "call remote functions as local",
7
7
  "private": false,
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Remote, isRemoteAdaptorData } from './remote'
2
- export type { AdaptorPackageData, Adaptor } from './adaptor'
2
+ export type { Adaptor, AdaptorCallback, AdaptorPackageData } from './adaptor'
3
3
  export {
4
4
  RemoteError,
5
5
  RemoteNotFoundError,
@@ -8,5 +8,6 @@ export {
8
8
  } from './response'
9
9
  export { createIframeAdaptor } from './adaptors/iframe'
10
10
  export { createHttpAdaptor, remoteEventManager } from './adaptors/http'
11
+ export type { ToFunc } from './remoteValue/type'
11
12
  export { remoteValue } from './remoteValue/remoteValue'
12
13
  export { exposeToRemote } from './remoteValue/exposeToRemote'
@@ -13,16 +13,29 @@ type RemoteValueProps = Pick<
13
13
  globalName: string
14
14
  adaptor: Adaptor
15
15
  timeoutMs?: number
16
+ log?: boolean
16
17
  }
17
18
 
18
19
  function geneProxy<T extends object>(paths: string[], props: RemoteValueProps) {
19
20
  return new Proxy<ToFunc<T>>(noop as unknown as ToFunc<T>, {
20
21
  apply(target, thisArg, argArray) {
21
- const { adaptor, globalName, timeoutMs = 30000, ...restProps } = props
22
+ const {
23
+ adaptor,
24
+ globalName,
25
+ timeoutMs = 30000,
26
+ log = false,
27
+ ...restProps
28
+ } = props
22
29
  const randomStr = Math.random().toString(36).slice(2)
23
30
  const name = `__REMOTE_VALUE_REQ__${globalName}`
24
31
  const responseName = `__REMOTE_VALUE_RES__${[globalName, ...paths].join('.')}-${randomStr}`
25
32
 
33
+ if (log) {
34
+ console.log(
35
+ `[remoteValue] [${restProps.deviceId}] 正在访问远端 [${restProps.targetDeviceId}] 的变量: "${[globalName, ...paths].join('.')}"`
36
+ )
37
+ }
38
+
26
39
  return new Promise((resolve, reject) => {
27
40
  let timer: NodeJS.Timeout | undefined
28
41
  const callback: AdaptorCallback = (e) => {