Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: rpc support multiple params (#4271)
Wenzhao Hu1dae650da82e
diff --git a/packages/rpc/src/services/rpc/__tests__/rpc.service.spec.ts b/packages/rpc/src/services/rpc/__tests__/rpc.service.spec.tsindex 42eb84e937..8587277ee7 100644--- a/packages/rpc/src/services/rpc/__tests__/rpc.service.spec.ts+++ b/packages/rpc/src/services/rpc/__tests__/rpc.service.spec.ts@@ -14,13 +14,12 @@* limitations under the License.*/+import type { Observable } from 'rxjs';+import type { IMessageProtocol } from '../rpc.service';import { awaitTime } from '@univerjs/core';import { of, Subject } from 'rxjs';import { beforeEach, describe, expect, it } from 'vitest';--import type { Observable } from 'rxjs';import { ChannelClient, ChannelServer, fromModule, toModule } from '../rpc.service';-import type { IMessageProtocol } from '../rpc.service';describe('Test ChannelClient & ChannelServer', () => {let clientProtocol: TestMessageProtocolForClient;diff --git a/packages/rpc/src/services/rpc/rpc.service.ts b/packages/rpc/src/services/rpc/rpc.service.tsindex b53f3c4f67..70ac733766 100644--- a/packages/rpc/src/services/rpc/rpc.service.ts+++ b/packages/rpc/src/services/rpc/rpc.service.ts@@ -14,6 +14,8 @@* limitations under the License.*/+/* eslint-disable ts/no-explicit-any */+import type { Subscription } from 'rxjs';import { RxDisposable } from '@univerjs/core';import { BehaviorSubject, firstValueFrom, isObservable, Observable, of } from 'rxjs';@@ -23,9 +25,7 @@ import { filter, take, takeUntil } from 'rxjs/operators';/** This protocol is for transferring data from the two peer univer instance running in different locations. */export interface IMessageProtocol {- // eslint-disable-next-line ts/no-explicit-anysend(message: any): void;- // eslint-disable-next-line ts/no-explicit-anyonMessage: Observable<any>;}@@ -36,9 +36,7 @@ export interface IMessageProtocol {* event sources are usually provided by the same service or controller.*/export interface IChannel {- // eslint-disable-next-line ts/no-explicit-anycall<T>(method: string, args?: any): Promise<T>;- // eslint-disable-next-line ts/no-explicit-anysubscribe<T>(event: string, args?: any): Observable<T>;}@@ -60,7 +58,7 @@ export function fromModule(module: unknown): IChannel {call<T>(method: string, args?: any): Promise<T> {const target = handler[method];if (typeof target === 'function') {- let res = target.apply(handler, [args]);+ let res = args ? target.apply(handler, args) : target.call(handler);if (!(res instanceof Promise)) {res = Promise.resolve(res);}@@ -70,10 +68,10 @@ export function fromModule(module: unknown): IChannel {throw new Error(`[RPC]: method not found for ${method}!`);}- subscribe<T>(eventMethod: string, args: any): Observable<T> {+ subscribe<T>(eventMethod: string, args?: any): Observable<T> {const target = handler[eventMethod];if (typeof target === 'function') {- const res = target.apply(handler, args);+ const res = args ? target.apply(handler, args) : target.call(handler);if (!isObservable(res)) {return of(res);}@@ -104,11 +102,11 @@ export function toModule<T extends object>(channel: IChannel): T {return function (...args: any[]) {const isObservable = propertyIsEventSource(propKey);if (isObservable) {- const observable = channel.subscribe(propKey, args[0]);+ const observable = channel.subscribe(propKey, args);return observable;}- return channel.call(propKey, args[0]);+ return channel.call(propKey, args);};},});@@ -153,7 +151,7 @@ interface IRPCRequest {type: RequestType;channelName: string;method: string;- args?: any;+ args?: any[];}enum ResponseType {@@ -388,7 +386,7 @@ export class ChannelServer extends RxDisposable implements IChannelServer {if (!channel) {throw new Error(`[ChannelServer]: Channel ${channelName} not found!`);}- promise = channel.call(method, args);+ promise = args ? channel.call(method, args) : channel.call(method);} catch (err: unknown) {promise = Promise.reject(err);}