@univerjs/rpc 0.5.4 → 0.5.5-experimental.20250123-34738ff
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 +1 -1
- package/lib/es/index.js +335 -322
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
- package/LICENSE +0 -176
- package/lib/types/services/rpc/__tests__/rpc.service.spec.d.ts +0 -16
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var N=Object.defineProperty;var k=(i,t,e)=>t in i?N(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var l=(i,t,e)=>k(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),u=require("rxjs/operators"),_=require("rxjs"),x="rpc.main-thread.config",T={},L="rpc.worker-thread.config",q={};var H=Object.defineProperty,A=Object.getOwnPropertyDescriptor,W=(i,t,e,n)=>{for(var s=n>1?void 0:n?A(t,e):t,r=i.length-1,c;r>=0;r--)(c=i[r])&&(s=(n?c(t,e,s):c(s))||s);return n&&s&&H(t,e,s),s},f=(i,t)=>(e,n)=>t(e,n,i);const g="rpc.remote-sync.service",v=a.createIdentifier(g);exports.RemoteSyncPrimaryService=class{constructor(t){this._commandService=t}async syncMutation(t){return this._commandService.syncExecuteCommand(t.mutationInfo.id,t.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}};exports.RemoteSyncPrimaryService=W([f(0,a.ICommandService)],exports.RemoteSyncPrimaryService);const R="univer.remote-instance-service",m=a.createIdentifier(R);exports.WebWorkerRemoteInstanceService=class{constructor(t,e,n){this._univerInstanceService=t,this._commandService=e,this._logService=n}whenReady(){return Promise.resolve(!0)}async syncMutation(t){return this._applyMutation(t.mutationInfo)}async createInstance(t){const{type:e,snapshot:n}=t;try{switch(e){case a.UniverInstanceType.UNIVER_SHEET:return this._univerInstanceService.createUnit(a.UniverInstanceType.UNIVER_SHEET,n),!0;default:throw new Error(`[WebWorkerRemoteInstanceService]: cannot create replica for document type: ${e}.`)}}catch(s){throw s instanceof Error?s:new TypeError(`${s}`)}}async disposeInstance(t){return this._univerInstanceService.disposeUnit(t.unitID)}_applyMutation(t){const{id:e,params:n}=t;return this._commandService.syncExecuteCommand(e,n,{onlyLocal:!0,fromSync:!0})}};exports.WebWorkerRemoteInstanceService=W([f(0,a.IUniverInstanceService),f(1,a.ICommandService),f(2,a.ILogService)],exports.WebWorkerRemoteInstanceService);function U(i){const t=i;return new class{call(e,n){const s=t[e];if(typeof s=="function"){let r=n?s.apply(t,n):s.call(t);return r instanceof Promise||(r=Promise.resolve(r)),r}throw new Error(`[RPC]: method not found for ${e}!`)}subscribe(e,n){const s=t[e];if(typeof s=="function"){const r=n?s.apply(t,n):s.call(t);return _.isObservable(r)?r:_.of(r)}throw new Error(`[RPC]: observable method not found for ${e}!`)}}}function E(i){return new Proxy({},{get(t,e){if(e!=="dispose")return function(...n){return V(e)?i.subscribe(e,n):i.call(e,n)}}})}function V(i){return i.endsWith("$")}class j extends a.RxDisposable{constructor(e){super();l(this,"_initialized",new _.BehaviorSubject(!1));l(this,"_lastRequestCounter",0);l(this,"_pendingRequests",new Map);this._protocol=e,this._protocol.send({type:50}),this._protocol.onMessage.pipe(u.takeUntil(this.dispose$)).subscribe(n=>this._onMessage(n))}dispose(){this._pendingRequests.clear()}getChannel(e){const n=this;return{call(s,r){return n._disposed?Promise.reject():n._remoteCall(e,s,r)},subscribe(s,r){if(n._disposed)throw new Error("[ChannelClient]: client is disposed!");return n._remoteSubscribe(e,s,r)}}}_whenReady(){return _.firstValueFrom(this._initialized.pipe(u.filter(e=>e),u.take(1)))}async _remoteCall(e,n,s){await this._whenReady();const r=++this._lastRequestCounter,h={seq:r,type:100,channelName:e,method:n,args:s},o=this;return new Promise((I,d)=>{const $={handle(b){switch(b.type){case 201:o._pendingRequests.delete(r),I(b.data);break;case 202:o._pendingRequests.delete(r),d(b.data);break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(r,$),this._sendRequest(h)})}_remoteSubscribe(e,n,s){return new _.Observable(r=>{let c=-1;return this._whenReady().then(()=>{c=++this._lastRequestCounter;const o={seq:c,type:101,channelName:e,method:n,args:s},I={handle(d){switch(d.type){case 300:r.next(d.data);break;case 301:r.error(d.data);break;case 302:r.complete();break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(c,I),this._sendRequest(o)}),()=>{if(c===-1)return;const h={type:102,seq:c,channelName:e,method:n};this._sendRequest(h)}})}_sendRequest(e){this._protocol.send(e)}_onMessage(e){var n;switch(e.type){case 0:this._initialized.next(!0);break;case 201:case 202:case 300:case 302:case 301:(n=this._pendingRequests.get(e.seq))==null||n.handle(e);break}}}class D extends a.RxDisposable{constructor(e){super();l(this,"_channels",new Map);l(this,"_subscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(u.takeUntil(this.dispose$)).subscribe(n=>this._onRequest(n)),this._sendInitialize()}dispose(){super.dispose(),this._subscriptions.clear(),this._channels.clear()}registerChannel(e,n){this._channels.set(e,n)}_onRequest(e){switch(e.type){case 50:this._sendInitialize();break;case 100:this._onMethodCall(e);break;case 101:this._onSubscribe(e);break;case 102:this._onUnsubscribe(e);break}}_sendInitialize(){this._sendResponse({seq:-1,type:0})}_onMethodCall(e){const{channelName:n,method:s,args:r}=e,c=this._channels.get(n);let h;try{if(!c)throw new Error(`[ChannelServer]: Channel ${n} not found!`);h=r?c.call(s,r):c.call(s)}catch(o){h=Promise.reject(o)}h.then(o=>{this._sendResponse({seq:e.seq,type:201,data:o})}).catch(o=>{o instanceof Error?this._sendResponse({seq:e.seq,type:202,data:o.message}):this._sendResponse({seq:e.seq,type:202,data:String(o)})})}_onSubscribe(e){const{channelName:n,seq:s}=e,r=this._channels.get(n);try{if(!r)throw new Error(`[ChannelServer]: Channel ${n} not found!`);const h=r.subscribe(e.method,e.args).subscribe({next:o=>{this._sendResponse({seq:s,type:300,data:o})},error:o=>{this._sendResponse({seq:s,type:301,data:o.message}),this._sendResponse({seq:s,type:302})},complete:()=>{this._sendResponse({seq:s,type:302})}});this._subscriptions.set(e.seq,h)}catch(c){c instanceof Error?this._sendResponse({seq:e.seq,type:301,data:c.message}):this._sendResponse({seq:e.seq,type:301,data:String(c)})}}_onUnsubscribe(e){const n=this._subscriptions.get(e.seq);n&&(n.unsubscribe(),this._subscriptions.delete(e.seq))}_sendResponse(e){this._protocol.send(e)}}const S=a.createIdentifier("IRPCChannelService");class M{constructor(t){l(this,"_client");l(this,"_server");this._client=new j(t),this._server=new D(t)}dispose(){this._client.dispose(),this._server.dispose()}requestChannel(t){return this._client.getChannel(t)}registerChannel(t,e){this._server.registerChannel(t,e)}}var F=Object.defineProperty,z=Object.getOwnPropertyDescriptor,G=(i,t,e,n)=>{for(var s=n>1?void 0:n?z(t,e):t,r=i.length-1,c;r>=0;r--)(c=i[r])&&(s=(n?c(t,e,s):c(s))||s);return n&&s&&F(t,e,s),s},p=(i,t)=>(e,n)=>t(e,n,i);exports.DataSyncPrimaryController=class extends a.RxDisposable{constructor(e,n,s,r,c){super();l(this,"_remoteInstanceService");l(this,"_syncingUnits",new Set);l(this,"_syncingMutations",new Set);this._injector=e,this._commandService=n,this._univerInstanceService=s,this._rpcChannelService=r,this._remoteSyncService=c,this._initRPCChannels(),this._init()}registerSyncingMutations(e){this._syncingMutations.add(e.id)}syncUnit(e){return this._syncingUnits.add(e),a.toDisposable(()=>this._syncingUnits.delete(e))}_initRPCChannels(){this._rpcChannelService.registerChannel(g,U(this._remoteSyncService)),this._injector.add([m,{useFactory:()=>E(this._rpcChannelService.requestChannel(R))}]),this._remoteInstanceService=this._injector.get(m)}_init(){this._univerInstanceService.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(u.takeUntil(this.dispose$)).subscribe(e=>{this._syncingUnits.add(e.getUnitId()),this._remoteInstanceService.createInstance({unitID:e.getUnitId(),type:a.UniverInstanceType.UNIVER_SHEET,snapshot:e.getSnapshot()})}),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(u.takeUntil(this.dispose$)).subscribe(e=>{this._syncingUnits.delete(e.getUnitId()),this._remoteInstanceService.disposeInstance({unitID:e.getUnitId()})}),this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{const{type:s,params:r,id:c}=e,h=(r==null?void 0:r.unitId)||"";s===a.CommandType.MUTATION&&(!h||this._syncingUnits.has(h))&&!(n!=null&&n.fromSync)&&this._syncingMutations.has(c)&&this._remoteInstanceService.syncMutation({mutationInfo:e})}))}};exports.DataSyncPrimaryController=G([p(0,a.Inject(a.Injector)),p(1,a.ICommandService),p(2,a.IUniverInstanceService),p(3,S),p(4,v)],exports.DataSyncPrimaryController);var Y=Object.defineProperty,B=Object.getOwnPropertyDescriptor,K=(i,t,e,n)=>{for(var s=n>1?void 0:n?B(t,e):t,r=i.length-1,c;r>=0;r--)(c=i[r])&&(s=(n?c(t,e,s):c(s))||s);return n&&s&&Y(t,e,s),s},y=(i,t)=>(e,n)=>t(e,n,i);exports.DataSyncReplicaController=class extends a.Disposable{constructor(e,n,s,r){super();l(this,"_remoteSyncService");this._injector=e,this._remoteInstanceService=n,this._commandService=s,this._rpcChannelService=r,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(R,U(this._remoteInstanceService)),this._injector.add([v,{useFactory:()=>E(this._rpcChannelService.requestChannel(g))}]),this._remoteSyncService=this._injector.get(v)}_init(){this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{e.type===a.CommandType.MUTATION&&!(n!=null&&n.fromSync)&&this._remoteSyncService.syncMutation({mutationInfo:e})}))}};exports.DataSyncReplicaController=K([y(0,a.Inject(a.Injector)),y(1,m),y(2,a.ICommandService),y(3,S)],exports.DataSyncReplicaController);function J(){return{send(i){postMessage(i)},onMessage:new _.Observable(i=>{const t=e=>{i.next(e.data)};return addEventListener("message",t),()=>removeEventListener("message",t)}).pipe(_.shareReplay(1))}}function Q(i){return{send(t){i.postMessage(t)},onMessage:new _.Observable(t=>{const e=n=>{t.next(n.data)};return i.addEventListener("message",e),()=>i.removeEventListener("message",e)}).pipe(_.shareReplay(1))}}var X=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,O=(i,t,e,n)=>{for(var s=n>1?void 0:n?Z(t,e):t,r=i.length-1,c;r>=0;r--)(c=i[r])&&(s=(n?c(t,e,s):c(s))||s);return n&&s&&X(t,e,s),s},C=(i,t)=>(e,n)=>t(e,n,i),P;exports.UniverRPCMainThreadPlugin=(P=class extends a.Plugin{constructor(e=T,n,s){super();l(this,"_internalWorker",null);this._config=e,this._injector=n,this._configService=s;const{...r}=a.merge({},T,this._config);this._configService.setConfig(x,r)}dispose(){super.dispose(),this._internalWorker&&(this._internalWorker.terminate(),this._internalWorker=null)}onStarting(){const{workerURL:e}=this._config;if(!e)throw new Error("[UniverRPCMainThreadPlugin]: The workerURL is required for the RPC main thread plugin.");const n=e instanceof Worker?e:new Worker(e);this._internalWorker=e instanceof Worker?null:n;const s=Q(n);[[S,{useFactory:()=>new M(s)}],[exports.DataSyncPrimaryController],[v,{useClass:exports.RemoteSyncPrimaryService}]].forEach(c=>this._injector.add(c)),this._injector.get(exports.DataSyncPrimaryController)}},l(P,"pluginName","UNIVER_RPC_MAIN_THREAD_PLUGIN"),P);exports.UniverRPCMainThreadPlugin=O([C(1,a.Inject(a.Injector)),C(2,a.IConfigService)],exports.UniverRPCMainThreadPlugin);var w;exports.UniverRPCWorkerThreadPlugin=(w=class extends a.Plugin{constructor(t=q,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...s}=a.merge({},q,this._config);this._configService.setConfig(L,s)}onStarting(){[[exports.DataSyncReplicaController],[S,{useFactory:()=>new M(J())}],[m,{useClass:exports.WebWorkerRemoteInstanceService}]].forEach(t=>this._injector.add(t)),this._injector.get(exports.DataSyncReplicaController)}},l(w,"pluginName","UNIVER_RPC_WORKER_THREAD_PLUGIN"),w);exports.UniverRPCWorkerThreadPlugin=O([C(1,a.Inject(a.Injector)),C(2,a.IConfigService)],exports.UniverRPCWorkerThreadPlugin);exports.ChannelClient=j;exports.ChannelServer=D;exports.ChannelService=M;exports.IRPCChannelService=S;exports.IRemoteInstanceService=m;exports.IRemoteSyncService=v;exports.RemoteInstanceServiceName=R;exports.RemoteSyncServiceName=g;exports.fromModule=U;exports.toModule=E;
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),operators=require("rxjs/operators"),rxjs=require("rxjs"),PLUGIN_CONFIG_KEY_MAIN_THREAD="rpc.main-thread.config",defaultPluginMainThreadConfig={},PLUGIN_CONFIG_KEY_WORKER_THREAD="rpc.worker-thread.config",defaultPluginWorkerThreadConfig={};var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");const RemoteSyncServiceName="rpc.remote-sync.service",IRemoteSyncService=core.createIdentifier(RemoteSyncServiceName);var _a;exports.RemoteSyncPrimaryService=(_a=class{constructor(_commandService){this._commandService=_commandService}async syncMutation(params){return this._commandService.syncExecuteCommand(params.mutationInfo.id,params.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}},__name(_a,"RemoteSyncPrimaryService"),_a);exports.RemoteSyncPrimaryService=__decorateClass$3([__decorateParam$3(0,core.ICommandService)],exports.RemoteSyncPrimaryService);const RemoteInstanceServiceName="univer.remote-instance-service",IRemoteInstanceService=core.createIdentifier(RemoteInstanceServiceName);var _a2;exports.WebWorkerRemoteInstanceService=(_a2=class{constructor(_univerInstanceService,_commandService,_logService){this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._logService=_logService}whenReady(){return Promise.resolve(!0)}async syncMutation(params){return this._applyMutation(params.mutationInfo)}async createInstance(params){const{type,snapshot}=params;try{switch(type){case core.UniverInstanceType.UNIVER_SHEET:return this._univerInstanceService.createUnit(core.UniverInstanceType.UNIVER_SHEET,snapshot),!0;default:throw new Error(`[WebWorkerRemoteInstanceService]: cannot create replica for document type: ${type}.`)}}catch(err){throw err instanceof Error?err:new TypeError(`${err}`)}}async disposeInstance(params){return this._univerInstanceService.disposeUnit(params.unitID)}_applyMutation(mutationInfo){const{id,params:mutationParams}=mutationInfo;return this._commandService.syncExecuteCommand(id,mutationParams,{onlyLocal:!0,fromSync:!0})}},__name(_a2,"WebWorkerRemoteInstanceService"),_a2);exports.WebWorkerRemoteInstanceService=__decorateClass$3([__decorateParam$3(0,core.IUniverInstanceService),__decorateParam$3(1,core.ICommandService),__decorateParam$3(2,core.ILogService)],exports.WebWorkerRemoteInstanceService);function fromModule(module2){const handler=module2;return new class{call(method,args){const target=handler[method];if(typeof target=="function"){let res=args?target.apply(handler,args):target.call(handler);return res instanceof Promise||(res=Promise.resolve(res)),res}throw new Error(`[RPC]: method not found for ${method}!`)}subscribe(eventMethod,args){const target=handler[eventMethod];if(typeof target=="function"){const res=args?target.apply(handler,args):target.call(handler);return rxjs.isObservable(res)?res:rxjs.of(res)}throw new Error(`[RPC]: observable method not found for ${eventMethod}!`)}}}__name(fromModule,"fromModule");function toModule(channel){return new Proxy({},{get(_,propKey){if(propKey!=="dispose")return function(...args){return propertyIsEventSource(propKey)?channel.subscribe(propKey,args):channel.call(propKey,args)}}})}__name(toModule,"toModule");function propertyIsEventSource(name){return name.endsWith("$")}__name(propertyIsEventSource,"propertyIsEventSource");const _ChannelClient=class _ChannelClient extends core.RxDisposable{constructor(_protocol){super();__publicField(this,"_initialized",new rxjs.BehaviorSubject(!1));__publicField(this,"_lastRequestCounter",0);__publicField(this,"_pendingRequests",new Map);this._protocol=_protocol,this._protocol.send({type:50}),this._protocol.onMessage.pipe(operators.takeUntil(this.dispose$)).subscribe(message=>this._onMessage(message))}dispose(){this._pendingRequests.clear()}getChannel(channelName){const self=this;return{call(method,args){return self._disposed?Promise.reject():self._remoteCall(channelName,method,args)},subscribe(eventMethod,args){if(self._disposed)throw new Error("[ChannelClient]: client is disposed!");return self._remoteSubscribe(channelName,eventMethod,args)}}}_whenReady(){return rxjs.firstValueFrom(this._initialized.pipe(operators.filter(v=>v),operators.take(1)))}async _remoteCall(channelName,method,args){await this._whenReady();const sequence=++this._lastRequestCounter,request={seq:sequence,type:100,channelName,method,args},client=this;return new Promise((resolve,reject)=>{const responseHandler={handle(response){switch(response.type){case 201:client._pendingRequests.delete(sequence),resolve(response.data);break;case 202:client._pendingRequests.delete(sequence),reject(response.data);break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(sequence,responseHandler),this._sendRequest(request)})}_remoteSubscribe(channelName,method,args){return new rxjs.Observable(subscriber=>{let sequence=-1;return this._whenReady().then(()=>{sequence=++this._lastRequestCounter;const request={seq:sequence,type:101,channelName,method,args},responseHandler={handle(response){switch(response.type){case 300:subscriber.next(response.data);break;case 301:subscriber.error(response.data);break;case 302:subscriber.complete();break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(sequence,responseHandler),this._sendRequest(request)}),()=>{if(sequence===-1)return;const cancelSubscriptionRequest={type:102,seq:sequence,channelName,method};this._sendRequest(cancelSubscriptionRequest)}})}_sendRequest(request){this._protocol.send(request)}_onMessage(response){var _a7;switch(response.type){case 0:this._initialized.next(!0);break;case 201:case 202:case 300:case 302:case 301:(_a7=this._pendingRequests.get(response.seq))==null||_a7.handle(response);break}}};__name(_ChannelClient,"ChannelClient");let ChannelClient=_ChannelClient;const _ChannelServer=class _ChannelServer extends core.RxDisposable{constructor(_protocol){super();__publicField(this,"_channels",new Map);__publicField(this,"_subscriptions",new Map);this._protocol=_protocol,this._protocol.onMessage.pipe(operators.takeUntil(this.dispose$)).subscribe(message=>this._onRequest(message)),this._sendInitialize()}dispose(){super.dispose(),this._subscriptions.clear(),this._channels.clear()}registerChannel(channelName,channel){this._channels.set(channelName,channel)}_onRequest(request){switch(request.type){case 50:this._sendInitialize();break;case 100:this._onMethodCall(request);break;case 101:this._onSubscribe(request);break;case 102:this._onUnsubscribe(request);break}}_sendInitialize(){this._sendResponse({seq:-1,type:0})}_onMethodCall(request){const{channelName,method,args}=request,channel=this._channels.get(channelName);let promise;try{if(!channel)throw new Error(`[ChannelServer]: Channel ${channelName} not found!`);promise=args?channel.call(method,args):channel.call(method)}catch(err){promise=Promise.reject(err)}promise.then(data=>{this._sendResponse({seq:request.seq,type:201,data})}).catch(err=>{err instanceof Error?this._sendResponse({seq:request.seq,type:202,data:err.message}):this._sendResponse({seq:request.seq,type:202,data:String(err)})})}_onSubscribe(request){const{channelName,seq}=request,channel=this._channels.get(channelName);try{if(!channel)throw new Error(`[ChannelServer]: Channel ${channelName} not found!`);const subscription=channel.subscribe(request.method,request.args).subscribe({next:__name(data=>{this._sendResponse({seq,type:300,data})},"next"),error:__name(err=>{this._sendResponse({seq,type:301,data:err.message}),this._sendResponse({seq,type:302})},"error"),complete:__name(()=>{this._sendResponse({seq,type:302})},"complete")});this._subscriptions.set(request.seq,subscription)}catch(err){err instanceof Error?this._sendResponse({seq:request.seq,type:301,data:err.message}):this._sendResponse({seq:request.seq,type:301,data:String(err)})}}_onUnsubscribe(request){const subscription=this._subscriptions.get(request.seq);subscription&&(subscription.unsubscribe(),this._subscriptions.delete(request.seq))}_sendResponse(response){this._protocol.send(response)}};__name(_ChannelServer,"ChannelServer");let ChannelServer=_ChannelServer;const IRPCChannelService=core.createIdentifier("IRPCChannelService"),_ChannelService=class _ChannelService{constructor(_messageProtocol){__publicField(this,"_client");__publicField(this,"_server");this._client=new ChannelClient(_messageProtocol),this._server=new ChannelServer(_messageProtocol)}dispose(){this._client.dispose(),this._server.dispose()}requestChannel(name){return this._client.getChannel(name)}registerChannel(name,channel){this._server.registerChannel(name,channel)}};__name(_ChannelService,"ChannelService");let ChannelService=_ChannelService;var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a3;exports.DataSyncPrimaryController=(_a3=class extends core.RxDisposable{constructor(_injector,_commandService,_univerInstanceService,_rpcChannelService,_remoteSyncService){super();__publicField(this,"_remoteInstanceService");__publicField(this,"_syncingUnits",new Set);__publicField(this,"_syncingMutations",new Set);this._injector=_injector,this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._rpcChannelService=_rpcChannelService,this._remoteSyncService=_remoteSyncService,this._initRPCChannels(),this._init()}registerSyncingMutations(mutation){this._syncingMutations.add(mutation.id)}syncUnit(unitId){return this._syncingUnits.add(unitId),core.toDisposable(()=>this._syncingUnits.delete(unitId))}_initRPCChannels(){this._rpcChannelService.registerChannel(RemoteSyncServiceName,fromModule(this._remoteSyncService)),this._injector.add([IRemoteInstanceService,{useFactory:__name(()=>toModule(this._rpcChannelService.requestChannel(RemoteInstanceServiceName)),"useFactory")}]),this._remoteInstanceService=this._injector.get(IRemoteInstanceService)}_init(){this._univerInstanceService.getTypeOfUnitAdded$(core.UniverInstanceType.UNIVER_SHEET).pipe(operators.takeUntil(this.dispose$)).subscribe(sheet=>{this._syncingUnits.add(sheet.getUnitId()),this._remoteInstanceService.createInstance({unitID:sheet.getUnitId(),type:core.UniverInstanceType.UNIVER_SHEET,snapshot:sheet.getSnapshot()})}),this._univerInstanceService.getTypeOfUnitDisposed$(core.UniverInstanceType.UNIVER_SHEET).pipe(operators.takeUntil(this.dispose$)).subscribe(workbook=>{this._syncingUnits.delete(workbook.getUnitId()),this._remoteInstanceService.disposeInstance({unitID:workbook.getUnitId()})}),this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo,options)=>{const{type,params,id}=commandInfo,unitId=(params==null?void 0:params.unitId)||"";type===core.CommandType.MUTATION&&(!unitId||this._syncingUnits.has(unitId))&&!(options!=null&&options.fromSync)&&this._syncingMutations.has(id)&&this._remoteInstanceService.syncMutation({mutationInfo:commandInfo})}))}},__name(_a3,"DataSyncPrimaryController"),_a3);exports.DataSyncPrimaryController=__decorateClass$2([__decorateParam$2(0,core.Inject(core.Injector)),__decorateParam$2(1,core.ICommandService),__decorateParam$2(2,core.IUniverInstanceService),__decorateParam$2(3,IRPCChannelService),__decorateParam$2(4,IRemoteSyncService)],exports.DataSyncPrimaryController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a4;exports.DataSyncReplicaController=(_a4=class extends core.Disposable{constructor(_injector,_remoteInstanceService,_commandService,_rpcChannelService){super();__publicField(this,"_remoteSyncService");this._injector=_injector,this._remoteInstanceService=_remoteInstanceService,this._commandService=_commandService,this._rpcChannelService=_rpcChannelService,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(RemoteInstanceServiceName,fromModule(this._remoteInstanceService)),this._injector.add([IRemoteSyncService,{useFactory:__name(()=>toModule(this._rpcChannelService.requestChannel(RemoteSyncServiceName)),"useFactory")}]),this._remoteSyncService=this._injector.get(IRemoteSyncService)}_init(){this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo,options)=>{commandInfo.type===core.CommandType.MUTATION&&!(options!=null&&options.fromSync)&&this._remoteSyncService.syncMutation({mutationInfo:commandInfo})}))}},__name(_a4,"DataSyncReplicaController"),_a4);exports.DataSyncReplicaController=__decorateClass$1([__decorateParam$1(0,core.Inject(core.Injector)),__decorateParam$1(1,IRemoteInstanceService),__decorateParam$1(2,core.ICommandService),__decorateParam$1(3,IRPCChannelService)],exports.DataSyncReplicaController);function createWebWorkerMessagePortOnWorker(){return{send(message){postMessage(message)},onMessage:new rxjs.Observable(subscriber=>{const handler=__name(event=>{subscriber.next(event.data)},"handler");return addEventListener("message",handler),()=>removeEventListener("message",handler)}).pipe(rxjs.shareReplay(1))}}__name(createWebWorkerMessagePortOnWorker,"createWebWorkerMessagePortOnWorker");function createWebWorkerMessagePortOnMain(worker){return{send(message){worker.postMessage(message)},onMessage:new rxjs.Observable(subscriber=>{const handler=__name(event=>{subscriber.next(event.data)},"handler");return worker.addEventListener("message",handler),()=>worker.removeEventListener("message",handler)}).pipe(rxjs.shareReplay(1))}}__name(createWebWorkerMessagePortOnMain,"createWebWorkerMessagePortOnMain");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),_a5;exports.UniverRPCMainThreadPlugin=(_a5=class extends core.Plugin{constructor(_config=defaultPluginMainThreadConfig,_injector,_configService){super();__publicField(this,"_internalWorker",null);this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=core.merge({},defaultPluginMainThreadConfig,this._config);this._configService.setConfig(PLUGIN_CONFIG_KEY_MAIN_THREAD,rest)}dispose(){super.dispose(),this._internalWorker&&(this._internalWorker.terminate(),this._internalWorker=null)}onStarting(){const{workerURL}=this._config;if(!workerURL)throw new Error("[UniverRPCMainThreadPlugin]: The workerURL is required for the RPC main thread plugin.");const worker=workerURL instanceof Worker?workerURL:new Worker(workerURL);this._internalWorker=workerURL instanceof Worker?null:worker;const messageProtocol=createWebWorkerMessagePortOnMain(worker);[[IRPCChannelService,{useFactory:__name(()=>new ChannelService(messageProtocol),"useFactory")}],[exports.DataSyncPrimaryController],[IRemoteSyncService,{useClass:exports.RemoteSyncPrimaryService}]].forEach(dependency=>this._injector.add(dependency)),this._injector.get(exports.DataSyncPrimaryController)}},__name(_a5,"UniverRPCMainThreadPlugin"),__publicField(_a5,"pluginName","UNIVER_RPC_MAIN_THREAD_PLUGIN"),_a5);exports.UniverRPCMainThreadPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverRPCMainThreadPlugin);var _a6;exports.UniverRPCWorkerThreadPlugin=(_a6=class extends core.Plugin{constructor(_config=defaultPluginWorkerThreadConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=core.merge({},defaultPluginWorkerThreadConfig,this._config);this._configService.setConfig(PLUGIN_CONFIG_KEY_WORKER_THREAD,rest)}onStarting(){[[exports.DataSyncReplicaController],[IRPCChannelService,{useFactory:__name(()=>new ChannelService(createWebWorkerMessagePortOnWorker()),"useFactory")}],[IRemoteInstanceService,{useClass:exports.WebWorkerRemoteInstanceService}]].forEach(dependency=>this._injector.add(dependency)),this._injector.get(exports.DataSyncReplicaController)}},__name(_a6,"UniverRPCWorkerThreadPlugin"),__publicField(_a6,"pluginName","UNIVER_RPC_WORKER_THREAD_PLUGIN"),_a6);exports.UniverRPCWorkerThreadPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverRPCWorkerThreadPlugin);exports.ChannelClient=ChannelClient;exports.ChannelServer=ChannelServer;exports.ChannelService=ChannelService;exports.IRPCChannelService=IRPCChannelService;exports.IRemoteInstanceService=IRemoteInstanceService;exports.IRemoteSyncService=IRemoteSyncService;exports.RemoteInstanceServiceName=RemoteInstanceServiceName;exports.RemoteSyncServiceName=RemoteSyncServiceName;exports.fromModule=fromModule;exports.toModule=toModule;
|
package/lib/es/index.js
CHANGED
|
@@ -1,204 +1,210 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { createIdentifier, UniverInstanceType, ICommandService, IUniverInstanceService, ILogService, RxDisposable, Inject, Injector, toDisposable, CommandType, Disposable, Plugin, merge, IConfigService } from "@univerjs/core";
|
|
6
|
+
import { takeUntil, filter, take } from "rxjs/operators";
|
|
7
|
+
import { isObservable, of, BehaviorSubject, firstValueFrom, Observable, shareReplay } from "rxjs";
|
|
8
|
+
const PLUGIN_CONFIG_KEY_MAIN_THREAD = "rpc.main-thread.config", defaultPluginMainThreadConfig = {}, PLUGIN_CONFIG_KEY_WORKER_THREAD = "rpc.worker-thread.config", defaultPluginWorkerThreadConfig = {};
|
|
9
|
+
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
10
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
11
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
12
|
+
return kind && result && __defProp$3(target, key, result), result;
|
|
13
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3");
|
|
14
|
+
const RemoteSyncServiceName = "rpc.remote-sync.service", IRemoteSyncService = createIdentifier(RemoteSyncServiceName);
|
|
15
|
+
var _a;
|
|
16
|
+
let RemoteSyncPrimaryService = (_a = class {
|
|
17
|
+
constructor(_commandService) {
|
|
18
|
+
this._commandService = _commandService;
|
|
19
|
+
}
|
|
20
|
+
async syncMutation(params) {
|
|
21
|
+
return this._commandService.syncExecuteCommand(params.mutationInfo.id, params.mutationInfo.params, {
|
|
20
22
|
onlyLocal: !0,
|
|
21
23
|
fromSync: !0
|
|
22
24
|
});
|
|
23
25
|
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
],
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
}, __name(_a, "RemoteSyncPrimaryService"), _a);
|
|
27
|
+
RemoteSyncPrimaryService = __decorateClass$3([
|
|
28
|
+
__decorateParam$3(0, ICommandService)
|
|
29
|
+
], RemoteSyncPrimaryService);
|
|
30
|
+
const RemoteInstanceServiceName = "univer.remote-instance-service", IRemoteInstanceService = createIdentifier(RemoteInstanceServiceName);
|
|
31
|
+
var _a2;
|
|
32
|
+
let WebWorkerRemoteInstanceService = (_a2 = class {
|
|
33
|
+
constructor(_univerInstanceService, _commandService, _logService) {
|
|
34
|
+
this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._logService = _logService;
|
|
32
35
|
}
|
|
33
36
|
whenReady() {
|
|
34
37
|
return Promise.resolve(!0);
|
|
35
38
|
}
|
|
36
|
-
async syncMutation(
|
|
37
|
-
return this._applyMutation(
|
|
39
|
+
async syncMutation(params) {
|
|
40
|
+
return this._applyMutation(params.mutationInfo);
|
|
38
41
|
}
|
|
39
|
-
async createInstance(
|
|
40
|
-
const { type
|
|
42
|
+
async createInstance(params) {
|
|
43
|
+
const { type, snapshot } = params;
|
|
41
44
|
try {
|
|
42
|
-
switch (
|
|
43
|
-
case
|
|
44
|
-
return this._univerInstanceService.createUnit(
|
|
45
|
+
switch (type) {
|
|
46
|
+
case UniverInstanceType.UNIVER_SHEET:
|
|
47
|
+
return this._univerInstanceService.createUnit(UniverInstanceType.UNIVER_SHEET, snapshot), !0;
|
|
45
48
|
default:
|
|
46
49
|
throw new Error(
|
|
47
|
-
`[WebWorkerRemoteInstanceService]: cannot create replica for document type: ${
|
|
50
|
+
`[WebWorkerRemoteInstanceService]: cannot create replica for document type: ${type}.`
|
|
48
51
|
);
|
|
49
52
|
}
|
|
50
|
-
} catch (
|
|
51
|
-
throw
|
|
53
|
+
} catch (err) {
|
|
54
|
+
throw err instanceof Error ? err : new TypeError(`${err}`);
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
async disposeInstance(
|
|
55
|
-
return this._univerInstanceService.disposeUnit(
|
|
57
|
+
async disposeInstance(params) {
|
|
58
|
+
return this._univerInstanceService.disposeUnit(params.unitID);
|
|
56
59
|
}
|
|
57
|
-
_applyMutation(
|
|
58
|
-
const { id
|
|
59
|
-
return this._commandService.syncExecuteCommand(
|
|
60
|
+
_applyMutation(mutationInfo) {
|
|
61
|
+
const { id, params: mutationParams } = mutationInfo;
|
|
62
|
+
return this._commandService.syncExecuteCommand(id, mutationParams, {
|
|
60
63
|
onlyLocal: !0,
|
|
61
64
|
fromSync: !0
|
|
62
65
|
});
|
|
63
66
|
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
],
|
|
70
|
-
function
|
|
71
|
-
const
|
|
67
|
+
}, __name(_a2, "WebWorkerRemoteInstanceService"), _a2);
|
|
68
|
+
WebWorkerRemoteInstanceService = __decorateClass$3([
|
|
69
|
+
__decorateParam$3(0, IUniverInstanceService),
|
|
70
|
+
__decorateParam$3(1, ICommandService),
|
|
71
|
+
__decorateParam$3(2, ILogService)
|
|
72
|
+
], WebWorkerRemoteInstanceService);
|
|
73
|
+
function fromModule(module) {
|
|
74
|
+
const handler = module;
|
|
72
75
|
return new class {
|
|
73
|
-
call(
|
|
74
|
-
const
|
|
75
|
-
if (typeof
|
|
76
|
-
let
|
|
77
|
-
return
|
|
76
|
+
call(method, args) {
|
|
77
|
+
const target = handler[method];
|
|
78
|
+
if (typeof target == "function") {
|
|
79
|
+
let res = args ? target.apply(handler, args) : target.call(handler);
|
|
80
|
+
return res instanceof Promise || (res = Promise.resolve(res)), res;
|
|
78
81
|
}
|
|
79
|
-
throw new Error(`[RPC]: method not found for ${
|
|
82
|
+
throw new Error(`[RPC]: method not found for ${method}!`);
|
|
80
83
|
}
|
|
81
|
-
subscribe(
|
|
82
|
-
const
|
|
83
|
-
if (typeof
|
|
84
|
-
const
|
|
85
|
-
return
|
|
84
|
+
subscribe(eventMethod, args) {
|
|
85
|
+
const target = handler[eventMethod];
|
|
86
|
+
if (typeof target == "function") {
|
|
87
|
+
const res = args ? target.apply(handler, args) : target.call(handler);
|
|
88
|
+
return isObservable(res) ? res : of(res);
|
|
86
89
|
}
|
|
87
|
-
throw new Error(`[RPC]: observable method not found for ${
|
|
90
|
+
throw new Error(`[RPC]: observable method not found for ${eventMethod}!`);
|
|
88
91
|
}
|
|
89
92
|
}();
|
|
90
93
|
}
|
|
91
|
-
|
|
94
|
+
__name(fromModule, "fromModule");
|
|
95
|
+
function toModule(channel) {
|
|
92
96
|
return new Proxy({}, {
|
|
93
|
-
get(
|
|
94
|
-
if (
|
|
95
|
-
return function(...
|
|
96
|
-
return
|
|
97
|
+
get(_, propKey) {
|
|
98
|
+
if (propKey !== "dispose")
|
|
99
|
+
return function(...args) {
|
|
100
|
+
return propertyIsEventSource(propKey) ? channel.subscribe(propKey, args) : channel.call(propKey, args);
|
|
97
101
|
};
|
|
98
102
|
}
|
|
99
103
|
});
|
|
100
104
|
}
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
__name(toModule, "toModule");
|
|
106
|
+
function propertyIsEventSource(name) {
|
|
107
|
+
return name.endsWith("$");
|
|
103
108
|
}
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
__name(propertyIsEventSource, "propertyIsEventSource");
|
|
110
|
+
const _ChannelClient = class _ChannelClient extends RxDisposable {
|
|
111
|
+
constructor(_protocol) {
|
|
106
112
|
super();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this._protocol =
|
|
113
|
+
__publicField(this, "_initialized", new BehaviorSubject(!1));
|
|
114
|
+
__publicField(this, "_lastRequestCounter", 0);
|
|
115
|
+
__publicField(this, "_pendingRequests", /* @__PURE__ */ new Map());
|
|
116
|
+
this._protocol = _protocol, this._protocol.send({
|
|
111
117
|
type: 50
|
|
112
118
|
/* REQUEST_INITIALIZATION */
|
|
113
|
-
}), this._protocol.onMessage.pipe(
|
|
119
|
+
}), this._protocol.onMessage.pipe(takeUntil(this.dispose$)).subscribe((message) => this._onMessage(message));
|
|
114
120
|
}
|
|
115
121
|
dispose() {
|
|
116
122
|
this._pendingRequests.clear();
|
|
117
123
|
}
|
|
118
|
-
getChannel(
|
|
119
|
-
const
|
|
124
|
+
getChannel(channelName) {
|
|
125
|
+
const self = this;
|
|
120
126
|
return {
|
|
121
|
-
call(
|
|
122
|
-
return
|
|
127
|
+
call(method, args) {
|
|
128
|
+
return self._disposed ? Promise.reject() : self._remoteCall(channelName, method, args);
|
|
123
129
|
},
|
|
124
|
-
subscribe(
|
|
125
|
-
if (
|
|
130
|
+
subscribe(eventMethod, args) {
|
|
131
|
+
if (self._disposed)
|
|
126
132
|
throw new Error("[ChannelClient]: client is disposed!");
|
|
127
|
-
return
|
|
133
|
+
return self._remoteSubscribe(channelName, eventMethod, args);
|
|
128
134
|
}
|
|
129
135
|
};
|
|
130
136
|
}
|
|
131
137
|
_whenReady() {
|
|
132
|
-
return
|
|
138
|
+
return firstValueFrom(
|
|
133
139
|
this._initialized.pipe(
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
filter((v) => v),
|
|
141
|
+
take(1)
|
|
136
142
|
)
|
|
137
143
|
);
|
|
138
144
|
}
|
|
139
|
-
async _remoteCall(
|
|
145
|
+
async _remoteCall(channelName, method, args) {
|
|
140
146
|
await this._whenReady();
|
|
141
|
-
const
|
|
142
|
-
return new Promise((
|
|
143
|
-
const
|
|
144
|
-
handle(
|
|
145
|
-
switch (
|
|
147
|
+
const sequence = ++this._lastRequestCounter, request = { seq: sequence, type: 100, channelName, method, args }, client = this;
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
const responseHandler = {
|
|
150
|
+
handle(response) {
|
|
151
|
+
switch (response.type) {
|
|
146
152
|
case 201:
|
|
147
|
-
|
|
153
|
+
client._pendingRequests.delete(sequence), resolve(response.data);
|
|
148
154
|
break;
|
|
149
155
|
case 202:
|
|
150
|
-
|
|
156
|
+
client._pendingRequests.delete(sequence), reject(response.data);
|
|
151
157
|
break;
|
|
152
158
|
default:
|
|
153
159
|
throw new Error("[ChannelClient]: unknown response type!");
|
|
154
160
|
}
|
|
155
161
|
}
|
|
156
162
|
};
|
|
157
|
-
this._pendingRequests.set(
|
|
163
|
+
this._pendingRequests.set(sequence, responseHandler), this._sendRequest(request);
|
|
158
164
|
});
|
|
159
165
|
}
|
|
160
|
-
_remoteSubscribe(
|
|
161
|
-
return new
|
|
162
|
-
let
|
|
166
|
+
_remoteSubscribe(channelName, method, args) {
|
|
167
|
+
return new Observable((subscriber) => {
|
|
168
|
+
let sequence = -1;
|
|
163
169
|
return this._whenReady().then(() => {
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
handle(
|
|
167
|
-
switch (
|
|
170
|
+
sequence = ++this._lastRequestCounter;
|
|
171
|
+
const request = { seq: sequence, type: 101, channelName, method, args }, responseHandler = {
|
|
172
|
+
handle(response) {
|
|
173
|
+
switch (response.type) {
|
|
168
174
|
case 300:
|
|
169
|
-
|
|
175
|
+
subscriber.next(response.data);
|
|
170
176
|
break;
|
|
171
177
|
case 301:
|
|
172
|
-
|
|
178
|
+
subscriber.error(response.data);
|
|
173
179
|
break;
|
|
174
180
|
case 302:
|
|
175
|
-
|
|
181
|
+
subscriber.complete();
|
|
176
182
|
break;
|
|
177
183
|
default:
|
|
178
184
|
throw new Error("[ChannelClient]: unknown response type!");
|
|
179
185
|
}
|
|
180
186
|
}
|
|
181
187
|
};
|
|
182
|
-
this._pendingRequests.set(
|
|
188
|
+
this._pendingRequests.set(sequence, responseHandler), this._sendRequest(request);
|
|
183
189
|
}), () => {
|
|
184
|
-
if (
|
|
190
|
+
if (sequence === -1)
|
|
185
191
|
return;
|
|
186
|
-
const
|
|
192
|
+
const cancelSubscriptionRequest = {
|
|
187
193
|
type: 102,
|
|
188
|
-
seq:
|
|
189
|
-
channelName
|
|
190
|
-
method
|
|
194
|
+
seq: sequence,
|
|
195
|
+
channelName,
|
|
196
|
+
method
|
|
191
197
|
};
|
|
192
|
-
this._sendRequest(
|
|
198
|
+
this._sendRequest(cancelSubscriptionRequest);
|
|
193
199
|
};
|
|
194
200
|
});
|
|
195
201
|
}
|
|
196
|
-
_sendRequest(
|
|
197
|
-
this._protocol.send(
|
|
202
|
+
_sendRequest(request) {
|
|
203
|
+
this._protocol.send(request);
|
|
198
204
|
}
|
|
199
|
-
_onMessage(
|
|
200
|
-
var
|
|
201
|
-
switch (
|
|
205
|
+
_onMessage(response) {
|
|
206
|
+
var _a7;
|
|
207
|
+
switch (response.type) {
|
|
202
208
|
case 0:
|
|
203
209
|
this._initialized.next(!0);
|
|
204
210
|
break;
|
|
@@ -207,37 +213,39 @@ class pe extends j {
|
|
|
207
213
|
case 300:
|
|
208
214
|
case 302:
|
|
209
215
|
case 301:
|
|
210
|
-
(
|
|
216
|
+
(_a7 = this._pendingRequests.get(response.seq)) == null || _a7.handle(response);
|
|
211
217
|
break;
|
|
212
218
|
}
|
|
213
219
|
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
220
|
+
};
|
|
221
|
+
__name(_ChannelClient, "ChannelClient");
|
|
222
|
+
let ChannelClient = _ChannelClient;
|
|
223
|
+
const _ChannelServer = class _ChannelServer extends RxDisposable {
|
|
224
|
+
constructor(_protocol) {
|
|
217
225
|
super();
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
this._protocol =
|
|
226
|
+
__publicField(this, "_channels", /* @__PURE__ */ new Map());
|
|
227
|
+
__publicField(this, "_subscriptions", /* @__PURE__ */ new Map());
|
|
228
|
+
this._protocol = _protocol, this._protocol.onMessage.pipe(takeUntil(this.dispose$)).subscribe((message) => this._onRequest(message)), this._sendInitialize();
|
|
221
229
|
}
|
|
222
230
|
dispose() {
|
|
223
231
|
super.dispose(), this._subscriptions.clear(), this._channels.clear();
|
|
224
232
|
}
|
|
225
|
-
registerChannel(
|
|
226
|
-
this._channels.set(
|
|
233
|
+
registerChannel(channelName, channel) {
|
|
234
|
+
this._channels.set(channelName, channel);
|
|
227
235
|
}
|
|
228
|
-
_onRequest(
|
|
229
|
-
switch (
|
|
236
|
+
_onRequest(request) {
|
|
237
|
+
switch (request.type) {
|
|
230
238
|
case 50:
|
|
231
239
|
this._sendInitialize();
|
|
232
240
|
break;
|
|
233
241
|
case 100:
|
|
234
|
-
this._onMethodCall(
|
|
242
|
+
this._onMethodCall(request);
|
|
235
243
|
break;
|
|
236
244
|
case 101:
|
|
237
|
-
this._onSubscribe(
|
|
245
|
+
this._onSubscribe(request);
|
|
238
246
|
break;
|
|
239
247
|
case 102:
|
|
240
|
-
this._onUnsubscribe(
|
|
248
|
+
this._onUnsubscribe(request);
|
|
241
249
|
break;
|
|
242
250
|
}
|
|
243
251
|
}
|
|
@@ -248,278 +256,283 @@ class ve extends j {
|
|
|
248
256
|
/* INITIALIZE */
|
|
249
257
|
});
|
|
250
258
|
}
|
|
251
|
-
_onMethodCall(
|
|
252
|
-
const { channelName
|
|
253
|
-
let
|
|
259
|
+
_onMethodCall(request) {
|
|
260
|
+
const { channelName, method, args } = request, channel = this._channels.get(channelName);
|
|
261
|
+
let promise;
|
|
254
262
|
try {
|
|
255
|
-
if (!
|
|
256
|
-
throw new Error(`[ChannelServer]: Channel ${
|
|
257
|
-
|
|
258
|
-
} catch (
|
|
259
|
-
|
|
263
|
+
if (!channel)
|
|
264
|
+
throw new Error(`[ChannelServer]: Channel ${channelName} not found!`);
|
|
265
|
+
promise = args ? channel.call(method, args) : channel.call(method);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
promise = Promise.reject(err);
|
|
260
268
|
}
|
|
261
|
-
|
|
262
|
-
this._sendResponse({ seq:
|
|
263
|
-
}).catch((
|
|
264
|
-
|
|
269
|
+
promise.then((data) => {
|
|
270
|
+
this._sendResponse({ seq: request.seq, type: 201, data });
|
|
271
|
+
}).catch((err) => {
|
|
272
|
+
err instanceof Error ? this._sendResponse({ seq: request.seq, type: 202, data: err.message }) : this._sendResponse({ seq: request.seq, type: 202, data: String(err) });
|
|
265
273
|
});
|
|
266
274
|
}
|
|
267
|
-
_onSubscribe(
|
|
268
|
-
const { channelName
|
|
275
|
+
_onSubscribe(request) {
|
|
276
|
+
const { channelName, seq } = request, channel = this._channels.get(channelName);
|
|
269
277
|
try {
|
|
270
|
-
if (!
|
|
271
|
-
throw new Error(`[ChannelServer]: Channel ${
|
|
272
|
-
const
|
|
273
|
-
next: (
|
|
274
|
-
this._sendResponse({ seq
|
|
275
|
-
},
|
|
276
|
-
error: (
|
|
277
|
-
this._sendResponse({ seq
|
|
278
|
-
seq
|
|
278
|
+
if (!channel)
|
|
279
|
+
throw new Error(`[ChannelServer]: Channel ${channelName} not found!`);
|
|
280
|
+
const subscription = channel.subscribe(request.method, request.args).subscribe({
|
|
281
|
+
next: /* @__PURE__ */ __name((data) => {
|
|
282
|
+
this._sendResponse({ seq, type: 300, data });
|
|
283
|
+
}, "next"),
|
|
284
|
+
error: /* @__PURE__ */ __name((err) => {
|
|
285
|
+
this._sendResponse({ seq, type: 301, data: err.message }), this._sendResponse({
|
|
286
|
+
seq,
|
|
279
287
|
type: 302
|
|
280
288
|
/* SUBSCRIBE_COMPLETE */
|
|
281
289
|
});
|
|
282
|
-
},
|
|
283
|
-
complete: () => {
|
|
290
|
+
}, "error"),
|
|
291
|
+
complete: /* @__PURE__ */ __name(() => {
|
|
284
292
|
this._sendResponse({
|
|
285
|
-
seq
|
|
293
|
+
seq,
|
|
286
294
|
type: 302
|
|
287
295
|
/* SUBSCRIBE_COMPLETE */
|
|
288
296
|
});
|
|
289
|
-
}
|
|
297
|
+
}, "complete")
|
|
290
298
|
});
|
|
291
|
-
this._subscriptions.set(
|
|
292
|
-
} catch (
|
|
293
|
-
|
|
299
|
+
this._subscriptions.set(request.seq, subscription);
|
|
300
|
+
} catch (err) {
|
|
301
|
+
err instanceof Error ? this._sendResponse({ seq: request.seq, type: 301, data: err.message }) : this._sendResponse({ seq: request.seq, type: 301, data: String(err) });
|
|
294
302
|
}
|
|
295
303
|
}
|
|
296
|
-
_onUnsubscribe(
|
|
297
|
-
const
|
|
298
|
-
|
|
304
|
+
_onUnsubscribe(request) {
|
|
305
|
+
const subscription = this._subscriptions.get(request.seq);
|
|
306
|
+
subscription && (subscription.unsubscribe(), this._subscriptions.delete(request.seq));
|
|
299
307
|
}
|
|
300
|
-
_sendResponse(
|
|
301
|
-
this._protocol.send(
|
|
308
|
+
_sendResponse(response) {
|
|
309
|
+
this._protocol.send(response);
|
|
302
310
|
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this
|
|
311
|
+
};
|
|
312
|
+
__name(_ChannelServer, "ChannelServer");
|
|
313
|
+
let ChannelServer = _ChannelServer;
|
|
314
|
+
const IRPCChannelService = createIdentifier("IRPCChannelService"), _ChannelService = class _ChannelService {
|
|
315
|
+
constructor(_messageProtocol) {
|
|
316
|
+
__publicField(this, "_client");
|
|
317
|
+
__publicField(this, "_server");
|
|
318
|
+
this._client = new ChannelClient(_messageProtocol), this._server = new ChannelServer(_messageProtocol);
|
|
310
319
|
}
|
|
311
320
|
dispose() {
|
|
312
321
|
this._client.dispose(), this._server.dispose();
|
|
313
322
|
}
|
|
314
|
-
requestChannel(
|
|
315
|
-
return this._client.getChannel(
|
|
323
|
+
requestChannel(name) {
|
|
324
|
+
return this._client.getChannel(name);
|
|
316
325
|
}
|
|
317
|
-
registerChannel(
|
|
318
|
-
this._server.registerChannel(
|
|
326
|
+
registerChannel(name, channel) {
|
|
327
|
+
this._server.registerChannel(name, channel);
|
|
319
328
|
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
329
|
+
};
|
|
330
|
+
__name(_ChannelService, "ChannelService");
|
|
331
|
+
let ChannelService = _ChannelService;
|
|
332
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
333
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
334
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
335
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
336
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a3;
|
|
337
|
+
let DataSyncPrimaryController = (_a3 = class extends RxDisposable {
|
|
338
|
+
constructor(_injector, _commandService, _univerInstanceService, _rpcChannelService, _remoteSyncService) {
|
|
328
339
|
super();
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
this._injector =
|
|
340
|
+
__publicField(this, "_remoteInstanceService");
|
|
341
|
+
__publicField(this, "_syncingUnits", /* @__PURE__ */ new Set());
|
|
342
|
+
__publicField(this, "_syncingMutations", /* @__PURE__ */ new Set());
|
|
343
|
+
this._injector = _injector, this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._rpcChannelService = _rpcChannelService, this._remoteSyncService = _remoteSyncService, this._initRPCChannels(), this._init();
|
|
333
344
|
}
|
|
334
|
-
registerSyncingMutations(
|
|
335
|
-
this._syncingMutations.add(
|
|
345
|
+
registerSyncingMutations(mutation) {
|
|
346
|
+
this._syncingMutations.add(mutation.id);
|
|
336
347
|
}
|
|
337
348
|
/**
|
|
338
349
|
* Only spreadsheets would be synced to the web worker in normal situations. If you would like to
|
|
339
350
|
* sync other types of documents, you should manually call this method with that document's id.
|
|
340
351
|
*/
|
|
341
|
-
syncUnit(
|
|
342
|
-
return this._syncingUnits.add(
|
|
352
|
+
syncUnit(unitId) {
|
|
353
|
+
return this._syncingUnits.add(unitId), toDisposable(() => this._syncingUnits.delete(unitId));
|
|
343
354
|
}
|
|
344
355
|
_initRPCChannels() {
|
|
345
|
-
this._rpcChannelService.registerChannel(
|
|
346
|
-
|
|
347
|
-
{ useFactory: () =>
|
|
348
|
-
]), this._remoteInstanceService = this._injector.get(
|
|
356
|
+
this._rpcChannelService.registerChannel(RemoteSyncServiceName, fromModule(this._remoteSyncService)), this._injector.add([
|
|
357
|
+
IRemoteInstanceService,
|
|
358
|
+
{ useFactory: /* @__PURE__ */ __name(() => toModule(this._rpcChannelService.requestChannel(RemoteInstanceServiceName)), "useFactory") }
|
|
359
|
+
]), this._remoteInstanceService = this._injector.get(IRemoteInstanceService);
|
|
349
360
|
}
|
|
350
361
|
_init() {
|
|
351
|
-
this._univerInstanceService.getTypeOfUnitAdded$(
|
|
352
|
-
this._syncingUnits.add(
|
|
353
|
-
unitID:
|
|
354
|
-
type:
|
|
355
|
-
snapshot:
|
|
362
|
+
this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((sheet) => {
|
|
363
|
+
this._syncingUnits.add(sheet.getUnitId()), this._remoteInstanceService.createInstance({
|
|
364
|
+
unitID: sheet.getUnitId(),
|
|
365
|
+
type: UniverInstanceType.UNIVER_SHEET,
|
|
366
|
+
snapshot: sheet.getSnapshot()
|
|
356
367
|
});
|
|
357
|
-
}), this._univerInstanceService.getTypeOfUnitDisposed$(
|
|
358
|
-
this._syncingUnits.delete(
|
|
359
|
-
unitID:
|
|
368
|
+
}), this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((workbook) => {
|
|
369
|
+
this._syncingUnits.delete(workbook.getUnitId()), this._remoteInstanceService.disposeInstance({
|
|
370
|
+
unitID: workbook.getUnitId()
|
|
360
371
|
});
|
|
361
|
-
}), this.disposeWithMe(this._commandService.onCommandExecuted((
|
|
362
|
-
const { type
|
|
363
|
-
|
|
364
|
-
(!
|
|
365
|
-
!(
|
|
366
|
-
this._syncingMutations.has(
|
|
372
|
+
}), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo, options) => {
|
|
373
|
+
const { type, params, id } = commandInfo, unitId = (params == null ? void 0 : params.unitId) || "";
|
|
374
|
+
type === CommandType.MUTATION && // only sync mutations to the worker thread
|
|
375
|
+
(!unitId || this._syncingUnits.has(unitId)) && // do not sync mutations from the web worker back to the web worker
|
|
376
|
+
!(options != null && options.fromSync) && // do not sync mutations those are not meant to be synced
|
|
377
|
+
this._syncingMutations.has(id) && this._remoteInstanceService.syncMutation({ mutationInfo: commandInfo });
|
|
367
378
|
}));
|
|
368
379
|
}
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
],
|
|
377
|
-
var
|
|
378
|
-
for (var
|
|
379
|
-
(
|
|
380
|
-
return
|
|
381
|
-
},
|
|
382
|
-
let
|
|
383
|
-
constructor(
|
|
380
|
+
}, __name(_a3, "DataSyncPrimaryController"), _a3);
|
|
381
|
+
DataSyncPrimaryController = __decorateClass$2([
|
|
382
|
+
__decorateParam$2(0, Inject(Injector)),
|
|
383
|
+
__decorateParam$2(1, ICommandService),
|
|
384
|
+
__decorateParam$2(2, IUniverInstanceService),
|
|
385
|
+
__decorateParam$2(3, IRPCChannelService),
|
|
386
|
+
__decorateParam$2(4, IRemoteSyncService)
|
|
387
|
+
], DataSyncPrimaryController);
|
|
388
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
389
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
390
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
391
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
392
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a4;
|
|
393
|
+
let DataSyncReplicaController = (_a4 = class extends Disposable {
|
|
394
|
+
constructor(_injector, _remoteInstanceService, _commandService, _rpcChannelService) {
|
|
384
395
|
super();
|
|
385
|
-
|
|
386
|
-
this._injector =
|
|
396
|
+
__publicField(this, "_remoteSyncService");
|
|
397
|
+
this._injector = _injector, this._remoteInstanceService = _remoteInstanceService, this._commandService = _commandService, this._rpcChannelService = _rpcChannelService, this._initRPCChannels(), this._init();
|
|
387
398
|
}
|
|
388
399
|
_initRPCChannels() {
|
|
389
|
-
this._rpcChannelService.registerChannel(
|
|
390
|
-
|
|
391
|
-
{ useFactory: () =>
|
|
392
|
-
]), this._remoteSyncService = this._injector.get(
|
|
400
|
+
this._rpcChannelService.registerChannel(RemoteInstanceServiceName, fromModule(this._remoteInstanceService)), this._injector.add([
|
|
401
|
+
IRemoteSyncService,
|
|
402
|
+
{ useFactory: /* @__PURE__ */ __name(() => toModule(this._rpcChannelService.requestChannel(RemoteSyncServiceName)), "useFactory") }
|
|
403
|
+
]), this._remoteSyncService = this._injector.get(IRemoteSyncService);
|
|
393
404
|
}
|
|
394
405
|
_init() {
|
|
395
406
|
this.disposeWithMe(
|
|
396
407
|
// Mutations executed on the main thread should be synced to the worker thread.
|
|
397
|
-
this._commandService.onCommandExecuted((
|
|
398
|
-
|
|
399
|
-
mutationInfo:
|
|
408
|
+
this._commandService.onCommandExecuted((commandInfo, options) => {
|
|
409
|
+
commandInfo.type === CommandType.MUTATION && !(options != null && options.fromSync) && this._remoteSyncService.syncMutation({
|
|
410
|
+
mutationInfo: commandInfo
|
|
400
411
|
});
|
|
401
412
|
})
|
|
402
413
|
);
|
|
403
414
|
}
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
],
|
|
411
|
-
function
|
|
415
|
+
}, __name(_a4, "DataSyncReplicaController"), _a4);
|
|
416
|
+
DataSyncReplicaController = __decorateClass$1([
|
|
417
|
+
__decorateParam$1(0, Inject(Injector)),
|
|
418
|
+
__decorateParam$1(1, IRemoteInstanceService),
|
|
419
|
+
__decorateParam$1(2, ICommandService),
|
|
420
|
+
__decorateParam$1(3, IRPCChannelService)
|
|
421
|
+
], DataSyncReplicaController);
|
|
422
|
+
function createWebWorkerMessagePortOnWorker() {
|
|
412
423
|
return {
|
|
413
|
-
send(
|
|
414
|
-
postMessage(
|
|
424
|
+
send(message) {
|
|
425
|
+
postMessage(message);
|
|
415
426
|
},
|
|
416
|
-
onMessage: new
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
};
|
|
420
|
-
return addEventListener("message",
|
|
421
|
-
}).pipe(
|
|
427
|
+
onMessage: new Observable((subscriber) => {
|
|
428
|
+
const handler = /* @__PURE__ */ __name((event) => {
|
|
429
|
+
subscriber.next(event.data);
|
|
430
|
+
}, "handler");
|
|
431
|
+
return addEventListener("message", handler), () => removeEventListener("message", handler);
|
|
432
|
+
}).pipe(shareReplay(1))
|
|
422
433
|
};
|
|
423
434
|
}
|
|
424
|
-
|
|
435
|
+
__name(createWebWorkerMessagePortOnWorker, "createWebWorkerMessagePortOnWorker");
|
|
436
|
+
function createWebWorkerMessagePortOnMain(worker) {
|
|
425
437
|
return {
|
|
426
|
-
send(
|
|
427
|
-
|
|
438
|
+
send(message) {
|
|
439
|
+
worker.postMessage(message);
|
|
428
440
|
},
|
|
429
|
-
onMessage: new
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
};
|
|
433
|
-
return
|
|
434
|
-
}).pipe(
|
|
441
|
+
onMessage: new Observable((subscriber) => {
|
|
442
|
+
const handler = /* @__PURE__ */ __name((event) => {
|
|
443
|
+
subscriber.next(event.data);
|
|
444
|
+
}, "handler");
|
|
445
|
+
return worker.addEventListener("message", handler), () => worker.removeEventListener("message", handler);
|
|
446
|
+
}).pipe(shareReplay(1))
|
|
435
447
|
};
|
|
436
448
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
449
|
+
__name(createWebWorkerMessagePortOnMain, "createWebWorkerMessagePortOnMain");
|
|
450
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
451
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
452
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
453
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
454
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a5;
|
|
455
|
+
let UniverRPCMainThreadPlugin = (_a5 = class extends Plugin {
|
|
456
|
+
constructor(_config = defaultPluginMainThreadConfig, _injector, _configService) {
|
|
444
457
|
super();
|
|
445
|
-
|
|
446
|
-
this._config =
|
|
447
|
-
const { ...
|
|
458
|
+
__publicField(this, "_internalWorker", null);
|
|
459
|
+
this._config = _config, this._injector = _injector, this._configService = _configService;
|
|
460
|
+
const { ...rest } = merge(
|
|
448
461
|
{},
|
|
449
|
-
|
|
462
|
+
defaultPluginMainThreadConfig,
|
|
450
463
|
this._config
|
|
451
464
|
);
|
|
452
|
-
this._configService.setConfig(
|
|
465
|
+
this._configService.setConfig(PLUGIN_CONFIG_KEY_MAIN_THREAD, rest);
|
|
453
466
|
}
|
|
454
467
|
dispose() {
|
|
455
468
|
super.dispose(), this._internalWorker && (this._internalWorker.terminate(), this._internalWorker = null);
|
|
456
469
|
}
|
|
457
470
|
onStarting() {
|
|
458
|
-
const { workerURL
|
|
459
|
-
if (!
|
|
471
|
+
const { workerURL } = this._config;
|
|
472
|
+
if (!workerURL)
|
|
460
473
|
throw new Error("[UniverRPCMainThreadPlugin]: The workerURL is required for the RPC main thread plugin.");
|
|
461
|
-
const
|
|
462
|
-
this._internalWorker =
|
|
463
|
-
const
|
|
474
|
+
const worker = workerURL instanceof Worker ? workerURL : new Worker(workerURL);
|
|
475
|
+
this._internalWorker = workerURL instanceof Worker ? null : worker;
|
|
476
|
+
const messageProtocol = createWebWorkerMessagePortOnMain(worker);
|
|
464
477
|
[
|
|
465
478
|
[
|
|
466
|
-
|
|
479
|
+
IRPCChannelService,
|
|
467
480
|
{
|
|
468
|
-
useFactory: () => new
|
|
481
|
+
useFactory: /* @__PURE__ */ __name(() => new ChannelService(messageProtocol), "useFactory")
|
|
469
482
|
}
|
|
470
483
|
],
|
|
471
|
-
[
|
|
472
|
-
[
|
|
473
|
-
].forEach((
|
|
474
|
-
}
|
|
475
|
-
},
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
],
|
|
480
|
-
var
|
|
481
|
-
let
|
|
482
|
-
constructor(
|
|
483
|
-
super(), this._config =
|
|
484
|
-
const { ...
|
|
484
|
+
[DataSyncPrimaryController],
|
|
485
|
+
[IRemoteSyncService, { useClass: RemoteSyncPrimaryService }]
|
|
486
|
+
].forEach((dependency) => this._injector.add(dependency)), this._injector.get(DataSyncPrimaryController);
|
|
487
|
+
}
|
|
488
|
+
}, __name(_a5, "UniverRPCMainThreadPlugin"), __publicField(_a5, "pluginName", "UNIVER_RPC_MAIN_THREAD_PLUGIN"), _a5);
|
|
489
|
+
UniverRPCMainThreadPlugin = __decorateClass([
|
|
490
|
+
__decorateParam(1, Inject(Injector)),
|
|
491
|
+
__decorateParam(2, IConfigService)
|
|
492
|
+
], UniverRPCMainThreadPlugin);
|
|
493
|
+
var _a6;
|
|
494
|
+
let UniverRPCWorkerThreadPlugin = (_a6 = class extends Plugin {
|
|
495
|
+
constructor(_config = defaultPluginWorkerThreadConfig, _injector, _configService) {
|
|
496
|
+
super(), this._config = _config, this._injector = _injector, this._configService = _configService;
|
|
497
|
+
const { ...rest } = merge(
|
|
485
498
|
{},
|
|
486
|
-
|
|
499
|
+
defaultPluginWorkerThreadConfig,
|
|
487
500
|
this._config
|
|
488
501
|
);
|
|
489
|
-
this._configService.setConfig(
|
|
502
|
+
this._configService.setConfig(PLUGIN_CONFIG_KEY_WORKER_THREAD, rest);
|
|
490
503
|
}
|
|
491
504
|
onStarting() {
|
|
492
505
|
[
|
|
493
|
-
[
|
|
506
|
+
[DataSyncReplicaController],
|
|
494
507
|
[
|
|
495
|
-
|
|
508
|
+
IRPCChannelService,
|
|
496
509
|
{
|
|
497
|
-
useFactory: () => new
|
|
510
|
+
useFactory: /* @__PURE__ */ __name(() => new ChannelService(createWebWorkerMessagePortOnWorker()), "useFactory")
|
|
498
511
|
}
|
|
499
512
|
],
|
|
500
|
-
[
|
|
501
|
-
].forEach((
|
|
502
|
-
}
|
|
503
|
-
},
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
],
|
|
513
|
+
[IRemoteInstanceService, { useClass: WebWorkerRemoteInstanceService }]
|
|
514
|
+
].forEach((dependency) => this._injector.add(dependency)), this._injector.get(DataSyncReplicaController);
|
|
515
|
+
}
|
|
516
|
+
}, __name(_a6, "UniverRPCWorkerThreadPlugin"), __publicField(_a6, "pluginName", "UNIVER_RPC_WORKER_THREAD_PLUGIN"), _a6);
|
|
517
|
+
UniverRPCWorkerThreadPlugin = __decorateClass([
|
|
518
|
+
__decorateParam(1, Inject(Injector)),
|
|
519
|
+
__decorateParam(2, IConfigService)
|
|
520
|
+
], UniverRPCWorkerThreadPlugin);
|
|
508
521
|
export {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
522
|
+
ChannelClient,
|
|
523
|
+
ChannelServer,
|
|
524
|
+
ChannelService,
|
|
525
|
+
DataSyncPrimaryController,
|
|
526
|
+
DataSyncReplicaController,
|
|
527
|
+
IRPCChannelService,
|
|
528
|
+
IRemoteInstanceService,
|
|
529
|
+
IRemoteSyncService,
|
|
530
|
+
RemoteInstanceServiceName,
|
|
531
|
+
RemoteSyncPrimaryService,
|
|
532
|
+
RemoteSyncServiceName,
|
|
533
|
+
UniverRPCMainThreadPlugin,
|
|
534
|
+
UniverRPCWorkerThreadPlugin,
|
|
535
|
+
WebWorkerRemoteInstanceService,
|
|
536
|
+
fromModule,
|
|
537
|
+
toModule
|
|
525
538
|
};
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("rxjs/operators"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs/operators","rxjs"],a):(r=typeof globalThis<"u"?globalThis:r||self,a(r.UniverRpc={},r.UniverCore,r.rxjs.operators,r.rxjs))})(this,function(r,a,u,d){"use strict";var x=Object.defineProperty;var ee=(r,a,u)=>a in r?x(r,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[a]=u;var h=(r,a,u)=>ee(r,typeof a!="symbol"?a+"":a,u);var U,E;const N="rpc.main-thread.config",q={},k="rpc.worker-thread.config",W={};var L=Object.defineProperty,H=Object.getOwnPropertyDescriptor,j=(c,t,e,n)=>{for(var s=n>1?void 0:n?H(t,e):t,i=c.length-1,o;i>=0;i--)(o=c[i])&&(s=(n?o(t,e,s):o(s))||s);return n&&s&&L(t,e,s),s},f=(c,t)=>(e,n)=>t(e,n,c);const C="rpc.remote-sync.service",v=a.createIdentifier(C);r.RemoteSyncPrimaryService=class{constructor(t){this._commandService=t}async syncMutation(t){return this._commandService.syncExecuteCommand(t.mutationInfo.id,t.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}},r.RemoteSyncPrimaryService=j([f(0,a.ICommandService)],r.RemoteSyncPrimaryService);const R="univer.remote-instance-service",p=a.createIdentifier(R);r.WebWorkerRemoteInstanceService=class{constructor(t,e,n){this._univerInstanceService=t,this._commandService=e,this._logService=n}whenReady(){return Promise.resolve(!0)}async syncMutation(t){return this._applyMutation(t.mutationInfo)}async createInstance(t){const{type:e,snapshot:n}=t;try{switch(e){case a.UniverInstanceType.UNIVER_SHEET:return this._univerInstanceService.createUnit(a.UniverInstanceType.UNIVER_SHEET,n),!0;default:throw new Error(`[WebWorkerRemoteInstanceService]: cannot create replica for document type: ${e}.`)}}catch(s){throw s instanceof Error?s:new TypeError(`${s}`)}}async disposeInstance(t){return this._univerInstanceService.disposeUnit(t.unitID)}_applyMutation(t){const{id:e,params:n}=t;return this._commandService.syncExecuteCommand(e,n,{onlyLocal:!0,fromSync:!0})}},r.WebWorkerRemoteInstanceService=j([f(0,a.IUniverInstanceService),f(1,a.ICommandService),f(2,a.ILogService)],r.WebWorkerRemoteInstanceService);function b(c){const t=c;return new class{call(e,n){const s=t[e];if(typeof s=="function"){let i=n?s.apply(t,n):s.call(t);return i instanceof Promise||(i=Promise.resolve(i)),i}throw new Error(`[RPC]: method not found for ${e}!`)}subscribe(e,n){const s=t[e];if(typeof s=="function"){const i=n?s.apply(t,n):s.call(t);return d.isObservable(i)?i:d.of(i)}throw new Error(`[RPC]: observable method not found for ${e}!`)}}}function P(c){return new Proxy({},{get(t,e){if(e!=="dispose")return function(...n){return A(e)?c.subscribe(e,n):c.call(e,n)}}})}function A(c){return c.endsWith("$")}class D extends a.RxDisposable{constructor(e){super();h(this,"_initialized",new d.BehaviorSubject(!1));h(this,"_lastRequestCounter",0);h(this,"_pendingRequests",new Map);this._protocol=e,this._protocol.send({type:50}),this._protocol.onMessage.pipe(u.takeUntil(this.dispose$)).subscribe(n=>this._onMessage(n))}dispose(){this._pendingRequests.clear()}getChannel(e){const n=this;return{call(s,i){return n._disposed?Promise.reject():n._remoteCall(e,s,i)},subscribe(s,i){if(n._disposed)throw new Error("[ChannelClient]: client is disposed!");return n._remoteSubscribe(e,s,i)}}}_whenReady(){return d.firstValueFrom(this._initialized.pipe(u.filter(e=>e),u.take(1)))}async _remoteCall(e,n,s){await this._whenReady();const i=++this._lastRequestCounter,_={seq:i,type:100,channelName:e,method:n,args:s},l=this;return new Promise((M,y)=>{const Z={handle(T){switch(T.type){case 201:l._pendingRequests.delete(i),M(T.data);break;case 202:l._pendingRequests.delete(i),y(T.data);break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(i,Z),this._sendRequest(_)})}_remoteSubscribe(e,n,s){return new d.Observable(i=>{let o=-1;return this._whenReady().then(()=>{o=++this._lastRequestCounter;const l={seq:o,type:101,channelName:e,method:n,args:s},M={handle(y){switch(y.type){case 300:i.next(y.data);break;case 301:i.error(y.data);break;case 302:i.complete();break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(o,M),this._sendRequest(l)}),()=>{if(o===-1)return;const _={type:102,seq:o,channelName:e,method:n};this._sendRequest(_)}})}_sendRequest(e){this._protocol.send(e)}_onMessage(e){var n;switch(e.type){case 0:this._initialized.next(!0);break;case 201:case 202:case 300:case 302:case 301:(n=this._pendingRequests.get(e.seq))==null||n.handle(e);break}}}class O extends a.RxDisposable{constructor(e){super();h(this,"_channels",new Map);h(this,"_subscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(u.takeUntil(this.dispose$)).subscribe(n=>this._onRequest(n)),this._sendInitialize()}dispose(){super.dispose(),this._subscriptions.clear(),this._channels.clear()}registerChannel(e,n){this._channels.set(e,n)}_onRequest(e){switch(e.type){case 50:this._sendInitialize();break;case 100:this._onMethodCall(e);break;case 101:this._onSubscribe(e);break;case 102:this._onUnsubscribe(e);break}}_sendInitialize(){this._sendResponse({seq:-1,type:0})}_onMethodCall(e){const{channelName:n,method:s,args:i}=e,o=this._channels.get(n);let _;try{if(!o)throw new Error(`[ChannelServer]: Channel ${n} not found!`);_=i?o.call(s,i):o.call(s)}catch(l){_=Promise.reject(l)}_.then(l=>{this._sendResponse({seq:e.seq,type:201,data:l})}).catch(l=>{l instanceof Error?this._sendResponse({seq:e.seq,type:202,data:l.message}):this._sendResponse({seq:e.seq,type:202,data:String(l)})})}_onSubscribe(e){const{channelName:n,seq:s}=e,i=this._channels.get(n);try{if(!i)throw new Error(`[ChannelServer]: Channel ${n} not found!`);const _=i.subscribe(e.method,e.args).subscribe({next:l=>{this._sendResponse({seq:s,type:300,data:l})},error:l=>{this._sendResponse({seq:s,type:301,data:l.message}),this._sendResponse({seq:s,type:302})},complete:()=>{this._sendResponse({seq:s,type:302})}});this._subscriptions.set(e.seq,_)}catch(o){o instanceof Error?this._sendResponse({seq:e.seq,type:301,data:o.message}):this._sendResponse({seq:e.seq,type:301,data:String(o)})}}_onUnsubscribe(e){const n=this._subscriptions.get(e.seq);n&&(n.unsubscribe(),this._subscriptions.delete(e.seq))}_sendResponse(e){this._protocol.send(e)}}const m=a.createIdentifier("IRPCChannelService");class w{constructor(t){h(this,"_client");h(this,"_server");this._client=new D(t),this._server=new O(t)}dispose(){this._client.dispose(),this._server.dispose()}requestChannel(t){return this._client.getChannel(t)}registerChannel(t,e){this._server.registerChannel(t,e)}}var V=Object.defineProperty,F=Object.getOwnPropertyDescriptor,z=(c,t,e,n)=>{for(var s=n>1?void 0:n?F(t,e):t,i=c.length-1,o;i>=0;i--)(o=c[i])&&(s=(n?o(t,e,s):o(s))||s);return n&&s&&V(t,e,s),s},S=(c,t)=>(e,n)=>t(e,n,c);r.DataSyncPrimaryController=class extends a.RxDisposable{constructor(e,n,s,i,o){super();h(this,"_remoteInstanceService");h(this,"_syncingUnits",new Set);h(this,"_syncingMutations",new Set);this._injector=e,this._commandService=n,this._univerInstanceService=s,this._rpcChannelService=i,this._remoteSyncService=o,this._initRPCChannels(),this._init()}registerSyncingMutations(e){this._syncingMutations.add(e.id)}syncUnit(e){return this._syncingUnits.add(e),a.toDisposable(()=>this._syncingUnits.delete(e))}_initRPCChannels(){this._rpcChannelService.registerChannel(C,b(this._remoteSyncService)),this._injector.add([p,{useFactory:()=>P(this._rpcChannelService.requestChannel(R))}]),this._remoteInstanceService=this._injector.get(p)}_init(){this._univerInstanceService.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(u.takeUntil(this.dispose$)).subscribe(e=>{this._syncingUnits.add(e.getUnitId()),this._remoteInstanceService.createInstance({unitID:e.getUnitId(),type:a.UniverInstanceType.UNIVER_SHEET,snapshot:e.getSnapshot()})}),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(u.takeUntil(this.dispose$)).subscribe(e=>{this._syncingUnits.delete(e.getUnitId()),this._remoteInstanceService.disposeInstance({unitID:e.getUnitId()})}),this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{const{type:s,params:i,id:o}=e,_=(i==null?void 0:i.unitId)||"";s===a.CommandType.MUTATION&&(!_||this._syncingUnits.has(_))&&!(n!=null&&n.fromSync)&&this._syncingMutations.has(o)&&this._remoteInstanceService.syncMutation({mutationInfo:e})}))}},r.DataSyncPrimaryController=z([S(0,a.Inject(a.Injector)),S(1,a.ICommandService),S(2,a.IUniverInstanceService),S(3,m),S(4,v)],r.DataSyncPrimaryController);var G=Object.defineProperty,Y=Object.getOwnPropertyDescriptor,B=(c,t,e,n)=>{for(var s=n>1?void 0:n?Y(t,e):t,i=c.length-1,o;i>=0;i--)(o=c[i])&&(s=(n?o(t,e,s):o(s))||s);return n&&s&&G(t,e,s),s},g=(c,t)=>(e,n)=>t(e,n,c);r.DataSyncReplicaController=class extends a.Disposable{constructor(e,n,s,i){super();h(this,"_remoteSyncService");this._injector=e,this._remoteInstanceService=n,this._commandService=s,this._rpcChannelService=i,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(R,b(this._remoteInstanceService)),this._injector.add([v,{useFactory:()=>P(this._rpcChannelService.requestChannel(C))}]),this._remoteSyncService=this._injector.get(v)}_init(){this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{e.type===a.CommandType.MUTATION&&!(n!=null&&n.fromSync)&&this._remoteSyncService.syncMutation({mutationInfo:e})}))}},r.DataSyncReplicaController=B([g(0,a.Inject(a.Injector)),g(1,p),g(2,a.ICommandService),g(3,m)],r.DataSyncReplicaController);function K(){return{send(c){postMessage(c)},onMessage:new d.Observable(c=>{const t=e=>{c.next(e.data)};return addEventListener("message",t),()=>removeEventListener("message",t)}).pipe(d.shareReplay(1))}}function J(c){return{send(t){c.postMessage(t)},onMessage:new d.Observable(t=>{const e=n=>{t.next(n.data)};return c.addEventListener("message",e),()=>c.removeEventListener("message",e)}).pipe(d.shareReplay(1))}}var Q=Object.defineProperty,X=Object.getOwnPropertyDescriptor,$=(c,t,e,n)=>{for(var s=n>1?void 0:n?X(t,e):t,i=c.length-1,o;i>=0;i--)(o=c[i])&&(s=(n?o(t,e,s):o(s))||s);return n&&s&&Q(t,e,s),s},I=(c,t)=>(e,n)=>t(e,n,c);r.UniverRPCMainThreadPlugin=(U=class extends a.Plugin{constructor(e=q,n,s){super();h(this,"_internalWorker",null);this._config=e,this._injector=n,this._configService=s;const{...i}=a.merge({},q,this._config);this._configService.setConfig(N,i)}dispose(){super.dispose(),this._internalWorker&&(this._internalWorker.terminate(),this._internalWorker=null)}onStarting(){const{workerURL:e}=this._config;if(!e)throw new Error("[UniverRPCMainThreadPlugin]: The workerURL is required for the RPC main thread plugin.");const n=e instanceof Worker?e:new Worker(e);this._internalWorker=e instanceof Worker?null:n;const s=J(n);[[m,{useFactory:()=>new w(s)}],[r.DataSyncPrimaryController],[v,{useClass:r.RemoteSyncPrimaryService}]].forEach(o=>this._injector.add(o)),this._injector.get(r.DataSyncPrimaryController)}},h(U,"pluginName","UNIVER_RPC_MAIN_THREAD_PLUGIN"),U),r.UniverRPCMainThreadPlugin=$([I(1,a.Inject(a.Injector)),I(2,a.IConfigService)],r.UniverRPCMainThreadPlugin),r.UniverRPCWorkerThreadPlugin=(E=class extends a.Plugin{constructor(t=W,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...s}=a.merge({},W,this._config);this._configService.setConfig(k,s)}onStarting(){[[r.DataSyncReplicaController],[m,{useFactory:()=>new w(K())}],[p,{useClass:r.WebWorkerRemoteInstanceService}]].forEach(t=>this._injector.add(t)),this._injector.get(r.DataSyncReplicaController)}},h(E,"pluginName","UNIVER_RPC_WORKER_THREAD_PLUGIN"),E),r.UniverRPCWorkerThreadPlugin=$([I(1,a.Inject(a.Injector)),I(2,a.IConfigService)],r.UniverRPCWorkerThreadPlugin),r.ChannelClient=D,r.ChannelServer=O,r.ChannelService=w,r.IRPCChannelService=m,r.IRemoteInstanceService=p,r.IRemoteSyncService=v,r.RemoteInstanceServiceName=R,r.RemoteSyncServiceName=C,r.fromModule=b,r.toModule=P,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("rxjs/operators"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs/operators","rxjs"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverRpc={},global.UniverCore,global.rxjs.operators,global.rxjs))})(this,function(exports2,core,operators,rxjs){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e,_f;const PLUGIN_CONFIG_KEY_MAIN_THREAD="rpc.main-thread.config",defaultPluginMainThreadConfig={},PLUGIN_CONFIG_KEY_WORKER_THREAD="rpc.worker-thread.config",defaultPluginWorkerThreadConfig={};var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");const RemoteSyncServiceName="rpc.remote-sync.service",IRemoteSyncService=core.createIdentifier(RemoteSyncServiceName);exports2.RemoteSyncPrimaryService=(_a=class{constructor(_commandService){this._commandService=_commandService}async syncMutation(params){return this._commandService.syncExecuteCommand(params.mutationInfo.id,params.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}},__name(_a,"RemoteSyncPrimaryService"),_a),exports2.RemoteSyncPrimaryService=__decorateClass$3([__decorateParam$3(0,core.ICommandService)],exports2.RemoteSyncPrimaryService);const RemoteInstanceServiceName="univer.remote-instance-service",IRemoteInstanceService=core.createIdentifier(RemoteInstanceServiceName);exports2.WebWorkerRemoteInstanceService=(_b=class{constructor(_univerInstanceService,_commandService,_logService){this._univerInstanceService=_univerInstanceService,this._commandService=_commandService,this._logService=_logService}whenReady(){return Promise.resolve(!0)}async syncMutation(params){return this._applyMutation(params.mutationInfo)}async createInstance(params){const{type,snapshot}=params;try{switch(type){case core.UniverInstanceType.UNIVER_SHEET:return this._univerInstanceService.createUnit(core.UniverInstanceType.UNIVER_SHEET,snapshot),!0;default:throw new Error(`[WebWorkerRemoteInstanceService]: cannot create replica for document type: ${type}.`)}}catch(err){throw err instanceof Error?err:new TypeError(`${err}`)}}async disposeInstance(params){return this._univerInstanceService.disposeUnit(params.unitID)}_applyMutation(mutationInfo){const{id,params:mutationParams}=mutationInfo;return this._commandService.syncExecuteCommand(id,mutationParams,{onlyLocal:!0,fromSync:!0})}},__name(_b,"WebWorkerRemoteInstanceService"),_b),exports2.WebWorkerRemoteInstanceService=__decorateClass$3([__decorateParam$3(0,core.IUniverInstanceService),__decorateParam$3(1,core.ICommandService),__decorateParam$3(2,core.ILogService)],exports2.WebWorkerRemoteInstanceService);function fromModule(module2){const handler=module2;return new class{call(method,args){const target=handler[method];if(typeof target=="function"){let res=args?target.apply(handler,args):target.call(handler);return res instanceof Promise||(res=Promise.resolve(res)),res}throw new Error(`[RPC]: method not found for ${method}!`)}subscribe(eventMethod,args){const target=handler[eventMethod];if(typeof target=="function"){const res=args?target.apply(handler,args):target.call(handler);return rxjs.isObservable(res)?res:rxjs.of(res)}throw new Error(`[RPC]: observable method not found for ${eventMethod}!`)}}}__name(fromModule,"fromModule");function toModule(channel){return new Proxy({},{get(_,propKey){if(propKey!=="dispose")return function(...args){return propertyIsEventSource(propKey)?channel.subscribe(propKey,args):channel.call(propKey,args)}}})}__name(toModule,"toModule");function propertyIsEventSource(name){return name.endsWith("$")}__name(propertyIsEventSource,"propertyIsEventSource");const _ChannelClient=class _ChannelClient extends core.RxDisposable{constructor(_protocol){super();__publicField(this,"_initialized",new rxjs.BehaviorSubject(!1));__publicField(this,"_lastRequestCounter",0);__publicField(this,"_pendingRequests",new Map);this._protocol=_protocol,this._protocol.send({type:50}),this._protocol.onMessage.pipe(operators.takeUntil(this.dispose$)).subscribe(message=>this._onMessage(message))}dispose(){this._pendingRequests.clear()}getChannel(channelName){const self2=this;return{call(method,args){return self2._disposed?Promise.reject():self2._remoteCall(channelName,method,args)},subscribe(eventMethod,args){if(self2._disposed)throw new Error("[ChannelClient]: client is disposed!");return self2._remoteSubscribe(channelName,eventMethod,args)}}}_whenReady(){return rxjs.firstValueFrom(this._initialized.pipe(operators.filter(v=>v),operators.take(1)))}async _remoteCall(channelName,method,args){await this._whenReady();const sequence=++this._lastRequestCounter,request={seq:sequence,type:100,channelName,method,args},client=this;return new Promise((resolve,reject)=>{const responseHandler={handle(response){switch(response.type){case 201:client._pendingRequests.delete(sequence),resolve(response.data);break;case 202:client._pendingRequests.delete(sequence),reject(response.data);break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(sequence,responseHandler),this._sendRequest(request)})}_remoteSubscribe(channelName,method,args){return new rxjs.Observable(subscriber=>{let sequence=-1;return this._whenReady().then(()=>{sequence=++this._lastRequestCounter;const request={seq:sequence,type:101,channelName,method,args},responseHandler={handle(response){switch(response.type){case 300:subscriber.next(response.data);break;case 301:subscriber.error(response.data);break;case 302:subscriber.complete();break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(sequence,responseHandler),this._sendRequest(request)}),()=>{if(sequence===-1)return;const cancelSubscriptionRequest={type:102,seq:sequence,channelName,method};this._sendRequest(cancelSubscriptionRequest)}})}_sendRequest(request){this._protocol.send(request)}_onMessage(response){var _a2;switch(response.type){case 0:this._initialized.next(!0);break;case 201:case 202:case 300:case 302:case 301:(_a2=this._pendingRequests.get(response.seq))==null||_a2.handle(response);break}}};__name(_ChannelClient,"ChannelClient");let ChannelClient=_ChannelClient;const _ChannelServer=class _ChannelServer extends core.RxDisposable{constructor(_protocol){super();__publicField(this,"_channels",new Map);__publicField(this,"_subscriptions",new Map);this._protocol=_protocol,this._protocol.onMessage.pipe(operators.takeUntil(this.dispose$)).subscribe(message=>this._onRequest(message)),this._sendInitialize()}dispose(){super.dispose(),this._subscriptions.clear(),this._channels.clear()}registerChannel(channelName,channel){this._channels.set(channelName,channel)}_onRequest(request){switch(request.type){case 50:this._sendInitialize();break;case 100:this._onMethodCall(request);break;case 101:this._onSubscribe(request);break;case 102:this._onUnsubscribe(request);break}}_sendInitialize(){this._sendResponse({seq:-1,type:0})}_onMethodCall(request){const{channelName,method,args}=request,channel=this._channels.get(channelName);let promise;try{if(!channel)throw new Error(`[ChannelServer]: Channel ${channelName} not found!`);promise=args?channel.call(method,args):channel.call(method)}catch(err){promise=Promise.reject(err)}promise.then(data=>{this._sendResponse({seq:request.seq,type:201,data})}).catch(err=>{err instanceof Error?this._sendResponse({seq:request.seq,type:202,data:err.message}):this._sendResponse({seq:request.seq,type:202,data:String(err)})})}_onSubscribe(request){const{channelName,seq}=request,channel=this._channels.get(channelName);try{if(!channel)throw new Error(`[ChannelServer]: Channel ${channelName} not found!`);const subscription=channel.subscribe(request.method,request.args).subscribe({next:__name(data=>{this._sendResponse({seq,type:300,data})},"next"),error:__name(err=>{this._sendResponse({seq,type:301,data:err.message}),this._sendResponse({seq,type:302})},"error"),complete:__name(()=>{this._sendResponse({seq,type:302})},"complete")});this._subscriptions.set(request.seq,subscription)}catch(err){err instanceof Error?this._sendResponse({seq:request.seq,type:301,data:err.message}):this._sendResponse({seq:request.seq,type:301,data:String(err)})}}_onUnsubscribe(request){const subscription=this._subscriptions.get(request.seq);subscription&&(subscription.unsubscribe(),this._subscriptions.delete(request.seq))}_sendResponse(response){this._protocol.send(response)}};__name(_ChannelServer,"ChannelServer");let ChannelServer=_ChannelServer;const IRPCChannelService=core.createIdentifier("IRPCChannelService"),_ChannelService=class _ChannelService{constructor(_messageProtocol){__publicField(this,"_client");__publicField(this,"_server");this._client=new ChannelClient(_messageProtocol),this._server=new ChannelServer(_messageProtocol)}dispose(){this._client.dispose(),this._server.dispose()}requestChannel(name){return this._client.getChannel(name)}registerChannel(name,channel){this._server.registerChannel(name,channel)}};__name(_ChannelService,"ChannelService");let ChannelService=_ChannelService;var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");exports2.DataSyncPrimaryController=(_c=class extends core.RxDisposable{constructor(_injector,_commandService,_univerInstanceService,_rpcChannelService,_remoteSyncService){super();__publicField(this,"_remoteInstanceService");__publicField(this,"_syncingUnits",new Set);__publicField(this,"_syncingMutations",new Set);this._injector=_injector,this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._rpcChannelService=_rpcChannelService,this._remoteSyncService=_remoteSyncService,this._initRPCChannels(),this._init()}registerSyncingMutations(mutation){this._syncingMutations.add(mutation.id)}syncUnit(unitId){return this._syncingUnits.add(unitId),core.toDisposable(()=>this._syncingUnits.delete(unitId))}_initRPCChannels(){this._rpcChannelService.registerChannel(RemoteSyncServiceName,fromModule(this._remoteSyncService)),this._injector.add([IRemoteInstanceService,{useFactory:__name(()=>toModule(this._rpcChannelService.requestChannel(RemoteInstanceServiceName)),"useFactory")}]),this._remoteInstanceService=this._injector.get(IRemoteInstanceService)}_init(){this._univerInstanceService.getTypeOfUnitAdded$(core.UniverInstanceType.UNIVER_SHEET).pipe(operators.takeUntil(this.dispose$)).subscribe(sheet=>{this._syncingUnits.add(sheet.getUnitId()),this._remoteInstanceService.createInstance({unitID:sheet.getUnitId(),type:core.UniverInstanceType.UNIVER_SHEET,snapshot:sheet.getSnapshot()})}),this._univerInstanceService.getTypeOfUnitDisposed$(core.UniverInstanceType.UNIVER_SHEET).pipe(operators.takeUntil(this.dispose$)).subscribe(workbook=>{this._syncingUnits.delete(workbook.getUnitId()),this._remoteInstanceService.disposeInstance({unitID:workbook.getUnitId()})}),this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo,options)=>{const{type,params,id}=commandInfo,unitId=(params==null?void 0:params.unitId)||"";type===core.CommandType.MUTATION&&(!unitId||this._syncingUnits.has(unitId))&&!(options!=null&&options.fromSync)&&this._syncingMutations.has(id)&&this._remoteInstanceService.syncMutation({mutationInfo:commandInfo})}))}},__name(_c,"DataSyncPrimaryController"),_c),exports2.DataSyncPrimaryController=__decorateClass$2([__decorateParam$2(0,core.Inject(core.Injector)),__decorateParam$2(1,core.ICommandService),__decorateParam$2(2,core.IUniverInstanceService),__decorateParam$2(3,IRPCChannelService),__decorateParam$2(4,IRemoteSyncService)],exports2.DataSyncPrimaryController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");exports2.DataSyncReplicaController=(_d=class extends core.Disposable{constructor(_injector,_remoteInstanceService,_commandService,_rpcChannelService){super();__publicField(this,"_remoteSyncService");this._injector=_injector,this._remoteInstanceService=_remoteInstanceService,this._commandService=_commandService,this._rpcChannelService=_rpcChannelService,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(RemoteInstanceServiceName,fromModule(this._remoteInstanceService)),this._injector.add([IRemoteSyncService,{useFactory:__name(()=>toModule(this._rpcChannelService.requestChannel(RemoteSyncServiceName)),"useFactory")}]),this._remoteSyncService=this._injector.get(IRemoteSyncService)}_init(){this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo,options)=>{commandInfo.type===core.CommandType.MUTATION&&!(options!=null&&options.fromSync)&&this._remoteSyncService.syncMutation({mutationInfo:commandInfo})}))}},__name(_d,"DataSyncReplicaController"),_d),exports2.DataSyncReplicaController=__decorateClass$1([__decorateParam$1(0,core.Inject(core.Injector)),__decorateParam$1(1,IRemoteInstanceService),__decorateParam$1(2,core.ICommandService),__decorateParam$1(3,IRPCChannelService)],exports2.DataSyncReplicaController);function createWebWorkerMessagePortOnWorker(){return{send(message){postMessage(message)},onMessage:new rxjs.Observable(subscriber=>{const handler=__name(event=>{subscriber.next(event.data)},"handler");return addEventListener("message",handler),()=>removeEventListener("message",handler)}).pipe(rxjs.shareReplay(1))}}__name(createWebWorkerMessagePortOnWorker,"createWebWorkerMessagePortOnWorker");function createWebWorkerMessagePortOnMain(worker){return{send(message){worker.postMessage(message)},onMessage:new rxjs.Observable(subscriber=>{const handler=__name(event=>{subscriber.next(event.data)},"handler");return worker.addEventListener("message",handler),()=>worker.removeEventListener("message",handler)}).pipe(rxjs.shareReplay(1))}}__name(createWebWorkerMessagePortOnMain,"createWebWorkerMessagePortOnMain");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");exports2.UniverRPCMainThreadPlugin=(_e=class extends core.Plugin{constructor(_config=defaultPluginMainThreadConfig,_injector,_configService){super();__publicField(this,"_internalWorker",null);this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=core.merge({},defaultPluginMainThreadConfig,this._config);this._configService.setConfig(PLUGIN_CONFIG_KEY_MAIN_THREAD,rest)}dispose(){super.dispose(),this._internalWorker&&(this._internalWorker.terminate(),this._internalWorker=null)}onStarting(){const{workerURL}=this._config;if(!workerURL)throw new Error("[UniverRPCMainThreadPlugin]: The workerURL is required for the RPC main thread plugin.");const worker=workerURL instanceof Worker?workerURL:new Worker(workerURL);this._internalWorker=workerURL instanceof Worker?null:worker;const messageProtocol=createWebWorkerMessagePortOnMain(worker);[[IRPCChannelService,{useFactory:__name(()=>new ChannelService(messageProtocol),"useFactory")}],[exports2.DataSyncPrimaryController],[IRemoteSyncService,{useClass:exports2.RemoteSyncPrimaryService}]].forEach(dependency=>this._injector.add(dependency)),this._injector.get(exports2.DataSyncPrimaryController)}},__name(_e,"UniverRPCMainThreadPlugin"),__publicField(_e,"pluginName","UNIVER_RPC_MAIN_THREAD_PLUGIN"),_e),exports2.UniverRPCMainThreadPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverRPCMainThreadPlugin),exports2.UniverRPCWorkerThreadPlugin=(_f=class extends core.Plugin{constructor(_config=defaultPluginWorkerThreadConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=core.merge({},defaultPluginWorkerThreadConfig,this._config);this._configService.setConfig(PLUGIN_CONFIG_KEY_WORKER_THREAD,rest)}onStarting(){[[exports2.DataSyncReplicaController],[IRPCChannelService,{useFactory:__name(()=>new ChannelService(createWebWorkerMessagePortOnWorker()),"useFactory")}],[IRemoteInstanceService,{useClass:exports2.WebWorkerRemoteInstanceService}]].forEach(dependency=>this._injector.add(dependency)),this._injector.get(exports2.DataSyncReplicaController)}},__name(_f,"UniverRPCWorkerThreadPlugin"),__publicField(_f,"pluginName","UNIVER_RPC_WORKER_THREAD_PLUGIN"),_f),exports2.UniverRPCWorkerThreadPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverRPCWorkerThreadPlugin),exports2.ChannelClient=ChannelClient,exports2.ChannelServer=ChannelServer,exports2.ChannelService=ChannelService,exports2.IRPCChannelService=IRPCChannelService,exports2.IRemoteInstanceService=IRemoteInstanceService,exports2.IRemoteSyncService=IRemoteSyncService,exports2.RemoteInstanceServiceName=RemoteInstanceServiceName,exports2.RemoteSyncServiceName=RemoteSyncServiceName,exports2.fromModule=fromModule,exports2.toModule=toModule,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/rpc",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5-experimental.20250123-34738ff",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"rxjs": ">=7.0.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@univerjs/core": "0.5.
|
|
50
|
+
"@univerjs/core": "0.5.5-experimental.20250123-34738ff"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"rxjs": "^7.8.1",
|
|
54
|
-
"typescript": "^5.7.
|
|
54
|
+
"typescript": "^5.7.3",
|
|
55
55
|
"vite": "^6.0.7",
|
|
56
56
|
"vitest": "^2.1.8",
|
|
57
|
-
"@univerjs-infra/shared": "0.5.
|
|
57
|
+
"@univerjs-infra/shared": "0.5.5"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2023-present DreamNum Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
export {};
|