@univerjs/rpc
Advanced tools
Comparing version 0.1.0-beta.2 to 0.1.0-beta.3
@@ -1,1 +0,1 @@ | ||
"use strict";var A=Object.defineProperty;var H=(r,n,e)=>n in r?A(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e;var h=(r,n,e)=>(H(r,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),l=require("@wendellhu/redi"),d=require("rxjs/operators"),_=require("rxjs");var F=Object.defineProperty,k=Object.getOwnPropertyDescriptor,O=(r,n,e,t)=>{for(var s=t>1?void 0:t?k(n,e):n,i=r.length-1,c;i>=0;i--)(c=r[i])&&(s=(t?c(n,e,s):c(s))||s);return t&&s&&F(n,e,s),s},w=(r,n)=>(e,t)=>n(e,t,r);const E="univer.remote-sync-service",C=l.createIdentifier(E);let U=class{constructor(r){this._commandService=r}async syncMutation(r){return this._commandService.syncExecuteCommand(r.mutationInfo.id,r.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}};U=O([w(0,a.ICommandService)],U);const M="univer.remote-instance-service",S=l.createIdentifier(M);let q=class{constructor(r,n){this._univerInstanceService=r,this._commandService=n}whenReady(){return Promise.resolve(!0)}async syncMutation(r){return this._commandService.syncExecuteCommand(r.mutationInfo.id,r.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}async createInstance(r){const{type:n,snapshot:e}=r;try{switch(n){case a.UniverInstanceType.SHEET:return!!this._univerInstanceService.createSheet(e);default:throw new Error(`[RemoteInstanceReplicaService]: cannot create replica for document type: ${n}.`)}}catch(t){throw t instanceof Error?t:new Error(`${t}`)}}async disposeInstance(r){return this._univerInstanceService.disposeDocument(r.unitID)}};q=O([w(0,a.IUniverInstanceService),w(1,a.ICommandService)],q);function j(r){const n=r;return new class{call(e,t){const s=n[e];if(typeof s=="function"){let i=s.apply(n,[t]);return i instanceof Promise||(i=Promise.resolve(i)),i}throw new Error(`[RPC]: method not found for ${e}!`)}subscribe(e,t){const s=n[e];if(typeof s=="function"){const i=s.apply(n,t);return _.isObservable(i)?i:_.of(i)}throw new Error(`[RPC]: observable method not found for ${e}!`)}}}function $(r){return new Proxy({},{get(n,e){return function(...t){return z(e)?r.subscribe(e,t[0]):r.call(e,t[0])}}})}function z(r){return r.endsWith("$")}class T extends a.RxDisposable{constructor(e){super();h(this,"_initialized",new _.BehaviorSubject(!1));h(this,"_lastRequestCounter",0);h(this,"_pendingRequests",new Map);h(this,"_pendingSubscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(d.takeUntil(this.dispose$)).subscribe(t=>this._onMessage(t))}getChannel(e){const t=this;return{call(s,i){return t._disposed?Promise.reject():t._remoteCall(e,s,i)},subscribe(s,i){if(t._disposed)throw new Error("[ChannelClient]: client is disposed!");return t._remoteSubscribe(e,s,i)}}}_whenReady(){return _.firstValueFrom(this._initialized.pipe(d.filter(e=>e),d.take(1)))}async _remoteCall(e,t,s){await this._whenReady();const i=++this._lastRequestCounter,u={seq:i,type:100,channelName:e,method:t,args:s},o=this;return new Promise((g,p)=>{const N={handle(R){switch(R.type){case 201:o._pendingRequests.delete(i),g(R.data);break;case 202:o._pendingRequests.delete(i),p(R.data);break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(i,N),this._sendRequest(u)})}_remoteSubscribe(e,t,s){return new _.Observable(i=>{let c=-1;return this._whenReady().then(()=>{c=++this._lastRequestCounter;const o={seq:c,type:101,channelName:e,method:t,args:s},g={handle(p){switch(p.type){case 300:i.next(p.data);break;case 301:i.error(p.data);break;case 302:i.complete();break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(c,g),this._sendRequest(o)}),()=>{if(c===-1)return;const u={type:102,seq:c,channelName:e,method:t};this._sendRequest(u)}})}_sendRequest(e){this._protocol.send(e)}_onMessage(e){var t;switch(e.type){case 0:this._initialized.next(!0);break;case 201:case 202:case 300:case 302:case 301:(t=this._pendingRequests.get(e.seq))==null||t.handle(e);break}}}class D extends a.RxDisposable{constructor(e){super();h(this,"_channels",new Map);h(this,"_subscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(d.takeUntil(this.dispose$)).subscribe(t=>this._onRequest(t)),this._sendResponse({seq:-1,type:0})}registerChannel(e,t){this._channels.set(e,t)}_onRequest(e){switch(e.type){case 100:this._onMethodCall(e);break;case 101:this._onSubscribe(e);break;case 102:this._onUnsubscribe(e);break}}_onMethodCall(e){const{channelName:t,method:s,args:i}=e,c=this._channels.get(t);let u;try{if(!c)throw new Error(`[ChannelServer]: Channel ${t} not found!`);u=c.call(s,i)}catch(o){u=Promise.reject(o)}u.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:t,seq:s}=e,i=this._channels.get(t);try{if(!i)throw new Error(`[ChannelServer]: Channel ${t} not found!`);const u=i.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,u)}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 t=this._subscriptions.get(e.seq);t&&(t.unsubscribe(),this._subscriptions.delete(e.seq))}_sendResponse(e){this._protocol.send(e)}}const f=l.createIdentifier("IRPChannelService");class x{constructor(n){h(this,"_client");h(this,"_server");this._client=new T(n),this._server=new D(n)}requestChannel(n){return this._client.getChannel(n)}registerChannel(n,e){this._server.registerChannel(n,e)}}var V=Object.defineProperty,G=Object.getOwnPropertyDescriptor,B=(r,n,e,t)=>{for(var s=t>1?void 0:t?G(n,e):n,i=r.length-1,c;i>=0;i--)(c=r[i])&&(s=(t?c(n,e,s):c(s))||s);return t&&s&&V(n,e,s),s},v=(r,n)=>(e,t)=>n(e,t,r);let m=class extends a.RxDisposable{constructor(n,e,t,s,i){super();h(this,"_remoteInstanceService");h(this,"_syncingUnits",new Set);this._injector=n,this._commandService=e,this._univerInstanceService=t,this._rpcChannelService=s,this._remoteSyncService=i,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(E,j(this._remoteSyncService)),this._injector.add([S,{useFactory:()=>$(this._rpcChannelService.requestChannel(M))}]),this._remoteInstanceService=this._injector.get(S)}_init(){this._univerInstanceService.sheetAdded$.pipe(d.takeUntil(this.dispose$)).subscribe(n=>{this._syncingUnits.add(n.getUnitId()),this._remoteInstanceService.createInstance({unitID:n.getUnitId(),type:a.UniverInstanceType.SHEET,snapshot:n.getSnapshot()})}),this._univerInstanceService.sheetDisposed$.pipe(d.takeUntil(this.dispose$)).subscribe(n=>{this._syncingUnits.delete(n.getUnitId()),this._remoteInstanceService.disposeInstance({unitID:n.getUnitId()})}),this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{const{type:t,params:s}=n,i=(s==null?void 0:s.unitId)||"";t===a.CommandType.MUTATION&&(!i||this._syncingUnits.has(i))&&!(e!=null&&e.fromSync)&&this._remoteInstanceService.syncMutation({mutationInfo:n})}))}};m=B([a.OnLifecycle(a.LifecycleStages.Starting,m),v(0,l.Inject(l.Injector)),v(1,a.ICommandService),v(2,a.IUniverInstanceService),v(3,f),v(4,C)],m);var J=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,X=(r,n,e,t)=>{for(var s=t>1?void 0:t?Q(n,e):n,i=r.length-1,c;i>=0;i--)(c=r[i])&&(s=(t?c(n,e,s):c(s))||s);return t&&s&&J(n,e,s),s},b=(r,n)=>(e,t)=>n(e,t,r);let y=class extends a.Disposable{constructor(n,e,t,s){super();h(this,"_remoteSyncService");this._injector=n,this._remoteInstanceService=e,this._commandService=t,this._rpcChannelService=s,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(M,j(this._remoteInstanceService)),this._injector.add([C,{useFactory:()=>$(this._rpcChannelService.requestChannel(E))}]),this._remoteSyncService=this._injector.get(C)}_init(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{n.type===a.CommandType.MUTATION&&!(e!=null&&e.fromSync)&&this._remoteSyncService.syncMutation({mutationInfo:n})}))}};y=X([a.OnLifecycle(a.LifecycleStages.Starting,y),b(0,l.Inject(l.Injector)),b(1,S),b(2,a.ICommandService),b(3,f)],y);function Y(){return{send(r){postMessage(r)},onMessage:new _.Observable(r=>{const n=e=>{r.next(e.data)};return addEventListener("message",n),()=>removeEventListener("message",n)}).pipe(_.shareReplay(1))}}function Z(r){return{send(n){r.postMessage(n)},onMessage:new _.Observable(n=>{const e=t=>{n.next(t.data)};return r.addEventListener("message",e),()=>r.removeEventListener("message",e)}).pipe(_.shareReplay(1))}}var K=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,W=(r,n,e,t)=>{for(var s=t>1?void 0:t?ee(n,e):n,i=r.length-1,c;i>=0;i--)(c=r[i])&&(s=(t?c(n,e,s):c(s))||s);return t&&s&&K(n,e,s),s},L=(r,n)=>(e,t)=>n(e,t,r),I;exports.UniverRPCMainThreadPlugin=(I=class extends a.Plugin{constructor(n,e){super("UNIVER_RPC_MAIN_THREAD_PLUGIN"),this._config=n,this._injector=e}async onStarting(n){const{workerURL:e}=this._config,t=e instanceof Worker?e:new Worker(e),s=Z(t);[[f,{useFactory:()=>new x(s)}],[m],[C,{useClass:U}]].forEach(c=>n.add(c)),n.get(m)}},h(I,"type",a.PluginType.Univer),I);exports.UniverRPCMainThreadPlugin=W([L(1,l.Inject(l.Injector))],exports.UniverRPCMainThreadPlugin);var P;exports.UniverRPCWorkerThreadPlugin=(P=class extends a.Plugin{constructor(n,e){super("UNIVER_RPC_WORKER_THREAD_PLUGIN"),this._config=n,this._injector=e}onStarting(n){[[y],[f,{useFactory:()=>new x(Y())}],[S,{useClass:q}]].forEach(e=>n.add(e)),n.get(y)}},h(P,"type",a.PluginType.Univer),P);exports.UniverRPCWorkerThreadPlugin=W([L(1,l.Inject(l.Injector))],exports.UniverRPCWorkerThreadPlugin);exports.ChannelClient=T;exports.ChannelServer=D;exports.IRPChannelService=f;exports.IRemoteInstanceService=S; | ||
"use strict";var A=Object.defineProperty;var H=(r,n,e)=>n in r?A(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e;var h=(r,n,e)=>(H(r,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),l=require("@wendellhu/redi"),d=require("rxjs/operators"),_=require("rxjs");var F=Object.defineProperty,k=Object.getOwnPropertyDescriptor,O=(r,n,e,t)=>{for(var s=t>1?void 0:t?k(n,e):n,i=r.length-1,c;i>=0;i--)(c=r[i])&&(s=(t?c(n,e,s):c(s))||s);return t&&s&&F(n,e,s),s},w=(r,n)=>(e,t)=>n(e,t,r);const E="univer.remote-sync-service",C=l.createIdentifier(E);let U=class{constructor(r){this._commandService=r}async syncMutation(r){return this._commandService.syncExecuteCommand(r.mutationInfo.id,r.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}};U=O([w(0,a.ICommandService)],U);const M="univer.remote-instance-service",S=l.createIdentifier(M);let q=class{constructor(r,n){this._univerInstanceService=r,this._commandService=n}whenReady(){return Promise.resolve(!0)}async syncMutation(r){return this._commandService.syncExecuteCommand(r.mutationInfo.id,r.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}async createInstance(r){const{type:n,snapshot:e}=r;try{switch(n){case a.UniverInstanceType.SHEET:return!!this._univerInstanceService.createSheet(e);default:throw new Error(`[RemoteInstanceReplicaService]: cannot create replica for document type: ${n}.`)}}catch(t){throw t instanceof Error?t:new Error(`${t}`)}}async disposeInstance(r){return this._univerInstanceService.disposeDocument(r.unitID)}};q=O([w(0,a.IUniverInstanceService),w(1,a.ICommandService)],q);function j(r){const n=r;return new class{call(e,t){const s=n[e];if(typeof s=="function"){let i=s.apply(n,[t]);return i instanceof Promise||(i=Promise.resolve(i)),i}throw new Error(`[RPC]: method not found for ${e}!`)}subscribe(e,t){const s=n[e];if(typeof s=="function"){const i=s.apply(n,t);return _.isObservable(i)?i:_.of(i)}throw new Error(`[RPC]: observable method not found for ${e}!`)}}}function $(r){return new Proxy({},{get(n,e){if(e!=="dispose")return function(...t){return z(e)?r.subscribe(e,t[0]):r.call(e,t[0])}}})}function z(r){return r.endsWith("$")}class T extends a.RxDisposable{constructor(e){super();h(this,"_initialized",new _.BehaviorSubject(!1));h(this,"_lastRequestCounter",0);h(this,"_pendingRequests",new Map);h(this,"_pendingSubscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(d.takeUntil(this.dispose$)).subscribe(t=>this._onMessage(t))}getChannel(e){const t=this;return{call(s,i){return t._disposed?Promise.reject():t._remoteCall(e,s,i)},subscribe(s,i){if(t._disposed)throw new Error("[ChannelClient]: client is disposed!");return t._remoteSubscribe(e,s,i)}}}_whenReady(){return _.firstValueFrom(this._initialized.pipe(d.filter(e=>e),d.take(1)))}async _remoteCall(e,t,s){await this._whenReady();const i=++this._lastRequestCounter,u={seq:i,type:100,channelName:e,method:t,args:s},o=this;return new Promise((g,p)=>{const N={handle(R){switch(R.type){case 201:o._pendingRequests.delete(i),g(R.data);break;case 202:o._pendingRequests.delete(i),p(R.data);break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(i,N),this._sendRequest(u)})}_remoteSubscribe(e,t,s){return new _.Observable(i=>{let c=-1;return this._whenReady().then(()=>{c=++this._lastRequestCounter;const o={seq:c,type:101,channelName:e,method:t,args:s},g={handle(p){switch(p.type){case 300:i.next(p.data);break;case 301:i.error(p.data);break;case 302:i.complete();break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(c,g),this._sendRequest(o)}),()=>{if(c===-1)return;const u={type:102,seq:c,channelName:e,method:t};this._sendRequest(u)}})}_sendRequest(e){this._protocol.send(e)}_onMessage(e){var t;switch(e.type){case 0:this._initialized.next(!0);break;case 201:case 202:case 300:case 302:case 301:(t=this._pendingRequests.get(e.seq))==null||t.handle(e);break}}}class D extends a.RxDisposable{constructor(e){super();h(this,"_channels",new Map);h(this,"_subscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(d.takeUntil(this.dispose$)).subscribe(t=>this._onRequest(t)),this._sendResponse({seq:-1,type:0})}registerChannel(e,t){this._channels.set(e,t)}_onRequest(e){switch(e.type){case 100:this._onMethodCall(e);break;case 101:this._onSubscribe(e);break;case 102:this._onUnsubscribe(e);break}}_onMethodCall(e){const{channelName:t,method:s,args:i}=e,c=this._channels.get(t);let u;try{if(!c)throw new Error(`[ChannelServer]: Channel ${t} not found!`);u=c.call(s,i)}catch(o){u=Promise.reject(o)}u.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:t,seq:s}=e,i=this._channels.get(t);try{if(!i)throw new Error(`[ChannelServer]: Channel ${t} not found!`);const u=i.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,u)}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 t=this._subscriptions.get(e.seq);t&&(t.unsubscribe(),this._subscriptions.delete(e.seq))}_sendResponse(e){this._protocol.send(e)}}const f=l.createIdentifier("IRPChannelService");class x{constructor(n){h(this,"_client");h(this,"_server");this._client=new T(n),this._server=new D(n)}requestChannel(n){return this._client.getChannel(n)}registerChannel(n,e){this._server.registerChannel(n,e)}}var V=Object.defineProperty,G=Object.getOwnPropertyDescriptor,B=(r,n,e,t)=>{for(var s=t>1?void 0:t?G(n,e):n,i=r.length-1,c;i>=0;i--)(c=r[i])&&(s=(t?c(n,e,s):c(s))||s);return t&&s&&V(n,e,s),s},v=(r,n)=>(e,t)=>n(e,t,r);let m=class extends a.RxDisposable{constructor(n,e,t,s,i){super();h(this,"_remoteInstanceService");h(this,"_syncingUnits",new Set);this._injector=n,this._commandService=e,this._univerInstanceService=t,this._rpcChannelService=s,this._remoteSyncService=i,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(E,j(this._remoteSyncService)),this._injector.add([S,{useFactory:()=>$(this._rpcChannelService.requestChannel(M))}]),this._remoteInstanceService=this._injector.get(S)}_init(){this._univerInstanceService.sheetAdded$.pipe(d.takeUntil(this.dispose$)).subscribe(n=>{this._syncingUnits.add(n.getUnitId()),this._remoteInstanceService.createInstance({unitID:n.getUnitId(),type:a.UniverInstanceType.SHEET,snapshot:n.getSnapshot()})}),this._univerInstanceService.sheetDisposed$.pipe(d.takeUntil(this.dispose$)).subscribe(n=>{this._syncingUnits.delete(n.getUnitId()),this._remoteInstanceService.disposeInstance({unitID:n.getUnitId()})}),this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{const{type:t,params:s}=n,i=(s==null?void 0:s.unitId)||"";t===a.CommandType.MUTATION&&(!i||this._syncingUnits.has(i))&&!(e!=null&&e.fromSync)&&this._remoteInstanceService.syncMutation({mutationInfo:n})}))}};m=B([a.OnLifecycle(a.LifecycleStages.Starting,m),v(0,l.Inject(l.Injector)),v(1,a.ICommandService),v(2,a.IUniverInstanceService),v(3,f),v(4,C)],m);var J=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,X=(r,n,e,t)=>{for(var s=t>1?void 0:t?Q(n,e):n,i=r.length-1,c;i>=0;i--)(c=r[i])&&(s=(t?c(n,e,s):c(s))||s);return t&&s&&J(n,e,s),s},b=(r,n)=>(e,t)=>n(e,t,r);let y=class extends a.Disposable{constructor(n,e,t,s){super();h(this,"_remoteSyncService");this._injector=n,this._remoteInstanceService=e,this._commandService=t,this._rpcChannelService=s,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(M,j(this._remoteInstanceService)),this._injector.add([C,{useFactory:()=>$(this._rpcChannelService.requestChannel(E))}]),this._remoteSyncService=this._injector.get(C)}_init(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{n.type===a.CommandType.MUTATION&&!(e!=null&&e.fromSync)&&this._remoteSyncService.syncMutation({mutationInfo:n})}))}};y=X([a.OnLifecycle(a.LifecycleStages.Starting,y),b(0,l.Inject(l.Injector)),b(1,S),b(2,a.ICommandService),b(3,f)],y);function Y(){return{send(r){postMessage(r)},onMessage:new _.Observable(r=>{const n=e=>{r.next(e.data)};return addEventListener("message",n),()=>removeEventListener("message",n)}).pipe(_.shareReplay(1))}}function Z(r){return{send(n){r.postMessage(n)},onMessage:new _.Observable(n=>{const e=t=>{n.next(t.data)};return r.addEventListener("message",e),()=>r.removeEventListener("message",e)}).pipe(_.shareReplay(1))}}var K=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,W=(r,n,e,t)=>{for(var s=t>1?void 0:t?ee(n,e):n,i=r.length-1,c;i>=0;i--)(c=r[i])&&(s=(t?c(n,e,s):c(s))||s);return t&&s&&K(n,e,s),s},L=(r,n)=>(e,t)=>n(e,t,r),I;exports.UniverRPCMainThreadPlugin=(I=class extends a.Plugin{constructor(n,e){super("UNIVER_RPC_MAIN_THREAD_PLUGIN"),this._config=n,this._injector=e}async onStarting(n){const{workerURL:e}=this._config,t=e instanceof Worker?e:new Worker(e),s=Z(t);[[f,{useFactory:()=>new x(s)}],[m],[C,{useClass:U}]].forEach(c=>n.add(c)),n.get(m)}},h(I,"type",a.PluginType.Univer),I);exports.UniverRPCMainThreadPlugin=W([L(1,l.Inject(l.Injector))],exports.UniverRPCMainThreadPlugin);var P;exports.UniverRPCWorkerThreadPlugin=(P=class extends a.Plugin{constructor(n,e){super("UNIVER_RPC_WORKER_THREAD_PLUGIN"),this._config=n,this._injector=e}onStarting(n){[[y],[f,{useFactory:()=>new x(Y())}],[S,{useClass:q}]].forEach(e=>n.add(e)),n.get(y)}},h(P,"type",a.PluginType.Univer),P);exports.UniverRPCWorkerThreadPlugin=W([L(1,l.Inject(l.Injector))],exports.UniverRPCWorkerThreadPlugin);exports.ChannelClient=T;exports.ChannelServer=D;exports.IRPChannelService=f;exports.IRemoteInstanceService=S; |
var Z = Object.defineProperty; | ||
var K = (s, t, e) => t in s ? Z(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e; | ||
var a = (s, t, e) => (K(s, typeof t != "symbol" ? t + "" : t, e), e); | ||
import { UniverInstanceType as T, ICommandService as y, IUniverInstanceService as W, RxDisposable as M, OnLifecycle as L, LifecycleStages as N, CommandType as A, Disposable as k, Plugin as H, PluginType as F } from "@univerjs/core"; | ||
var k = (s, t, e) => t in s ? Z(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e; | ||
var a = (s, t, e) => (k(s, typeof t != "symbol" ? t + "" : t, e), e); | ||
import { UniverInstanceType as T, ICommandService as y, IUniverInstanceService as W, RxDisposable as M, OnLifecycle as L, LifecycleStages as N, CommandType as A, Disposable as K, Plugin as H, PluginType as F } from "@univerjs/core"; | ||
import { createIdentifier as O, Inject as S, Injector as b } from "@wendellhu/redi"; | ||
@@ -89,5 +89,6 @@ import { takeUntil as v, filter as ee, take as te } from "rxjs/operators"; | ||
get(t, e) { | ||
return function(...n) { | ||
return ae(e) ? s.subscribe(e, n[0]) : s.call(e, n[0]); | ||
}; | ||
if (e !== "dispose") | ||
return function(...n) { | ||
return ae(e) ? s.subscribe(e, n[0]) : s.call(e, n[0]); | ||
}; | ||
} | ||
@@ -354,3 +355,3 @@ }); | ||
}, d = (s, t) => (e, n) => t(e, n, s); | ||
let p = class extends k { | ||
let p = class extends K { | ||
constructor(t, e, n, r) { | ||
@@ -357,0 +358,0 @@ super(); |
@@ -1,1 +0,1 @@ | ||
(function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("rxjs/operators"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","rxjs/operators","rxjs"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o.UniverRpc={},o.UniverCore,o["@wendellhu/redi"],o.rxjs.operators,o.rxjs))})(this,function(o,c,h,p,d){"use strict";var ee=Object.defineProperty;var ne=(o,c,h)=>c in o?ee(o,c,{enumerable:!0,configurable:!0,writable:!0,value:h}):o[c]=h;var u=(o,c,h)=>(ne(o,typeof c!="symbol"?c+"":c,h),h);var q,E;var A=Object.defineProperty,H=Object.getOwnPropertyDescriptor,j=(r,n,e,t)=>{for(var s=t>1?void 0:t?H(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&A(n,e,s),s},g=(r,n)=>(e,t)=>n(e,t,r);const I="univer.remote-sync-service",b=h.createIdentifier(I);let P=class{constructor(r){this._commandService=r}async syncMutation(r){return this._commandService.syncExecuteCommand(r.mutationInfo.id,r.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}};P=j([g(0,c.ICommandService)],P);const w="univer.remote-instance-service",v=h.createIdentifier(w);let U=class{constructor(r,n){this._univerInstanceService=r,this._commandService=n}whenReady(){return Promise.resolve(!0)}async syncMutation(r){return this._commandService.syncExecuteCommand(r.mutationInfo.id,r.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}async createInstance(r){const{type:n,snapshot:e}=r;try{switch(n){case c.UniverInstanceType.SHEET:return!!this._univerInstanceService.createSheet(e);default:throw new Error(`[RemoteInstanceReplicaService]: cannot create replica for document type: ${n}.`)}}catch(t){throw t instanceof Error?t:new Error(`${t}`)}}async disposeInstance(r){return this._univerInstanceService.disposeDocument(r.unitID)}};U=j([g(0,c.IUniverInstanceService),g(1,c.ICommandService)],U);function T(r){const n=r;return new class{call(e,t){const s=n[e];if(typeof s=="function"){let i=s.apply(n,[t]);return i instanceof Promise||(i=Promise.resolve(i)),i}throw new Error(`[RPC]: method not found for ${e}!`)}subscribe(e,t){const s=n[e];if(typeof s=="function"){const i=s.apply(n,t);return d.isObservable(i)?i:d.of(i)}throw new Error(`[RPC]: observable method not found for ${e}!`)}}}function $(r){return new Proxy({},{get(n,e){return function(...t){return F(e)?r.subscribe(e,t[0]):r.call(e,t[0])}}})}function F(r){return r.endsWith("$")}class D extends c.RxDisposable{constructor(e){super();u(this,"_initialized",new d.BehaviorSubject(!1));u(this,"_lastRequestCounter",0);u(this,"_pendingRequests",new Map);u(this,"_pendingSubscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(p.takeUntil(this.dispose$)).subscribe(t=>this._onMessage(t))}getChannel(e){const t=this;return{call(s,i){return t._disposed?Promise.reject():t._remoteCall(e,s,i)},subscribe(s,i){if(t._disposed)throw new Error("[ChannelClient]: client is disposed!");return t._remoteSubscribe(e,s,i)}}}_whenReady(){return d.firstValueFrom(this._initialized.pipe(p.filter(e=>e),p.take(1)))}async _remoteCall(e,t,s){await this._whenReady();const i=++this._lastRequestCounter,_={seq:i,type:100,channelName:e,method:t,args:s},l=this;return new Promise((M,C)=>{const K={handle(O){switch(O.type){case 201:l._pendingRequests.delete(i),M(O.data);break;case 202:l._pendingRequests.delete(i),C(O.data);break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(i,K),this._sendRequest(_)})}_remoteSubscribe(e,t,s){return new d.Observable(i=>{let a=-1;return this._whenReady().then(()=>{a=++this._lastRequestCounter;const l={seq:a,type:101,channelName:e,method:t,args:s},M={handle(C){switch(C.type){case 300:i.next(C.data);break;case 301:i.error(C.data);break;case 302:i.complete();break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(a,M),this._sendRequest(l)}),()=>{if(a===-1)return;const _={type:102,seq:a,channelName:e,method:t};this._sendRequest(_)}})}_sendRequest(e){this._protocol.send(e)}_onMessage(e){var t;switch(e.type){case 0:this._initialized.next(!0);break;case 201:case 202:case 300:case 302:case 301:(t=this._pendingRequests.get(e.seq))==null||t.handle(e);break}}}class W extends c.RxDisposable{constructor(e){super();u(this,"_channels",new Map);u(this,"_subscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(p.takeUntil(this.dispose$)).subscribe(t=>this._onRequest(t)),this._sendResponse({seq:-1,type:0})}registerChannel(e,t){this._channels.set(e,t)}_onRequest(e){switch(e.type){case 100:this._onMethodCall(e);break;case 101:this._onSubscribe(e);break;case 102:this._onUnsubscribe(e);break}}_onMethodCall(e){const{channelName:t,method:s,args:i}=e,a=this._channels.get(t);let _;try{if(!a)throw new Error(`[ChannelServer]: Channel ${t} not found!`);_=a.call(s,i)}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:t,seq:s}=e,i=this._channels.get(t);try{if(!i)throw new Error(`[ChannelServer]: Channel ${t} 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(a){a instanceof Error?this._sendResponse({seq:e.seq,type:301,data:a.message}):this._sendResponse({seq:e.seq,type:301,data:String(a)})}}_onUnsubscribe(e){const t=this._subscriptions.get(e.seq);t&&(t.unsubscribe(),this._subscriptions.delete(e.seq))}_sendResponse(e){this._protocol.send(e)}}const m=h.createIdentifier("IRPChannelService");class L{constructor(n){u(this,"_client");u(this,"_server");this._client=new D(n),this._server=new W(n)}requestChannel(n){return this._client.getChannel(n)}registerChannel(n,e){this._server.registerChannel(n,e)}}var k=Object.defineProperty,z=Object.getOwnPropertyDescriptor,V=(r,n,e,t)=>{for(var s=t>1?void 0:t?z(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&k(n,e,s),s},f=(r,n)=>(e,t)=>n(e,t,r);let y=class extends c.RxDisposable{constructor(n,e,t,s,i){super();u(this,"_remoteInstanceService");u(this,"_syncingUnits",new Set);this._injector=n,this._commandService=e,this._univerInstanceService=t,this._rpcChannelService=s,this._remoteSyncService=i,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(I,T(this._remoteSyncService)),this._injector.add([v,{useFactory:()=>$(this._rpcChannelService.requestChannel(w))}]),this._remoteInstanceService=this._injector.get(v)}_init(){this._univerInstanceService.sheetAdded$.pipe(p.takeUntil(this.dispose$)).subscribe(n=>{this._syncingUnits.add(n.getUnitId()),this._remoteInstanceService.createInstance({unitID:n.getUnitId(),type:c.UniverInstanceType.SHEET,snapshot:n.getSnapshot()})}),this._univerInstanceService.sheetDisposed$.pipe(p.takeUntil(this.dispose$)).subscribe(n=>{this._syncingUnits.delete(n.getUnitId()),this._remoteInstanceService.disposeInstance({unitID:n.getUnitId()})}),this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{const{type:t,params:s}=n,i=(s==null?void 0:s.unitId)||"";t===c.CommandType.MUTATION&&(!i||this._syncingUnits.has(i))&&!(e!=null&&e.fromSync)&&this._remoteInstanceService.syncMutation({mutationInfo:n})}))}};y=V([c.OnLifecycle(c.LifecycleStages.Starting,y),f(0,h.Inject(h.Injector)),f(1,c.ICommandService),f(2,c.IUniverInstanceService),f(3,m),f(4,b)],y);var G=Object.defineProperty,B=Object.getOwnPropertyDescriptor,J=(r,n,e,t)=>{for(var s=t>1?void 0:t?B(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&G(n,e,s),s},R=(r,n)=>(e,t)=>n(e,t,r);let S=class extends c.Disposable{constructor(n,e,t,s){super();u(this,"_remoteSyncService");this._injector=n,this._remoteInstanceService=e,this._commandService=t,this._rpcChannelService=s,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(w,T(this._remoteInstanceService)),this._injector.add([b,{useFactory:()=>$(this._rpcChannelService.requestChannel(I))}]),this._remoteSyncService=this._injector.get(b)}_init(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{n.type===c.CommandType.MUTATION&&!(e!=null&&e.fromSync)&&this._remoteSyncService.syncMutation({mutationInfo:n})}))}};S=J([c.OnLifecycle(c.LifecycleStages.Starting,S),R(0,h.Inject(h.Injector)),R(1,v),R(2,c.ICommandService),R(3,m)],S);function Q(){return{send(r){postMessage(r)},onMessage:new d.Observable(r=>{const n=e=>{r.next(e.data)};return addEventListener("message",n),()=>removeEventListener("message",n)}).pipe(d.shareReplay(1))}}function X(r){return{send(n){r.postMessage(n)},onMessage:new d.Observable(n=>{const e=t=>{n.next(t.data)};return r.addEventListener("message",e),()=>r.removeEventListener("message",e)}).pipe(d.shareReplay(1))}}var Y=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,x=(r,n,e,t)=>{for(var s=t>1?void 0:t?Z(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Y(n,e,s),s},N=(r,n)=>(e,t)=>n(e,t,r);o.UniverRPCMainThreadPlugin=(q=class extends c.Plugin{constructor(n,e){super("UNIVER_RPC_MAIN_THREAD_PLUGIN"),this._config=n,this._injector=e}async onStarting(n){const{workerURL:e}=this._config,t=e instanceof Worker?e:new Worker(e),s=X(t);[[m,{useFactory:()=>new L(s)}],[y],[b,{useClass:P}]].forEach(a=>n.add(a)),n.get(y)}},u(q,"type",c.PluginType.Univer),q),o.UniverRPCMainThreadPlugin=x([N(1,h.Inject(h.Injector))],o.UniverRPCMainThreadPlugin),o.UniverRPCWorkerThreadPlugin=(E=class extends c.Plugin{constructor(n,e){super("UNIVER_RPC_WORKER_THREAD_PLUGIN"),this._config=n,this._injector=e}onStarting(n){[[S],[m,{useFactory:()=>new L(Q())}],[v,{useClass:U}]].forEach(e=>n.add(e)),n.get(S)}},u(E,"type",c.PluginType.Univer),E),o.UniverRPCWorkerThreadPlugin=x([N(1,h.Inject(h.Injector))],o.UniverRPCWorkerThreadPlugin),o.ChannelClient=D,o.ChannelServer=W,o.IRPChannelService=m,o.IRemoteInstanceService=v,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}); | ||
(function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("rxjs/operators"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","rxjs/operators","rxjs"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o.UniverRpc={},o.UniverCore,o["@wendellhu/redi"],o.rxjs.operators,o.rxjs))})(this,function(o,c,h,p,d){"use strict";var ee=Object.defineProperty;var ne=(o,c,h)=>c in o?ee(o,c,{enumerable:!0,configurable:!0,writable:!0,value:h}):o[c]=h;var u=(o,c,h)=>(ne(o,typeof c!="symbol"?c+"":c,h),h);var q,E;var A=Object.defineProperty,H=Object.getOwnPropertyDescriptor,j=(r,n,e,t)=>{for(var s=t>1?void 0:t?H(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&A(n,e,s),s},g=(r,n)=>(e,t)=>n(e,t,r);const I="univer.remote-sync-service",b=h.createIdentifier(I);let P=class{constructor(r){this._commandService=r}async syncMutation(r){return this._commandService.syncExecuteCommand(r.mutationInfo.id,r.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}};P=j([g(0,c.ICommandService)],P);const w="univer.remote-instance-service",v=h.createIdentifier(w);let U=class{constructor(r,n){this._univerInstanceService=r,this._commandService=n}whenReady(){return Promise.resolve(!0)}async syncMutation(r){return this._commandService.syncExecuteCommand(r.mutationInfo.id,r.mutationInfo.params,{onlyLocal:!0,fromSync:!0})}async createInstance(r){const{type:n,snapshot:e}=r;try{switch(n){case c.UniverInstanceType.SHEET:return!!this._univerInstanceService.createSheet(e);default:throw new Error(`[RemoteInstanceReplicaService]: cannot create replica for document type: ${n}.`)}}catch(t){throw t instanceof Error?t:new Error(`${t}`)}}async disposeInstance(r){return this._univerInstanceService.disposeDocument(r.unitID)}};U=j([g(0,c.IUniverInstanceService),g(1,c.ICommandService)],U);function T(r){const n=r;return new class{call(e,t){const s=n[e];if(typeof s=="function"){let i=s.apply(n,[t]);return i instanceof Promise||(i=Promise.resolve(i)),i}throw new Error(`[RPC]: method not found for ${e}!`)}subscribe(e,t){const s=n[e];if(typeof s=="function"){const i=s.apply(n,t);return d.isObservable(i)?i:d.of(i)}throw new Error(`[RPC]: observable method not found for ${e}!`)}}}function $(r){return new Proxy({},{get(n,e){if(e!=="dispose")return function(...t){return F(e)?r.subscribe(e,t[0]):r.call(e,t[0])}}})}function F(r){return r.endsWith("$")}class D extends c.RxDisposable{constructor(e){super();u(this,"_initialized",new d.BehaviorSubject(!1));u(this,"_lastRequestCounter",0);u(this,"_pendingRequests",new Map);u(this,"_pendingSubscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(p.takeUntil(this.dispose$)).subscribe(t=>this._onMessage(t))}getChannel(e){const t=this;return{call(s,i){return t._disposed?Promise.reject():t._remoteCall(e,s,i)},subscribe(s,i){if(t._disposed)throw new Error("[ChannelClient]: client is disposed!");return t._remoteSubscribe(e,s,i)}}}_whenReady(){return d.firstValueFrom(this._initialized.pipe(p.filter(e=>e),p.take(1)))}async _remoteCall(e,t,s){await this._whenReady();const i=++this._lastRequestCounter,_={seq:i,type:100,channelName:e,method:t,args:s},l=this;return new Promise((M,C)=>{const K={handle(O){switch(O.type){case 201:l._pendingRequests.delete(i),M(O.data);break;case 202:l._pendingRequests.delete(i),C(O.data);break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(i,K),this._sendRequest(_)})}_remoteSubscribe(e,t,s){return new d.Observable(i=>{let a=-1;return this._whenReady().then(()=>{a=++this._lastRequestCounter;const l={seq:a,type:101,channelName:e,method:t,args:s},M={handle(C){switch(C.type){case 300:i.next(C.data);break;case 301:i.error(C.data);break;case 302:i.complete();break;default:throw new Error("[ChannelClient]: unknown response type!")}}};this._pendingRequests.set(a,M),this._sendRequest(l)}),()=>{if(a===-1)return;const _={type:102,seq:a,channelName:e,method:t};this._sendRequest(_)}})}_sendRequest(e){this._protocol.send(e)}_onMessage(e){var t;switch(e.type){case 0:this._initialized.next(!0);break;case 201:case 202:case 300:case 302:case 301:(t=this._pendingRequests.get(e.seq))==null||t.handle(e);break}}}class W extends c.RxDisposable{constructor(e){super();u(this,"_channels",new Map);u(this,"_subscriptions",new Map);this._protocol=e,this._protocol.onMessage.pipe(p.takeUntil(this.dispose$)).subscribe(t=>this._onRequest(t)),this._sendResponse({seq:-1,type:0})}registerChannel(e,t){this._channels.set(e,t)}_onRequest(e){switch(e.type){case 100:this._onMethodCall(e);break;case 101:this._onSubscribe(e);break;case 102:this._onUnsubscribe(e);break}}_onMethodCall(e){const{channelName:t,method:s,args:i}=e,a=this._channels.get(t);let _;try{if(!a)throw new Error(`[ChannelServer]: Channel ${t} not found!`);_=a.call(s,i)}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:t,seq:s}=e,i=this._channels.get(t);try{if(!i)throw new Error(`[ChannelServer]: Channel ${t} 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(a){a instanceof Error?this._sendResponse({seq:e.seq,type:301,data:a.message}):this._sendResponse({seq:e.seq,type:301,data:String(a)})}}_onUnsubscribe(e){const t=this._subscriptions.get(e.seq);t&&(t.unsubscribe(),this._subscriptions.delete(e.seq))}_sendResponse(e){this._protocol.send(e)}}const m=h.createIdentifier("IRPChannelService");class L{constructor(n){u(this,"_client");u(this,"_server");this._client=new D(n),this._server=new W(n)}requestChannel(n){return this._client.getChannel(n)}registerChannel(n,e){this._server.registerChannel(n,e)}}var k=Object.defineProperty,z=Object.getOwnPropertyDescriptor,V=(r,n,e,t)=>{for(var s=t>1?void 0:t?z(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&k(n,e,s),s},f=(r,n)=>(e,t)=>n(e,t,r);let y=class extends c.RxDisposable{constructor(n,e,t,s,i){super();u(this,"_remoteInstanceService");u(this,"_syncingUnits",new Set);this._injector=n,this._commandService=e,this._univerInstanceService=t,this._rpcChannelService=s,this._remoteSyncService=i,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(I,T(this._remoteSyncService)),this._injector.add([v,{useFactory:()=>$(this._rpcChannelService.requestChannel(w))}]),this._remoteInstanceService=this._injector.get(v)}_init(){this._univerInstanceService.sheetAdded$.pipe(p.takeUntil(this.dispose$)).subscribe(n=>{this._syncingUnits.add(n.getUnitId()),this._remoteInstanceService.createInstance({unitID:n.getUnitId(),type:c.UniverInstanceType.SHEET,snapshot:n.getSnapshot()})}),this._univerInstanceService.sheetDisposed$.pipe(p.takeUntil(this.dispose$)).subscribe(n=>{this._syncingUnits.delete(n.getUnitId()),this._remoteInstanceService.disposeInstance({unitID:n.getUnitId()})}),this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{const{type:t,params:s}=n,i=(s==null?void 0:s.unitId)||"";t===c.CommandType.MUTATION&&(!i||this._syncingUnits.has(i))&&!(e!=null&&e.fromSync)&&this._remoteInstanceService.syncMutation({mutationInfo:n})}))}};y=V([c.OnLifecycle(c.LifecycleStages.Starting,y),f(0,h.Inject(h.Injector)),f(1,c.ICommandService),f(2,c.IUniverInstanceService),f(3,m),f(4,b)],y);var G=Object.defineProperty,B=Object.getOwnPropertyDescriptor,J=(r,n,e,t)=>{for(var s=t>1?void 0:t?B(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&G(n,e,s),s},R=(r,n)=>(e,t)=>n(e,t,r);let S=class extends c.Disposable{constructor(n,e,t,s){super();u(this,"_remoteSyncService");this._injector=n,this._remoteInstanceService=e,this._commandService=t,this._rpcChannelService=s,this._initRPCChannels(),this._init()}_initRPCChannels(){this._rpcChannelService.registerChannel(w,T(this._remoteInstanceService)),this._injector.add([b,{useFactory:()=>$(this._rpcChannelService.requestChannel(I))}]),this._remoteSyncService=this._injector.get(b)}_init(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{n.type===c.CommandType.MUTATION&&!(e!=null&&e.fromSync)&&this._remoteSyncService.syncMutation({mutationInfo:n})}))}};S=J([c.OnLifecycle(c.LifecycleStages.Starting,S),R(0,h.Inject(h.Injector)),R(1,v),R(2,c.ICommandService),R(3,m)],S);function Q(){return{send(r){postMessage(r)},onMessage:new d.Observable(r=>{const n=e=>{r.next(e.data)};return addEventListener("message",n),()=>removeEventListener("message",n)}).pipe(d.shareReplay(1))}}function X(r){return{send(n){r.postMessage(n)},onMessage:new d.Observable(n=>{const e=t=>{n.next(t.data)};return r.addEventListener("message",e),()=>r.removeEventListener("message",e)}).pipe(d.shareReplay(1))}}var Y=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,x=(r,n,e,t)=>{for(var s=t>1?void 0:t?Z(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Y(n,e,s),s},N=(r,n)=>(e,t)=>n(e,t,r);o.UniverRPCMainThreadPlugin=(q=class extends c.Plugin{constructor(n,e){super("UNIVER_RPC_MAIN_THREAD_PLUGIN"),this._config=n,this._injector=e}async onStarting(n){const{workerURL:e}=this._config,t=e instanceof Worker?e:new Worker(e),s=X(t);[[m,{useFactory:()=>new L(s)}],[y],[b,{useClass:P}]].forEach(a=>n.add(a)),n.get(y)}},u(q,"type",c.PluginType.Univer),q),o.UniverRPCMainThreadPlugin=x([N(1,h.Inject(h.Injector))],o.UniverRPCMainThreadPlugin),o.UniverRPCWorkerThreadPlugin=(E=class extends c.Plugin{constructor(n,e){super("UNIVER_RPC_WORKER_THREAD_PLUGIN"),this._config=n,this._injector=e}onStarting(n){[[S],[m,{useFactory:()=>new L(Q())}],[v,{useClass:U}]].forEach(e=>n.add(e)),n.get(S)}},u(E,"type",c.PluginType.Univer),E),o.UniverRPCWorkerThreadPlugin=x([N(1,h.Inject(h.Injector))],o.UniverRPCWorkerThreadPlugin),o.ChannelClient=D,o.ChannelServer=W,o.IRPChannelService=m,o.IRemoteInstanceService=v,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}); |
{ | ||
"name": "@univerjs/rpc", | ||
"version": "0.1.0-beta.2", | ||
"keywords": [], | ||
"version": "0.1.0-beta.3", | ||
"private": false, | ||
"author": "DreamNum <developer@univer.ai>", | ||
"license": "Apache-2.0", | ||
"main": "./lib/cjs/index.js", | ||
"module": "./lib/es/index.js", | ||
"types": "./lib/types/index.d.ts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"keywords": [], | ||
"exports": { | ||
@@ -25,2 +20,8 @@ ".": { | ||
}, | ||
"main": "./lib/cjs/index.js", | ||
"module": "./lib/es/index.js", | ||
"types": "./lib/types/index.d.ts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"directories": { | ||
@@ -32,24 +33,25 @@ "lib": "lib" | ||
], | ||
"private": false, | ||
"dependencies": { | ||
"engines": { | ||
"node": ">=16.0.0", | ||
"npm": ">=8.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@wendellhu/redi": ">=0.12.13", | ||
"rxjs": ">=7.0.0", | ||
"@univerjs/core": "0.1.0-beta.3" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@wendellhu/redi": "^0.12.13", | ||
"rxjs": "^7.8.1", | ||
"@univerjs/core": "0.1.0-beta.2" | ||
}, | ||
"devDependencies": { | ||
"@vitest/coverage-istanbul": "^1.1.1", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.10", | ||
"vite-plugin-dts": "^3.7.0", | ||
"vite-plugin-externals": "^0.6.2", | ||
"vitest": "^1.1.1" | ||
"vite": "^5.0.12", | ||
"vitest": "^1.2.1", | ||
"@univerjs/core": "0.1.0-beta.3", | ||
"@univerjs/shared": "0.1.0-beta.3" | ||
}, | ||
"peerDependencies": { | ||
"@wendellhu/redi": ">=0.12.12", | ||
"rxjs": ">=7.0.0", | ||
"@univerjs/core": "0.1.0-beta.2" | ||
}, | ||
"scripts": { | ||
"lint:types": "tsc --noEmit", | ||
"build": "tsc && vite build" | ||
} | ||
} |
60886
3
915
7
+ Added@univerjs/core@0.1.0-beta.3(transitive)
+ Added@wendellhu/redi@0.17.1(transitive)
- Removed@univerjs/core@0.1.0-beta.2
- Removed@wendellhu/redi@^0.12.13
- Removedrxjs@^7.8.1
- Removed@univerjs/core@0.1.0-beta.2(transitive)
- Removed@wendellhu/redi@0.12.13(transitive)