Skip to content

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.

chore: rename services in rpc package and export some dependencies (#1833)

Wenzhao Huceb7a72edaab
diff --git a/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts b/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts
index 282636c2f2..2197b3e30b 100644
--- a/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts
+++ b/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts
@@ -34,7 +34,7 @@ import {
RemoteInstanceServiceName,
RemoteSyncServiceName,
} from '../../services/remote-instance/remote-instance.service';
-import { IRPChannelService } from '../../services/rpc/channel.service';
+import { IRPCChannelService } from '../../services/rpc/channel.service';
import { fromModule, toModule } from '../../services/rpc/rpc.service';
/**
@@ -50,7 +50,7 @@ export class DataSyncPrimaryController extends RxDisposable {
@Inject(Injector) private readonly _injector: Injector,
@ICommandService private readonly _commandService: ICommandService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
- @IRPChannelService private readonly _rpcChannelService: IRPChannelService,
+ @IRPCChannelService private readonly _rpcChannelService: IRPCChannelService,
@IRemoteSyncService private readonly _remoteSyncService: IRemoteSyncService
) {
super();
@@ -76,6 +76,7 @@ export class DataSyncPrimaryController extends RxDisposable {
private _init(): void {
this._univerInstanceService.sheetAdded$.pipe(takeUntil(this.dispose$)).subscribe((sheet) => {
this._syncingUnits.add(sheet.getUnitId());
+
// If a sheet is created, it should sync the data to the worker thread.
this._remoteInstanceService.createInstance({
unitID: sheet.getUnitId(),
@@ -96,7 +97,9 @@ export class DataSyncPrimaryController extends RxDisposable {
// Mutations executed on the main thread should be synced to the worker thread.
this._commandService.onCommandExecuted((commandInfo, options) => {
const { type, params } = commandInfo;
- const unitID = (params as any)?.unitId || ''; // TODO@wzhudev: use a universal way to get unitId
+ // TODO@wzhudev: use a universal way to get unitId
+ const unitID = (params as any)?.unitId || '';
+
if (
// only sync mutations to the worker thread
type === CommandType.MUTATION &&
diff --git a/packages/rpc/src/controllers/data-sync/data-sync-replica.controller.ts b/packages/rpc/src/controllers/data-sync/data-sync-replica.controller.ts
index 2f7916ab33..43310a178e 100644
--- a/packages/rpc/src/controllers/data-sync/data-sync-replica.controller.ts
+++ b/packages/rpc/src/controllers/data-sync/data-sync-replica.controller.ts
@@ -25,7 +25,7 @@ import {
RemoteInstanceServiceName,
RemoteSyncServiceName,
} from '../../services/remote-instance/remote-instance.service';
-import { IRPChannelService } from '../../services/rpc/channel.service';
+import { IRPCChannelService } from '../../services/rpc/channel.service';
import { fromModule, toModule } from '../../services/rpc/rpc.service';
/**
@@ -40,7 +40,7 @@ export class DataSyncReplicaController extends Disposable {
@Inject(Injector) private readonly _injector: Injector,
@IRemoteInstanceService private readonly _remoteInstanceService: IRemoteInstanceService,
@ICommandService private readonly _commandService: ICommandService,
- @IRPChannelService private readonly _rpcChannelService: IRPChannelService
+ @IRPCChannelService private readonly _rpcChannelService: IRPCChannelService
) {
super();
diff --git a/packages/rpc/src/index.ts b/packages/rpc/src/index.ts
index 8f672d5038..a3f818080a 100644
--- a/packages/rpc/src/index.ts
+++ b/packages/rpc/src/index.ts
@@ -20,6 +20,14 @@ export {
UniverRPCMainThreadPlugin,
UniverRPCWorkerThreadPlugin,
} from './plugin';
-export { IRemoteInstanceService } from './services/remote-instance/remote-instance.service';
-export { IRPChannelService } from './services/rpc/channel.service';
+export { DataSyncReplicaController } from './controllers/data-sync/data-sync-replica.controller';
+export { DataSyncPrimaryController } from './controllers/data-sync/data-sync-primary.controller';
+export {
+ IRemoteInstanceService,
+ WebWorkerRemoteInstanceService,
+ RemoteInstanceServiceName,
+ RemoteSyncPrimaryService,
+ RemoteSyncServiceName,
+} from './services/remote-instance/remote-instance.service';
+export { ChannelService, IRPCChannelService } from './services/rpc/channel.service';
export { ChannelClient, ChannelServer, type IMessageProtocol } from './services/rpc/rpc.service';
diff --git a/packages/rpc/src/plugin.ts b/packages/rpc/src/plugin.ts
index 4240ff1cb9..c009e6984c 100644
--- a/packages/rpc/src/plugin.ts
+++ b/packages/rpc/src/plugin.ts
@@ -23,10 +23,10 @@ import { DataSyncReplicaController } from './controllers/data-sync/data-sync-rep
import {
IRemoteInstanceService,
IRemoteSyncService,
- RemoteInstanceReplicaService,
RemoteSyncPrimaryService,
+ WebWorkerRemoteInstanceService,
} from './services/remote-instance/remote-instance.service';
-import { ChannelService, IRPChannelService } from './services/rpc/channel.service';
+import { ChannelService, IRPCChannelService } from './services/rpc/channel.service';
import {
createWebWorkerMessagePortOnMain,
createWebWorkerMessagePortOnWorker,
@@ -56,7 +56,7 @@ export class UniverRPCMainThreadPlugin extends Plugin {
const messageProtocol = createWebWorkerMessagePortOnMain(worker);
const dependencies: Dependency[] = [
[
- IRPChannelService,
+ IRPCChannelService,
{
useFactory: () => new ChannelService(messageProtocol),
},
@@ -81,7 +81,7 @@ export class UniverRPCWorkerThreadPlugin extends Plugin {
static override type = PluginType.Univer;
constructor(
- private readonly _config: UniverRPCWorkerThreadPlugin,
+ private readonly _config: IUniverRPCWorkerThreadPluginConfig,
@Inject(Injector) protected readonly _injector: Injector
) {
super('UNIVER_RPC_WORKER_THREAD_PLUGIN');
@@ -92,12 +92,12 @@ export class UniverRPCWorkerThreadPlugin extends Plugin {
[
[DataSyncReplicaController],
[
- IRPChannelService,
+ IRPCChannelService,
{
useFactory: () => new ChannelService(createWebWorkerMessagePortOnWorker()),
},
],
- [IRemoteInstanceService, { useClass: RemoteInstanceReplicaService }],
+ [IRemoteInstanceService, { useClass: WebWorkerRemoteInstanceService }],
] as Dependency[]
).forEach((dependency) => injector.add(dependency));
diff --git a/packages/rpc/src/services/remote-instance/remote-instance.service.ts b/packages/rpc/src/services/remote-instance/remote-instance.service.ts
index 83a06894cf..84865b64ff 100644
--- a/packages/rpc/src/services/remote-instance/remote-instance.service.ts
+++ b/packages/rpc/src/services/remote-instance/remote-instance.service.ts
@@ -45,6 +45,7 @@ export class RemoteSyncPrimaryService implements IRemoteSyncService {
}
export const RemoteInstanceServiceName = 'univer.remote-instance-service';
+
/**
* This service is provided by the replica Univer.
*
@@ -60,7 +61,8 @@ export interface IRemoteInstanceService {
disposeInstance(params: { unitID: string }): Promise<boolean>;
syncMutation(params: { mutationInfo: IMutationInfo }): Promise<boolean>;
}
-export class RemoteInstanceReplicaService implements IRemoteInstanceService {
+
+export class WebWorkerRemoteInstanceService implements IRemoteInstanceService {
constructor(
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@ICommandService private readonly _commandService: ICommandService,
@@ -96,7 +98,7 @@ export class RemoteInstanceReplicaService implements IRemoteInstanceService {
return !!this._univerInstanceService.createSheet(snapshot);
default:
throw new Error(
- `[RemoteInstanceReplicaService]: cannot create replica for document type: ${type}.`
+ `[WebWorkerRemoteInstanceService]: cannot create replica for document type: ${type}.`
);
}
} catch (err: unknown) {
diff --git a/packages/rpc/src/services/rpc/channel.service.ts b/packages/rpc/src/services/rpc/channel.service.ts
index 206cd968bd..adac4d8eae 100644
--- a/packages/rpc/src/services/rpc/channel.service.ts
+++ b/packages/rpc/src/services/rpc/channel.service.ts
@@ -19,12 +19,12 @@ import { createIdentifier } from '@wendellhu/redi';
import type { IChannel, IMessageProtocol } from './rpc.service';
import { ChannelClient, ChannelServer } from './rpc.service';
-export interface IRPChannelService {
+export interface IRPCChannelService {
requestChannel(name: string): IChannel;
registerChannel(name: string, channel: IChannel): void;
}
-export const IRPChannelService = createIdentifier<IRPChannelService>('IRPChannelService');
+export const IRPCChannelService = createIdentifier<IRPCChannelService>('IRPCChannelService');
/**
* This service is responsible for managing the RPC channels.