@univerjs/rpc 0.20.1 → 0.21.0-insiders.20260422-d7fcb4d

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/lib/cjs/index.js CHANGED
@@ -1 +1,776 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`rxjs/operators`),n=require(`rxjs`);const r=`rpc.main-thread.config`;Symbol(r);const i={},a=`rpc.worker-thread.config`;Symbol(a);const o={};function s(e,t){return function(n,r){t(n,r,e)}}function c(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const l=`rpc.remote-sync.service`,u=(0,e.createIdentifier)(l);let d=class{constructor(e){this._commandService=e}async syncMutation(e,t){let{fromCollab:n,...r}=t||{};return this._commandService.syncExecuteCommand(e.mutationInfo.id,e.mutationInfo.params,{...r,onlyLocal:!0,fromSync:!0})}};d=c([s(0,e.ICommandService)],d);const f=`univer.remote-instance-service`,p=(0,e.createIdentifier)(f);let m=class{constructor(e,t,n){this._univerInstanceService=e,this._commandService=t,this._logService=n}whenReady(){return Promise.resolve(!0)}async syncMutation(e,t){return this._applyMutation(e.mutationInfo,t)}async createInstance(t){this._logService.debug(`[WebWorkerRemoteInstanceService]: Creating instance with id ${t.unitID}`);let{type:n,snapshot:r}=t;try{switch(n){case e.UniverInstanceType.UNIVER_SHEET:return this._univerInstanceService.createUnit(e.UniverInstanceType.UNIVER_SHEET,r),!0;default:throw Error(`[WebWorkerRemoteInstanceService]: cannot create replica for document type: ${n}.`)}}catch(e){throw e instanceof Error?e:TypeError(`${e}`)}}async disposeInstance(e){return this._logService.debug(`[WebWorkerRemoteInstanceService]: Disposing instance with id ${e.unitID}`),this._univerInstanceService.disposeUnit(e.unitID)}_applyMutation(e,t){let{id:n,params:r}=e,{fromCollab:i,...a}=t||{};return this._commandService.syncExecuteCommand(n,r,{...a,onlyLocal:!0,fromSync:!0})}};m=c([s(0,e.IUniverInstanceService),s(1,e.ICommandService),s(2,e.ILogService)],m);function h(e){"@babel/helpers - typeof";return h=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},h(e)}function g(e,t){if(h(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(h(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function _(e){var t=g(e,`string`);return h(t)==`symbol`?t:t+``}function v(e,t,n){return(t=_(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e){let t=e;return new class{call(e,n){let r=t[e];if(typeof r==`function`){let e=n?r.apply(t,n):r.call(t);return e instanceof Promise||(e=Promise.resolve(e)),e}throw Error(`[RPC]: method not found for ${e}!`)}subscribe(e,r){let i=t[e];if(typeof i==`function`){let e=r?i.apply(t,r):i.call(t);return(0,n.isObservable)(e)?e:(0,n.of)(e)}throw Error(`[RPC]: observable method not found for ${e}!`)}}}function b(e){return new Proxy({},{get(t,n){if(n!==`dispose`)return function(...t){return x(n)?e.subscribe(n,t):e.call(n,t)}}})}function x(e){return e.endsWith(`$`)}var S=function(e){return e[e.REQUEST_INITIALIZATION=50]=`REQUEST_INITIALIZATION`,e[e.CALL=100]=`CALL`,e[e.SUBSCRIBE=101]=`SUBSCRIBE`,e[e.UNSUBSCRIBE=102]=`UNSUBSCRIBE`,e}(S||{}),C=function(e){return e[e.INITIALIZE=0]=`INITIALIZE`,e[e.CALL_SUCCESS=201]=`CALL_SUCCESS`,e[e.CALL_FAILURE=202]=`CALL_FAILURE`,e[e.SUBSCRIBE_NEXT=300]=`SUBSCRIBE_NEXT`,e[e.SUBSCRIBE_ERROR=301]=`SUBSCRIBE_ERROR`,e[e.SUBSCRIBE_COMPLETE=302]=`SUBSCRIBE_COMPLETE`,e}(C||{}),w=class extends e.RxDisposable{constructor(e){super(),this._protocol=e,v(this,`_initialized`,new n.BehaviorSubject(!1)),v(this,`_lastRequestCounter`,0),v(this,`_pendingRequests`,new Map),this._protocol.send({type:S.REQUEST_INITIALIZATION}),this._protocol.onMessage.pipe((0,t.takeUntil)(this.dispose$)).subscribe(e=>this._onMessage(e))}dispose(){this._pendingRequests.clear()}getChannel(e){return{call:(t,n)=>this._disposed?Promise.reject(Error(`[ChannelClient]: client is disposed!`)):this._remoteCall(e,t,n),subscribe:(t,n)=>{if(this._disposed)throw Error(`[ChannelClient]: client is disposed!`);return this._remoteSubscribe(e,t,n)}}}_whenReady(){return(0,n.firstValueFrom)(this._initialized.pipe((0,t.filter)(e=>e),(0,t.take)(1)))}_remoteCall(e,t,n){return this._initialized.getValue()?this._doRemoteCall(e,t,n):this._whenReady().then(()=>this._doRemoteCall(e,t,n))}_doRemoteCall(e,t,n){let r=++this._lastRequestCounter,i={seq:r,type:S.CALL,channelName:e,method:t,args:n},a=this._pendingRequests;return new Promise((e,t)=>{this._pendingRequests.set(r,{handle(n){switch(n.type){case C.CALL_SUCCESS:a.delete(r),e(n.data);break;case C.CALL_FAILURE:a.delete(r),t(n.data);break;default:throw Error(`[ChannelClient]: unknown response type!`)}}}),this._sendRequest(i)})}_remoteSubscribe(e,t,r){return new n.Observable(n=>{let i=-1,a=()=>{i=++this._lastRequestCounter;let a=S.SUBSCRIBE,o={seq:i,type:a,channelName:e,method:t,args:r};this._pendingRequests.set(i,{handle(e){switch(e.type){case C.SUBSCRIBE_NEXT:n.next(e.data);break;case C.SUBSCRIBE_ERROR:n.error(e.data);break;case C.SUBSCRIBE_COMPLETE:n.complete();break;default:throw Error(`[ChannelClient]: unknown response type!`)}}}),this._sendRequest(o)};return this._initialized.getValue()?a():this._whenReady().then(a),()=>{if(i===-1)return;let n={type:S.UNSUBSCRIBE,seq:i,channelName:e,method:t};this._sendRequest(n)}})}_sendRequest(e){this._protocol.send(e)}_onMessage(e){let{type:t,seq:n}=e;switch(t){case C.INITIALIZE:this._initialized.next(!0);break;case C.CALL_SUCCESS:case C.CALL_FAILURE:case C.SUBSCRIBE_NEXT:case C.SUBSCRIBE_COMPLETE:case C.SUBSCRIBE_ERROR:{var r;let{_pendingRequests:i}=this;(r=i.get(n))==null||r.handle(e),t!==C.SUBSCRIBE_NEXT&&i.delete(n);break}}}},T=class extends e.RxDisposable{constructor(e){super(),this._protocol=e,v(this,`_channels`,new Map),v(this,`_subscriptions`,new Map),this._protocol.onMessage.pipe((0,t.takeUntil)(this.dispose$)).subscribe(e=>this._onRequest(e)),this._sendInitialize()}dispose(){super.dispose(),this._subscriptions.clear(),this._channels.clear()}registerChannel(e,t){this._channels.set(e,t)}_onRequest(e){switch(e.type){case S.REQUEST_INITIALIZATION:this._sendInitialize();break;case S.CALL:this._onMethodCall(e);break;case S.SUBSCRIBE:this._onSubscribe(e);break;case S.UNSUBSCRIBE:this._onUnsubscribe(e);break;default:break}}_sendInitialize(){this._sendResponse({seq:-1,type:C.INITIALIZE})}_onMethodCall(e){let{channelName:t,method:n,args:r}=e,i=this._channels.get(t),a;try{if(!i)throw Error(`[ChannelServer]: Channel ${t} not found!`);a=r?i.call(n,r):i.call(n)}catch(e){a=Promise.reject(e instanceof Error?e:Error(String(e)))}a.then(t=>{this._sendResponse({seq:e.seq,type:C.CALL_SUCCESS,data:t})}).catch(t=>{t instanceof Error?this._sendResponse({seq:e.seq,type:C.CALL_FAILURE,data:t.message}):this._sendResponse({seq:e.seq,type:C.CALL_FAILURE,data:String(t)})})}_onSubscribe(e){let{channelName:t,seq:n}=e,r=this._channels.get(t);try{if(!r)throw Error(`[ChannelServer]: Channel ${t} not found!`);let i=r.subscribe(e.method,e.args).subscribe({next:e=>{this._sendResponse({seq:n,type:C.SUBSCRIBE_NEXT,data:e})},error:e=>{this._sendResponse({seq:n,type:C.SUBSCRIBE_ERROR,data:e.message}),this._sendResponse({seq:n,type:C.SUBSCRIBE_COMPLETE})},complete:()=>{this._sendResponse({seq:n,type:C.SUBSCRIBE_COMPLETE})}});this._subscriptions.set(e.seq,i)}catch(t){t instanceof Error?this._sendResponse({seq:e.seq,type:C.SUBSCRIBE_ERROR,data:t.message}):this._sendResponse({seq:e.seq,type:C.SUBSCRIBE_ERROR,data:String(t)})}}_onUnsubscribe(e){let t=this._subscriptions.get(e.seq);t&&(t.unsubscribe(),this._subscriptions.delete(e.seq))}_sendResponse(e){this._protocol.send(e)}};const E=(0,e.createIdentifier)(`IRPCChannelService`);var D=class{constructor(e){v(this,`_client`,void 0),v(this,`_server`,void 0),this._client=new w(e),this._server=new T(e)}dispose(){this._client.dispose(),this._server.dispose()}requestChannel(e){return this._client.getChannel(e)}registerChannel(e,t){this._server.registerChannel(e,t)}};let O=class extends e.RxDisposable{constructor(e,t,n,r,i){super(),this._injector=e,this._commandService=t,this._univerInstanceService=n,this._rpcChannelService=r,this._remoteSyncService=i,v(this,`_remoteInstanceService`,void 0),v(this,`_syncingUnits`,new Set),v(this,`_syncingMutations`,new Set),this._initRPCChannels(),this._init()}registerSyncingMutations(e){this._syncingMutations.add(e.id)}syncUnit(t){return this._syncingUnits.add(t),(0,e.toDisposable)(()=>this._syncingUnits.delete(t))}_initRPCChannels(){this._rpcChannelService.registerChannel(l,y(this._remoteSyncService)),this._injector.add([p,{useFactory:()=>b(this._rpcChannelService.requestChannel(f))}]),this._remoteInstanceService=this._injector.get(p)}_init(){this._univerInstanceService.getTypeOfUnitAdded$(e.UniverInstanceType.UNIVER_SHEET).pipe((0,t.takeUntil)(this.dispose$)).subscribe(t=>{this._syncingUnits.add(t.getUnitId()),this._remoteInstanceService.createInstance({unitID:t.getUnitId(),type:e.UniverInstanceType.UNIVER_SHEET,snapshot:t.getSnapshot()})}),this._univerInstanceService.getTypeOfUnitDisposed$(e.UniverInstanceType.UNIVER_SHEET).pipe((0,t.takeUntil)(this.dispose$)).subscribe(e=>{this._syncingUnits.delete(e.getUnitId()),this._remoteInstanceService.disposeInstance({unitID:e.getUnitId()})}),this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{let{type:r,params:i,id:a}=t,o=(i==null?void 0:i.unitId)||``;r===e.CommandType.MUTATION&&(!o||this._syncingUnits.has(o))&&!(n!=null&&n.fromSync)&&this._syncingMutations.has(a)&&this._remoteInstanceService.syncMutation({mutationInfo:t},n)}))}};O=c([s(0,(0,e.Inject)(e.Injector)),s(1,e.ICommandService),s(2,e.IUniverInstanceService),s(3,E),s(4,u)],O);let k=class extends e.Disposable{constructor(e,t,n,r){super(),this._injector=e,this._remoteInstanceService=t,this._commandService=n,this._rpcChannelService=r,v(this,`_remoteSyncService`,void 0),this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(f,y(this._remoteInstanceService)),this._injector.add([u,{useFactory:()=>b(this._rpcChannelService.requestChannel(l))}]),this._remoteSyncService=this._injector.get(u)}_init(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{t.type===e.CommandType.MUTATION&&!(n!=null&&n.fromSync)&&this._remoteSyncService.syncMutation({mutationInfo:t},n)}))}};k=c([s(0,(0,e.Inject)(e.Injector)),s(1,p),s(2,e.ICommandService),s(3,E)],k);var A=`@univerjs/rpc`,j=`0.20.1`;function M(){return{send(e){postMessage(e)},onMessage:new n.Observable(e=>{let t=t=>{e.next(t.data)};return addEventListener(`message`,t),()=>removeEventListener(`message`,t)}).pipe((0,n.shareReplay)(1))}}function N(e){return{send(t){e.postMessage(t)},onMessage:new n.Observable(t=>{let n=e=>{t.next(e.data)};return e.addEventListener(`message`,n),()=>e.removeEventListener(`message`,n)}).pipe((0,n.shareReplay)(1))}}let P=class extends e.Plugin{constructor(t=i,n,a){super(),this._config=t,this._injector=n,this._configService=a,v(this,`_internalWorker`,null);let{...o}=(0,e.merge)({},i,this._config);this._configService.setConfig(r,o)}dispose(){super.dispose(),this._internalWorker&&(this._internalWorker.terminate(),this._internalWorker=null)}onStarting(){let{workerURL:e}=this._config;if(!e)throw Error(`[UniverRPCMainThreadPlugin]: The workerURL is required for the RPC main thread plugin.`);let t=e instanceof Worker?e:new Worker(e);this._internalWorker=e instanceof Worker?null:t;let n=N(t);[[E,{useFactory:()=>new D(n)}],[O],[u,{useClass:d}]].forEach(e=>this._injector.add(e)),this._injector.get(O)}};v(P,`pluginName`,`UNIVER_RPC_MAIN_THREAD_PLUGIN`),v(P,`packageName`,A),v(P,`version`,j),P=c([s(1,(0,e.Inject)(e.Injector)),s(2,e.IConfigService)],P);let F=class extends e.Plugin{constructor(t=o,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{...i}=(0,e.merge)({},o,this._config);this._configService.setConfig(a,i)}onStarting(){[[k],[E,{useFactory:()=>new D(M())}],[p,{useClass:m}]].forEach(e=>this._injector.add(e)),this._injector.get(k)}};v(F,`pluginName`,`UNIVER_RPC_WORKER_THREAD_PLUGIN`),v(F,`packageName`,A),v(F,`version`,j),F=c([s(1,(0,e.Inject)(e.Injector)),s(2,e.IConfigService)],F),exports.ChannelClient=w,exports.ChannelServer=T,exports.ChannelService=D,Object.defineProperty(exports,`DataSyncPrimaryController`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`DataSyncReplicaController`,{enumerable:!0,get:function(){return k}}),exports.IRPCChannelService=E,exports.IRemoteInstanceService=p,exports.IRemoteSyncService=u,exports.PLUGIN_CONFIG_KEY_MAIN_THREAD=r,exports.PLUGIN_CONFIG_KEY_WORKER_THREAD=a,exports.RemoteInstanceServiceName=f,Object.defineProperty(exports,`RemoteSyncPrimaryService`,{enumerable:!0,get:function(){return d}}),exports.RemoteSyncServiceName=l,Object.defineProperty(exports,`UniverRPCMainThreadPlugin`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`UniverRPCWorkerThreadPlugin`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`WebWorkerRemoteInstanceService`,{enumerable:!0,get:function(){return m}}),exports.fromModule=y,exports.toModule=b;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let rxjs_operators = require("rxjs/operators");
4
+ let rxjs = require("rxjs");
5
+
6
+ //#region src/config/config.ts
7
+ /**
8
+ * Copyright 2023-present DreamNum Co., Ltd.
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const PLUGIN_CONFIG_KEY_MAIN_THREAD = "rpc.main-thread.config";
23
+ const configSymbolMainThread = Symbol(PLUGIN_CONFIG_KEY_MAIN_THREAD);
24
+ const defaultPluginMainThreadConfig = {};
25
+ const PLUGIN_CONFIG_KEY_WORKER_THREAD = "rpc.worker-thread.config";
26
+ const configSymbolWorkerThread = Symbol(PLUGIN_CONFIG_KEY_WORKER_THREAD);
27
+ const defaultPluginWorkerThreadConfig = {};
28
+
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
31
+ function __decorateParam(paramIndex, decorator) {
32
+ return function(target, key) {
33
+ decorator(target, key, paramIndex);
34
+ };
35
+ }
36
+
37
+ //#endregion
38
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
39
+ function __decorate(decorators, target, key, desc) {
40
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
41
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
42
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
43
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
44
+ }
45
+
46
+ //#endregion
47
+ //#region src/services/remote-instance/remote-instance.service.ts
48
+ const RemoteSyncServiceName = "rpc.remote-sync.service";
49
+ /**
50
+ * This service is provided by the primary Univer.
51
+ *
52
+ * Replica Univer could call this service to update mutations back to the primary Univer.
53
+ */
54
+ const IRemoteSyncService = (0, _univerjs_core.createIdentifier)(RemoteSyncServiceName);
55
+ let RemoteSyncPrimaryService = class RemoteSyncPrimaryService {
56
+ constructor(_commandService) {
57
+ this._commandService = _commandService;
58
+ }
59
+ async syncMutation(params, options) {
60
+ const { fromCollab, ...restOptions } = options || {};
61
+ return this._commandService.syncExecuteCommand(params.mutationInfo.id, params.mutationInfo.params, {
62
+ ...restOptions,
63
+ onlyLocal: true,
64
+ fromSync: true
65
+ });
66
+ }
67
+ };
68
+ RemoteSyncPrimaryService = __decorate([__decorateParam(0, _univerjs_core.ICommandService)], RemoteSyncPrimaryService);
69
+ const RemoteInstanceServiceName = "univer.remote-instance-service";
70
+ /**
71
+ * This service is provided by the replica Univer.
72
+ *
73
+ * Primary univer could call this service to init and dispose univer business instances
74
+ * and sync mutations to replica univer.
75
+ */
76
+ const IRemoteInstanceService = (0, _univerjs_core.createIdentifier)(RemoteInstanceServiceName);
77
+ let WebWorkerRemoteInstanceService = class WebWorkerRemoteInstanceService {
78
+ constructor(_univerInstanceService, _commandService, _logService) {
79
+ this._univerInstanceService = _univerInstanceService;
80
+ this._commandService = _commandService;
81
+ this._logService = _logService;
82
+ }
83
+ whenReady() {
84
+ return Promise.resolve(true);
85
+ }
86
+ async syncMutation(params, options) {
87
+ return this._applyMutation(params.mutationInfo, options);
88
+ }
89
+ async createInstance(params) {
90
+ this._logService.debug(`[WebWorkerRemoteInstanceService]: Creating instance with id ${params.unitID}`);
91
+ const { type, snapshot } = params;
92
+ try {
93
+ switch (type) {
94
+ case _univerjs_core.UniverInstanceType.UNIVER_SHEET:
95
+ this._univerInstanceService.createUnit(_univerjs_core.UniverInstanceType.UNIVER_SHEET, snapshot);
96
+ return true;
97
+ default: throw new Error(`[WebWorkerRemoteInstanceService]: cannot create replica for document type: ${type}.`);
98
+ }
99
+ } catch (err) {
100
+ if (err instanceof Error) throw err;
101
+ else throw new TypeError(`${err}`);
102
+ }
103
+ }
104
+ async disposeInstance(params) {
105
+ this._logService.debug(`[WebWorkerRemoteInstanceService]: Disposing instance with id ${params.unitID}`);
106
+ return this._univerInstanceService.disposeUnit(params.unitID);
107
+ }
108
+ _applyMutation(mutationInfo, options) {
109
+ const { id, params: mutationParams } = mutationInfo;
110
+ const { fromCollab, ...restOptions } = options || {};
111
+ return this._commandService.syncExecuteCommand(id, mutationParams, {
112
+ ...restOptions,
113
+ onlyLocal: true,
114
+ fromSync: true
115
+ });
116
+ }
117
+ };
118
+ WebWorkerRemoteInstanceService = __decorate([
119
+ __decorateParam(0, _univerjs_core.IUniverInstanceService),
120
+ __decorateParam(1, _univerjs_core.ICommandService),
121
+ __decorateParam(2, _univerjs_core.ILogService)
122
+ ], WebWorkerRemoteInstanceService);
123
+
124
+ //#endregion
125
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
126
+ function _typeof(o) {
127
+ "@babel/helpers - typeof";
128
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
129
+ return typeof o;
130
+ } : function(o) {
131
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
132
+ }, _typeof(o);
133
+ }
134
+
135
+ //#endregion
136
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
137
+ function toPrimitive(t, r) {
138
+ if ("object" != _typeof(t) || !t) return t;
139
+ var e = t[Symbol.toPrimitive];
140
+ if (void 0 !== e) {
141
+ var i = e.call(t, r || "default");
142
+ if ("object" != _typeof(i)) return i;
143
+ throw new TypeError("@@toPrimitive must return a primitive value.");
144
+ }
145
+ return ("string" === r ? String : Number)(t);
146
+ }
147
+
148
+ //#endregion
149
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
150
+ function toPropertyKey(t) {
151
+ var i = toPrimitive(t, "string");
152
+ return "symbol" == _typeof(i) ? i : i + "";
153
+ }
154
+
155
+ //#endregion
156
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
157
+ function _defineProperty(e, r, t) {
158
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
159
+ value: t,
160
+ enumerable: !0,
161
+ configurable: !0,
162
+ writable: !0
163
+ }) : e[r] = t, e;
164
+ }
165
+
166
+ //#endregion
167
+ //#region src/services/rpc/rpc.service.ts
168
+ /**
169
+ * Wrapper a service or a controller into a channel so it could be invoked by
170
+ * a remote client. When the protocol is called, it would forward to the
171
+ * underlying service or controller.
172
+ *
173
+ * @param module the wrapper service or controller
174
+ * @returns the channel instance
175
+ */
176
+ function fromModule(module) {
177
+ const handler = module;
178
+ return new class {
179
+ call(method, args) {
180
+ const target = handler[method];
181
+ if (typeof target === "function") {
182
+ let res = args ? target.apply(handler, args) : target.call(handler);
183
+ if (!(res instanceof Promise)) res = Promise.resolve(res);
184
+ return res;
185
+ }
186
+ throw new Error(`[RPC]: method not found for ${method}!`);
187
+ }
188
+ subscribe(eventMethod, args) {
189
+ const target = handler[eventMethod];
190
+ if (typeof target === "function") {
191
+ const res = args ? target.apply(handler, args) : target.call(handler);
192
+ if (!(0, rxjs.isObservable)(res)) return (0, rxjs.of)(res);
193
+ return res;
194
+ }
195
+ throw new Error(`[RPC]: observable method not found for ${eventMethod}!`);
196
+ }
197
+ }();
198
+ }
199
+ /**
200
+ * Wrap a channel into a service or a controller so it could be invoked by
201
+ * the upper layer modules. When the service or controller is called, it would
202
+ * request the remote server by calling the channel.
203
+ *
204
+ * @param channel
205
+ * @returns A proxy object that forwards calls/subscriptions to the remote channel.
206
+ */
207
+ function toModule(channel) {
208
+ return new Proxy({}, { get(_, propKey) {
209
+ if (propKey === "dispose") return;
210
+ return function(...args) {
211
+ if (propertyIsEventSource(propKey)) return channel.subscribe(propKey, args);
212
+ return channel.call(propKey, args);
213
+ };
214
+ } });
215
+ }
216
+ function propertyIsEventSource(name) {
217
+ return name.endsWith("$");
218
+ }
219
+ var RequestType = /* @__PURE__ */ function(RequestType) {
220
+ /**
221
+ * In Univer, we cannot make sure that when IPCServer constructs, the process (or thread)
222
+ * where the corresponding IPCClient residents has bootstrapped and been ready to recieve messages.
223
+ * This may result in the IPCClient hanging there, waiting for the `INITIALIZE` message that it has
224
+ * already missed. So the client should send a REQUEST_INITIALIZATION in case of that.
225
+ *
226
+ * Later, we may want a more sophisticated RPC system where the server can serve more than
227
+ * one clients, and this event may be removed.
228
+ */
229
+ RequestType[RequestType["REQUEST_INITIALIZATION"] = 50] = "REQUEST_INITIALIZATION";
230
+ /** A simple remote calling wrapper in a Promise. */
231
+ RequestType[RequestType["CALL"] = 100] = "CALL";
232
+ /** Subscribe to a remote Observable. */
233
+ RequestType[RequestType["SUBSCRIBE"] = 101] = "SUBSCRIBE";
234
+ /** Cancel subscription to that remove Observable. */
235
+ RequestType[RequestType["UNSUBSCRIBE"] = 102] = "UNSUBSCRIBE";
236
+ return RequestType;
237
+ }(RequestType || {});
238
+ var ResponseType = /* @__PURE__ */ function(ResponseType) {
239
+ /**
240
+ * When underlying protocol is established. The server should send the
241
+ * client an `INITIALIZE` response to indicate that the server is up
242
+ * and ready to provide services.
243
+ */
244
+ ResponseType[ResponseType["INITIALIZE"] = 0] = "INITIALIZE";
245
+ ResponseType[ResponseType["CALL_SUCCESS"] = 201] = "CALL_SUCCESS";
246
+ ResponseType[ResponseType["CALL_FAILURE"] = 202] = "CALL_FAILURE";
247
+ ResponseType[ResponseType["SUBSCRIBE_NEXT"] = 300] = "SUBSCRIBE_NEXT";
248
+ ResponseType[ResponseType["SUBSCRIBE_ERROR"] = 301] = "SUBSCRIBE_ERROR";
249
+ ResponseType[ResponseType["SUBSCRIBE_COMPLETE"] = 302] = "SUBSCRIBE_COMPLETE";
250
+ return ResponseType;
251
+ }(ResponseType || {});
252
+ /**
253
+ * This method provides implementation for `IChannel` and is responsible for
254
+ * transforming a local calling to a RPC calling.
255
+ */
256
+ var ChannelClient = class extends _univerjs_core.RxDisposable {
257
+ constructor(_protocol) {
258
+ super();
259
+ this._protocol = _protocol;
260
+ _defineProperty(this, "_initialized", new rxjs.BehaviorSubject(false));
261
+ _defineProperty(this, "_lastRequestCounter", 0);
262
+ _defineProperty(this, "_pendingRequests", /* @__PURE__ */ new Map());
263
+ this._protocol.send({ type: RequestType.REQUEST_INITIALIZATION });
264
+ this._protocol.onMessage.pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe((message) => this._onMessage(message));
265
+ }
266
+ dispose() {
267
+ this._pendingRequests.clear();
268
+ }
269
+ getChannel(channelName) {
270
+ return {
271
+ call: (method, args) => {
272
+ if (this._disposed) return Promise.reject(/* @__PURE__ */ new Error("[ChannelClient]: client is disposed!"));
273
+ return this._remoteCall(channelName, method, args);
274
+ },
275
+ subscribe: (eventMethod, args) => {
276
+ if (this._disposed) throw new Error("[ChannelClient]: client is disposed!");
277
+ return this._remoteSubscribe(channelName, eventMethod, args);
278
+ }
279
+ };
280
+ }
281
+ _whenReady() {
282
+ return (0, rxjs.firstValueFrom)(this._initialized.pipe((0, rxjs_operators.filter)((v) => v), (0, rxjs_operators.take)(1)));
283
+ }
284
+ _remoteCall(channelName, method, args) {
285
+ if (this._initialized.getValue()) return this._doRemoteCall(channelName, method, args);
286
+ return this._whenReady().then(() => this._doRemoteCall(channelName, method, args));
287
+ }
288
+ _doRemoteCall(channelName, method, args) {
289
+ const sequence = ++this._lastRequestCounter;
290
+ const request = {
291
+ seq: sequence,
292
+ type: RequestType.CALL,
293
+ channelName,
294
+ method,
295
+ args
296
+ };
297
+ const pendingRequests = this._pendingRequests;
298
+ return new Promise((resolve, reject) => {
299
+ this._pendingRequests.set(sequence, { handle(response) {
300
+ switch (response.type) {
301
+ case ResponseType.CALL_SUCCESS:
302
+ pendingRequests.delete(sequence);
303
+ resolve(response.data);
304
+ break;
305
+ case ResponseType.CALL_FAILURE:
306
+ pendingRequests.delete(sequence);
307
+ reject(response.data);
308
+ break;
309
+ default: throw new Error("[ChannelClient]: unknown response type!");
310
+ }
311
+ } });
312
+ this._sendRequest(request);
313
+ });
314
+ }
315
+ _remoteSubscribe(channelName, method, args) {
316
+ return new rxjs.Observable((subscriber) => {
317
+ let sequence = -1;
318
+ const doSubscribe = () => {
319
+ sequence = ++this._lastRequestCounter;
320
+ const type = RequestType.SUBSCRIBE;
321
+ const request = {
322
+ seq: sequence,
323
+ type,
324
+ channelName,
325
+ method,
326
+ args
327
+ };
328
+ this._pendingRequests.set(sequence, { handle(response) {
329
+ switch (response.type) {
330
+ case ResponseType.SUBSCRIBE_NEXT:
331
+ subscriber.next(response.data);
332
+ break;
333
+ case ResponseType.SUBSCRIBE_ERROR:
334
+ subscriber.error(response.data);
335
+ break;
336
+ case ResponseType.SUBSCRIBE_COMPLETE:
337
+ subscriber.complete();
338
+ break;
339
+ default: throw new Error("[ChannelClient]: unknown response type!");
340
+ }
341
+ } });
342
+ this._sendRequest(request);
343
+ };
344
+ if (this._initialized.getValue()) doSubscribe();
345
+ else this._whenReady().then(doSubscribe);
346
+ return () => {
347
+ if (sequence === -1) return;
348
+ const cancelSubscriptionRequest = {
349
+ type: RequestType.UNSUBSCRIBE,
350
+ seq: sequence,
351
+ channelName,
352
+ method
353
+ };
354
+ this._sendRequest(cancelSubscriptionRequest);
355
+ };
356
+ });
357
+ }
358
+ _sendRequest(request) {
359
+ this._protocol.send(request);
360
+ }
361
+ _onMessage(response) {
362
+ const { type: responseType, seq } = response;
363
+ switch (responseType) {
364
+ case ResponseType.INITIALIZE:
365
+ this._initialized.next(true);
366
+ break;
367
+ case ResponseType.CALL_SUCCESS:
368
+ case ResponseType.CALL_FAILURE:
369
+ case ResponseType.SUBSCRIBE_NEXT:
370
+ case ResponseType.SUBSCRIBE_COMPLETE:
371
+ case ResponseType.SUBSCRIBE_ERROR: {
372
+ var _pendingRequests$get;
373
+ const { _pendingRequests } = this;
374
+ (_pendingRequests$get = _pendingRequests.get(seq)) === null || _pendingRequests$get === void 0 || _pendingRequests$get.handle(response);
375
+ responseType !== ResponseType.SUBSCRIBE_NEXT && _pendingRequests.delete(seq);
376
+ break;
377
+ }
378
+ }
379
+ }
380
+ };
381
+ var ChannelServer = class extends _univerjs_core.RxDisposable {
382
+ constructor(_protocol) {
383
+ super();
384
+ this._protocol = _protocol;
385
+ _defineProperty(this, "_channels", /* @__PURE__ */ new Map());
386
+ _defineProperty(this, "_subscriptions", /* @__PURE__ */ new Map());
387
+ this._protocol.onMessage.pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe((message) => this._onRequest(message));
388
+ this._sendInitialize();
389
+ }
390
+ dispose() {
391
+ super.dispose();
392
+ this._subscriptions.clear();
393
+ this._channels.clear();
394
+ }
395
+ registerChannel(channelName, channel) {
396
+ this._channels.set(channelName, channel);
397
+ }
398
+ _onRequest(request) {
399
+ switch (request.type) {
400
+ case RequestType.REQUEST_INITIALIZATION:
401
+ this._sendInitialize();
402
+ break;
403
+ case RequestType.CALL:
404
+ this._onMethodCall(request);
405
+ break;
406
+ case RequestType.SUBSCRIBE:
407
+ this._onSubscribe(request);
408
+ break;
409
+ case RequestType.UNSUBSCRIBE:
410
+ this._onUnsubscribe(request);
411
+ break;
412
+ default: break;
413
+ }
414
+ }
415
+ _sendInitialize() {
416
+ this._sendResponse({
417
+ seq: -1,
418
+ type: ResponseType.INITIALIZE
419
+ });
420
+ }
421
+ _onMethodCall(request) {
422
+ const { channelName, method, args } = request;
423
+ const channel = this._channels.get(channelName);
424
+ let promise;
425
+ try {
426
+ if (!channel) throw new Error(`[ChannelServer]: Channel ${channelName} not found!`);
427
+ promise = args ? channel.call(method, args) : channel.call(method);
428
+ } catch (err) {
429
+ promise = Promise.reject(err instanceof Error ? err : new Error(String(err)));
430
+ }
431
+ promise.then((data) => {
432
+ this._sendResponse({
433
+ seq: request.seq,
434
+ type: ResponseType.CALL_SUCCESS,
435
+ data
436
+ });
437
+ }).catch((err) => {
438
+ if (err instanceof Error) this._sendResponse({
439
+ seq: request.seq,
440
+ type: ResponseType.CALL_FAILURE,
441
+ data: err.message
442
+ });
443
+ else this._sendResponse({
444
+ seq: request.seq,
445
+ type: ResponseType.CALL_FAILURE,
446
+ data: String(err)
447
+ });
448
+ });
449
+ }
450
+ _onSubscribe(request) {
451
+ const { channelName, seq } = request;
452
+ const channel = this._channels.get(channelName);
453
+ try {
454
+ if (!channel) throw new Error(`[ChannelServer]: Channel ${channelName} not found!`);
455
+ const subscription = channel.subscribe(request.method, request.args).subscribe({
456
+ next: (data) => {
457
+ this._sendResponse({
458
+ seq,
459
+ type: ResponseType.SUBSCRIBE_NEXT,
460
+ data
461
+ });
462
+ },
463
+ error: (err) => {
464
+ this._sendResponse({
465
+ seq,
466
+ type: ResponseType.SUBSCRIBE_ERROR,
467
+ data: err.message
468
+ });
469
+ this._sendResponse({
470
+ seq,
471
+ type: ResponseType.SUBSCRIBE_COMPLETE
472
+ });
473
+ },
474
+ complete: () => {
475
+ this._sendResponse({
476
+ seq,
477
+ type: ResponseType.SUBSCRIBE_COMPLETE
478
+ });
479
+ }
480
+ });
481
+ this._subscriptions.set(request.seq, subscription);
482
+ } catch (err) {
483
+ if (err instanceof Error) this._sendResponse({
484
+ seq: request.seq,
485
+ type: ResponseType.SUBSCRIBE_ERROR,
486
+ data: err.message
487
+ });
488
+ else this._sendResponse({
489
+ seq: request.seq,
490
+ type: ResponseType.SUBSCRIBE_ERROR,
491
+ data: String(err)
492
+ });
493
+ }
494
+ }
495
+ _onUnsubscribe(request) {
496
+ const subscription = this._subscriptions.get(request.seq);
497
+ if (subscription) {
498
+ subscription.unsubscribe();
499
+ this._subscriptions.delete(request.seq);
500
+ }
501
+ }
502
+ _sendResponse(response) {
503
+ this._protocol.send(response);
504
+ }
505
+ };
506
+
507
+ //#endregion
508
+ //#region src/services/rpc/channel.service.ts
509
+ const IRPCChannelService = (0, _univerjs_core.createIdentifier)("IRPCChannelService");
510
+ /**
511
+ * This service is responsible for managing the RPC channels.
512
+ */
513
+ var ChannelService = class {
514
+ constructor(_messageProtocol) {
515
+ _defineProperty(this, "_client", void 0);
516
+ _defineProperty(this, "_server", void 0);
517
+ this._client = new ChannelClient(_messageProtocol);
518
+ this._server = new ChannelServer(_messageProtocol);
519
+ }
520
+ dispose() {
521
+ this._client.dispose();
522
+ this._server.dispose();
523
+ }
524
+ requestChannel(name) {
525
+ return this._client.getChannel(name);
526
+ }
527
+ registerChannel(name, channel) {
528
+ this._server.registerChannel(name, channel);
529
+ }
530
+ };
531
+
532
+ //#endregion
533
+ //#region src/controllers/data-sync/data-sync-primary.controller.ts
534
+ let DataSyncPrimaryController = class DataSyncPrimaryController extends _univerjs_core.RxDisposable {
535
+ constructor(_injector, _commandService, _univerInstanceService, _rpcChannelService, _remoteSyncService) {
536
+ super();
537
+ this._injector = _injector;
538
+ this._commandService = _commandService;
539
+ this._univerInstanceService = _univerInstanceService;
540
+ this._rpcChannelService = _rpcChannelService;
541
+ this._remoteSyncService = _remoteSyncService;
542
+ _defineProperty(this, "_remoteInstanceService", void 0);
543
+ _defineProperty(this, "_syncingUnits", /* @__PURE__ */ new Set());
544
+ _defineProperty(this, "_syncingMutations", /* @__PURE__ */ new Set());
545
+ this._initRPCChannels();
546
+ this._init();
547
+ }
548
+ registerSyncingMutations(mutation) {
549
+ this._syncingMutations.add(mutation.id);
550
+ }
551
+ /**
552
+ * Only spreadsheets would be synced to the web worker in normal situations. If you would like to
553
+ * sync other types of documents, you should manually call this method with that document's id.
554
+ */
555
+ syncUnit(unitId) {
556
+ this._syncingUnits.add(unitId);
557
+ return (0, _univerjs_core.toDisposable)(() => this._syncingUnits.delete(unitId));
558
+ }
559
+ _initRPCChannels() {
560
+ this._rpcChannelService.registerChannel(RemoteSyncServiceName, fromModule(this._remoteSyncService));
561
+ this._injector.add([IRemoteInstanceService, { useFactory: () => toModule(this._rpcChannelService.requestChannel(RemoteInstanceServiceName)) }]);
562
+ this._remoteInstanceService = this._injector.get(IRemoteInstanceService);
563
+ }
564
+ _init() {
565
+ this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe((sheet) => {
566
+ this._syncingUnits.add(sheet.getUnitId());
567
+ this._remoteInstanceService.createInstance({
568
+ unitID: sheet.getUnitId(),
569
+ type: _univerjs_core.UniverInstanceType.UNIVER_SHEET,
570
+ snapshot: sheet.getSnapshot()
571
+ });
572
+ });
573
+ this._univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe((workbook) => {
574
+ this._syncingUnits.delete(workbook.getUnitId());
575
+ this._remoteInstanceService.disposeInstance({ unitID: workbook.getUnitId() });
576
+ });
577
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo, options) => {
578
+ const { type, params, id } = commandInfo;
579
+ const unitId = (params === null || params === void 0 ? void 0 : params.unitId) || "";
580
+ if (type === _univerjs_core.CommandType.MUTATION && (!unitId || this._syncingUnits.has(unitId)) && !(options === null || options === void 0 ? void 0 : options.fromSync) && this._syncingMutations.has(id)) this._remoteInstanceService.syncMutation({ mutationInfo: commandInfo }, options);
581
+ }));
582
+ }
583
+ };
584
+ DataSyncPrimaryController = __decorate([
585
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
586
+ __decorateParam(1, _univerjs_core.ICommandService),
587
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
588
+ __decorateParam(3, IRPCChannelService),
589
+ __decorateParam(4, IRemoteSyncService)
590
+ ], DataSyncPrimaryController);
591
+
592
+ //#endregion
593
+ //#region src/controllers/data-sync/data-sync-replica.controller.ts
594
+ let DataSyncReplicaController = class DataSyncReplicaController extends _univerjs_core.Disposable {
595
+ constructor(_injector, _remoteInstanceService, _commandService, _rpcChannelService) {
596
+ super();
597
+ this._injector = _injector;
598
+ this._remoteInstanceService = _remoteInstanceService;
599
+ this._commandService = _commandService;
600
+ this._rpcChannelService = _rpcChannelService;
601
+ _defineProperty(this, "_remoteSyncService", void 0);
602
+ this._initRPCChannels();
603
+ this._init();
604
+ }
605
+ _initRPCChannels() {
606
+ this._rpcChannelService.registerChannel(RemoteInstanceServiceName, fromModule(this._remoteInstanceService));
607
+ this._injector.add([IRemoteSyncService, { useFactory: () => toModule(this._rpcChannelService.requestChannel(RemoteSyncServiceName)) }]);
608
+ this._remoteSyncService = this._injector.get(IRemoteSyncService);
609
+ }
610
+ _init() {
611
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo, options) => {
612
+ if (commandInfo.type === _univerjs_core.CommandType.MUTATION && !(options === null || options === void 0 ? void 0 : options.fromSync)) this._remoteSyncService.syncMutation({ mutationInfo: commandInfo }, options);
613
+ }));
614
+ }
615
+ };
616
+ DataSyncReplicaController = __decorate([
617
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
618
+ __decorateParam(1, IRemoteInstanceService),
619
+ __decorateParam(2, _univerjs_core.ICommandService),
620
+ __decorateParam(3, IRPCChannelService)
621
+ ], DataSyncReplicaController);
622
+
623
+ //#endregion
624
+ //#region package.json
625
+ var name = "@univerjs/rpc";
626
+ var version = "0.21.0-insiders.20260422-d7fcb4d";
627
+
628
+ //#endregion
629
+ //#region src/services/rpc/implementations/web-worker-rpc.service.ts
630
+ /**
631
+ * Generate an `IMessageProtocol` on the web worker.
632
+ * @returns A protocol wrapper around worker global messaging APIs.
633
+ */
634
+ function createWebWorkerMessagePortOnWorker() {
635
+ return {
636
+ send(message) {
637
+ postMessage(message);
638
+ },
639
+ onMessage: new rxjs.Observable((subscriber) => {
640
+ const handler = (event) => {
641
+ subscriber.next(event.data);
642
+ };
643
+ addEventListener("message", handler);
644
+ return () => removeEventListener("message", handler);
645
+ }).pipe((0, rxjs.shareReplay)(1))
646
+ };
647
+ }
648
+ /**
649
+ * Generate an `IMessageProtocol` on the main thread side.
650
+ * @param worker The Web Worker object
651
+ * @returns A protocol wrapper around the given worker messaging APIs.
652
+ */
653
+ function createWebWorkerMessagePortOnMain(worker) {
654
+ return {
655
+ send(message) {
656
+ worker.postMessage(message);
657
+ },
658
+ onMessage: new rxjs.Observable((subscriber) => {
659
+ const handler = (event) => {
660
+ subscriber.next(event.data);
661
+ };
662
+ worker.addEventListener("message", handler);
663
+ return () => worker.removeEventListener("message", handler);
664
+ }).pipe((0, rxjs.shareReplay)(1))
665
+ };
666
+ }
667
+
668
+ //#endregion
669
+ //#region src/plugin.ts
670
+ let UniverRPCMainThreadPlugin = class UniverRPCMainThreadPlugin extends _univerjs_core.Plugin {
671
+ constructor(_config = defaultPluginMainThreadConfig, _injector, _configService) {
672
+ super();
673
+ this._config = _config;
674
+ this._injector = _injector;
675
+ this._configService = _configService;
676
+ _defineProperty(this, "_internalWorker", null);
677
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginMainThreadConfig, this._config);
678
+ this._configService.setConfig(PLUGIN_CONFIG_KEY_MAIN_THREAD, rest);
679
+ }
680
+ dispose() {
681
+ super.dispose();
682
+ if (this._internalWorker) {
683
+ this._internalWorker.terminate();
684
+ this._internalWorker = null;
685
+ }
686
+ }
687
+ onStarting() {
688
+ const { workerURL } = this._config;
689
+ if (!workerURL) throw new Error("[UniverRPCMainThreadPlugin]: The workerURL is required for the RPC main thread plugin.");
690
+ const worker = workerURL instanceof Worker ? workerURL : new Worker(workerURL);
691
+ this._internalWorker = workerURL instanceof Worker ? null : worker;
692
+ const messageProtocol = createWebWorkerMessagePortOnMain(worker);
693
+ [
694
+ [IRPCChannelService, { useFactory: () => new ChannelService(messageProtocol) }],
695
+ [DataSyncPrimaryController],
696
+ [IRemoteSyncService, { useClass: RemoteSyncPrimaryService }]
697
+ ].forEach((dependency) => this._injector.add(dependency));
698
+ this._injector.get(DataSyncPrimaryController);
699
+ }
700
+ };
701
+ _defineProperty(UniverRPCMainThreadPlugin, "pluginName", "UNIVER_RPC_MAIN_THREAD_PLUGIN");
702
+ _defineProperty(UniverRPCMainThreadPlugin, "packageName", name);
703
+ _defineProperty(UniverRPCMainThreadPlugin, "version", version);
704
+ UniverRPCMainThreadPlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_core.IConfigService)], UniverRPCMainThreadPlugin);
705
+ let UniverRPCWorkerThreadPlugin = class UniverRPCWorkerThreadPlugin extends _univerjs_core.Plugin {
706
+ constructor(_config = defaultPluginWorkerThreadConfig, _injector, _configService) {
707
+ super();
708
+ this._config = _config;
709
+ this._injector = _injector;
710
+ this._configService = _configService;
711
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginWorkerThreadConfig, this._config);
712
+ this._configService.setConfig(PLUGIN_CONFIG_KEY_WORKER_THREAD, rest);
713
+ }
714
+ onStarting() {
715
+ [
716
+ [DataSyncReplicaController],
717
+ [IRPCChannelService, { useFactory: () => new ChannelService(createWebWorkerMessagePortOnWorker()) }],
718
+ [IRemoteInstanceService, { useClass: WebWorkerRemoteInstanceService }]
719
+ ].forEach((dependency) => this._injector.add(dependency));
720
+ this._injector.get(DataSyncReplicaController);
721
+ }
722
+ };
723
+ _defineProperty(UniverRPCWorkerThreadPlugin, "pluginName", "UNIVER_RPC_WORKER_THREAD_PLUGIN");
724
+ _defineProperty(UniverRPCWorkerThreadPlugin, "packageName", name);
725
+ _defineProperty(UniverRPCWorkerThreadPlugin, "version", version);
726
+ UniverRPCWorkerThreadPlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_core.IConfigService)], UniverRPCWorkerThreadPlugin);
727
+
728
+ //#endregion
729
+ exports.ChannelClient = ChannelClient;
730
+ exports.ChannelServer = ChannelServer;
731
+ exports.ChannelService = ChannelService;
732
+ Object.defineProperty(exports, 'DataSyncPrimaryController', {
733
+ enumerable: true,
734
+ get: function () {
735
+ return DataSyncPrimaryController;
736
+ }
737
+ });
738
+ Object.defineProperty(exports, 'DataSyncReplicaController', {
739
+ enumerable: true,
740
+ get: function () {
741
+ return DataSyncReplicaController;
742
+ }
743
+ });
744
+ exports.IRPCChannelService = IRPCChannelService;
745
+ exports.IRemoteInstanceService = IRemoteInstanceService;
746
+ exports.IRemoteSyncService = IRemoteSyncService;
747
+ exports.PLUGIN_CONFIG_KEY_MAIN_THREAD = PLUGIN_CONFIG_KEY_MAIN_THREAD;
748
+ exports.PLUGIN_CONFIG_KEY_WORKER_THREAD = PLUGIN_CONFIG_KEY_WORKER_THREAD;
749
+ exports.RemoteInstanceServiceName = RemoteInstanceServiceName;
750
+ Object.defineProperty(exports, 'RemoteSyncPrimaryService', {
751
+ enumerable: true,
752
+ get: function () {
753
+ return RemoteSyncPrimaryService;
754
+ }
755
+ });
756
+ exports.RemoteSyncServiceName = RemoteSyncServiceName;
757
+ Object.defineProperty(exports, 'UniverRPCMainThreadPlugin', {
758
+ enumerable: true,
759
+ get: function () {
760
+ return UniverRPCMainThreadPlugin;
761
+ }
762
+ });
763
+ Object.defineProperty(exports, 'UniverRPCWorkerThreadPlugin', {
764
+ enumerable: true,
765
+ get: function () {
766
+ return UniverRPCWorkerThreadPlugin;
767
+ }
768
+ });
769
+ Object.defineProperty(exports, 'WebWorkerRemoteInstanceService', {
770
+ enumerable: true,
771
+ get: function () {
772
+ return WebWorkerRemoteInstanceService;
773
+ }
774
+ });
775
+ exports.fromModule = fromModule;
776
+ exports.toModule = toModule;