@univerjs/rpc-node 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1,230 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:child_process`),l=require(`node:process`);l=s(l);let u=require(`@univerjs/core`),d=require(`@univerjs/rpc`),f=require(`rxjs`);var p=`@univerjs/rpc-node`,m=`0.20.1`;const h=`rpc-node.main-thread.config`;Symbol(h);const g={},_=`rpc-node.worker-thread.config`;Symbol(_);const v={};function y(e){"@babel/helpers - typeof";return y=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},y(e)}function b(e,t){if(y(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(y(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function x(e){var t=b(e,`string`);return y(t)==`symbol`?t:t+``}function S(e,t,n){return(t=x(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function C(e,t){return function(n,r){t(n,r,e)}}function w(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let T=class extends u.Plugin{constructor(e=g,t,n){super(),this._config=e,this._injector=t,this._configService=n,S(this,`_child`,null);let{...r}=(0,u.merge)({},g,this._config);this._configService.setConfig(h,r)}onStarting(){let{workerSrc:e}=this._config;if(!e)throw Error(`[UniverRPCNodeMainPlugin] workerSrc is required for UniverRPCNodeMainPlugin`);let[t,n]=D(this._injector,e);[[d.IRPCChannelService,{useFactory:()=>new d.ChannelService(t)}],[d.DataSyncPrimaryController],[d.IRemoteSyncService,{useClass:d.RemoteSyncPrimaryService}]].forEach(e=>this._injector.add(e)),this._injector.get(d.DataSyncPrimaryController),this._child=n}dispose(){if(super.dispose(),this._child){try{this._child.kill()}catch(e){console.error(`Failed to kill child process:`,e)}this._child=null}}};S(T,`pluginName`,`UNIVER_RPC_NODE_MAIN_PLUGIN`),S(T,`packageName`,p),S(T,`version`,m),T=w([C(1,(0,u.Inject)(u.Injector)),C(2,u.IConfigService)],T);let E=class extends u.Plugin{constructor(e=v,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=(0,u.merge)({},v,this._config);this._configService.setConfig(_,r)}onStarting(){[[d.DataSyncReplicaController],[d.IRPCChannelService,{useFactory:()=>new d.ChannelService(O())}],[d.IRemoteInstanceService,{useClass:d.WebWorkerRemoteInstanceService}]].forEach(e=>this._injector.add(e)),this._injector.get(d.DataSyncReplicaController)}};S(E,`pluginName`,`UNIVER_RPC_NODE_WORKER_PLUGIN`),S(E,`packageName`,p),S(E,`version`,m),E=w([C(1,(0,u.Inject)(u.Injector)),C(2,u.IConfigService)],E);function D(e,t){let n=e.get(u.ILogService),r=(0,c.fork)(t);return r.on(`spawn`,()=>n.log(`Child computing process spawned!`)),r.on(`error`,e=>n.error(e)),[{send(e){r.send(e)},onMessage:new f.Observable(e=>{let t=t=>{e.next(t)};return r.on(`message`,t),()=>r.off(`message`,t)}).pipe((0,f.shareReplay)(1))},r]}function O(){return{send(e){l.default.send(e)},onMessage:new f.Observable(e=>{let t=t=>{e.next(t)};return l.default.on(`message`,t),()=>l.default.off(`message`,t)}).pipe((0,f.shareReplay)(1))}}Object.defineProperty(exports,`UniverRPCNodeMainPlugin`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`UniverRPCNodeWorkerPlugin`,{enumerable:!0,get:function(){return E}});
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+
28
+ //#endregion
29
+ let node_child_process = require("node:child_process");
30
+ let node_process = require("node:process");
31
+ node_process = __toESM(node_process);
32
+ let _univerjs_core = require("@univerjs/core");
33
+ let _univerjs_rpc = require("@univerjs/rpc");
34
+ let rxjs = require("rxjs");
35
+
36
+ //#region package.json
37
+ var name = "@univerjs/rpc-node";
38
+ var version = "0.21.0";
39
+
40
+ //#endregion
41
+ //#region src/config/config.ts
42
+ /**
43
+ * Copyright 2023-present DreamNum Co., Ltd.
44
+ *
45
+ * Licensed under the Apache License, Version 2.0 (the "License");
46
+ * you may not use this file except in compliance with the License.
47
+ * You may obtain a copy of the License at
48
+ *
49
+ * http://www.apache.org/licenses/LICENSE-2.0
50
+ *
51
+ * Unless required by applicable law or agreed to in writing, software
52
+ * distributed under the License is distributed on an "AS IS" BASIS,
53
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
54
+ * See the License for the specific language governing permissions and
55
+ * limitations under the License.
56
+ */
57
+ const PLUGIN_CONFIG_KEY_MAIN_THREAD = "rpc-node.main-thread.config";
58
+ const configSymbolMainThread = Symbol(PLUGIN_CONFIG_KEY_MAIN_THREAD);
59
+ const defaultPluginMainThreadConfig = {};
60
+ const PLUGIN_CONFIG_KEY_WORKER_THREAD = "rpc-node.worker-thread.config";
61
+ const configSymbolWorkerThread = Symbol(PLUGIN_CONFIG_KEY_WORKER_THREAD);
62
+ const defaultPluginWorkerThreadConfig = {};
63
+
64
+ //#endregion
65
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
66
+ function _typeof(o) {
67
+ "@babel/helpers - typeof";
68
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
69
+ return typeof o;
70
+ } : function(o) {
71
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
72
+ }, _typeof(o);
73
+ }
74
+
75
+ //#endregion
76
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
77
+ function toPrimitive(t, r) {
78
+ if ("object" != _typeof(t) || !t) return t;
79
+ var e = t[Symbol.toPrimitive];
80
+ if (void 0 !== e) {
81
+ var i = e.call(t, r || "default");
82
+ if ("object" != _typeof(i)) return i;
83
+ throw new TypeError("@@toPrimitive must return a primitive value.");
84
+ }
85
+ return ("string" === r ? String : Number)(t);
86
+ }
87
+
88
+ //#endregion
89
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
90
+ function toPropertyKey(t) {
91
+ var i = toPrimitive(t, "string");
92
+ return "symbol" == _typeof(i) ? i : i + "";
93
+ }
94
+
95
+ //#endregion
96
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
97
+ function _defineProperty(e, r, t) {
98
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
99
+ value: t,
100
+ enumerable: !0,
101
+ configurable: !0,
102
+ writable: !0
103
+ }) : e[r] = t, e;
104
+ }
105
+
106
+ //#endregion
107
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
108
+ function __decorateParam(paramIndex, decorator) {
109
+ return function(target, key) {
110
+ decorator(target, key, paramIndex);
111
+ };
112
+ }
113
+
114
+ //#endregion
115
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
116
+ function __decorate(decorators, target, key, desc) {
117
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
118
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
119
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
120
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
121
+ }
122
+
123
+ //#endregion
124
+ //#region src/plugin.ts
125
+ let UniverRPCNodeMainPlugin = class UniverRPCNodeMainPlugin extends _univerjs_core.Plugin {
126
+ constructor(_config = defaultPluginMainThreadConfig, _injector, _configService) {
127
+ super();
128
+ this._config = _config;
129
+ this._injector = _injector;
130
+ this._configService = _configService;
131
+ _defineProperty(this, "_child", null);
132
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginMainThreadConfig, this._config);
133
+ this._configService.setConfig(PLUGIN_CONFIG_KEY_MAIN_THREAD, rest);
134
+ }
135
+ onStarting() {
136
+ const { workerSrc } = this._config;
137
+ if (!workerSrc) throw new Error("[UniverRPCNodeMainPlugin] workerSrc is required for UniverRPCNodeMainPlugin");
138
+ const [messageProtocol, child] = createNodeMessagePortOnMain(this._injector, workerSrc);
139
+ [
140
+ [_univerjs_rpc.IRPCChannelService, { useFactory: () => new _univerjs_rpc.ChannelService(messageProtocol) }],
141
+ [_univerjs_rpc.DataSyncPrimaryController],
142
+ [_univerjs_rpc.IRemoteSyncService, { useClass: _univerjs_rpc.RemoteSyncPrimaryService }]
143
+ ].forEach((dependency) => this._injector.add(dependency));
144
+ this._injector.get(_univerjs_rpc.DataSyncPrimaryController);
145
+ this._child = child;
146
+ }
147
+ dispose() {
148
+ super.dispose();
149
+ if (this._child) {
150
+ try {
151
+ this._child.kill();
152
+ } catch (e) {
153
+ console.error("Failed to kill child process:", e);
154
+ }
155
+ this._child = null;
156
+ }
157
+ }
158
+ };
159
+ _defineProperty(UniverRPCNodeMainPlugin, "pluginName", "UNIVER_RPC_NODE_MAIN_PLUGIN");
160
+ _defineProperty(UniverRPCNodeMainPlugin, "packageName", name);
161
+ _defineProperty(UniverRPCNodeMainPlugin, "version", version);
162
+ UniverRPCNodeMainPlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_core.IConfigService)], UniverRPCNodeMainPlugin);
163
+ let UniverRPCNodeWorkerPlugin = class UniverRPCNodeWorkerPlugin extends _univerjs_core.Plugin {
164
+ constructor(_config = defaultPluginWorkerThreadConfig, _injector, _configService) {
165
+ super();
166
+ this._config = _config;
167
+ this._injector = _injector;
168
+ this._configService = _configService;
169
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginWorkerThreadConfig, this._config);
170
+ this._configService.setConfig(PLUGIN_CONFIG_KEY_WORKER_THREAD, rest);
171
+ }
172
+ onStarting() {
173
+ [
174
+ [_univerjs_rpc.DataSyncReplicaController],
175
+ [_univerjs_rpc.IRPCChannelService, { useFactory: () => new _univerjs_rpc.ChannelService(createNodeWorkerMessageProtocol()) }],
176
+ [_univerjs_rpc.IRemoteInstanceService, { useClass: _univerjs_rpc.WebWorkerRemoteInstanceService }]
177
+ ].forEach((d) => this._injector.add(d));
178
+ this._injector.get(_univerjs_rpc.DataSyncReplicaController);
179
+ }
180
+ };
181
+ _defineProperty(UniverRPCNodeWorkerPlugin, "pluginName", "UNIVER_RPC_NODE_WORKER_PLUGIN");
182
+ _defineProperty(UniverRPCNodeWorkerPlugin, "packageName", name);
183
+ _defineProperty(UniverRPCNodeWorkerPlugin, "version", version);
184
+ UniverRPCNodeWorkerPlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_core.IConfigService)], UniverRPCNodeWorkerPlugin);
185
+ function createNodeMessagePortOnMain(injector, path) {
186
+ const logService = injector.get(_univerjs_core.ILogService);
187
+ const child = (0, node_child_process.fork)(path);
188
+ child.on("spawn", () => logService.log("Child computing process spawned!"));
189
+ child.on("error", (error) => logService.error(error));
190
+ return [{
191
+ send(message) {
192
+ child.send(message);
193
+ },
194
+ onMessage: new rxjs.Observable((subscriber) => {
195
+ const handler = (message) => {
196
+ subscriber.next(message);
197
+ };
198
+ child.on("message", handler);
199
+ return () => child.off("message", handler);
200
+ }).pipe((0, rxjs.shareReplay)(1))
201
+ }, child];
202
+ }
203
+ function createNodeWorkerMessageProtocol() {
204
+ return {
205
+ send(message) {
206
+ node_process.default.send(message);
207
+ },
208
+ onMessage: new rxjs.Observable((subscriber) => {
209
+ const handler = (event) => {
210
+ subscriber.next(event);
211
+ };
212
+ node_process.default.on("message", handler);
213
+ return () => node_process.default.off("message", handler);
214
+ }).pipe((0, rxjs.shareReplay)(1))
215
+ };
216
+ }
217
+
218
+ //#endregion
219
+ Object.defineProperty(exports, 'UniverRPCNodeMainPlugin', {
220
+ enumerable: true,
221
+ get: function () {
222
+ return UniverRPCNodeMainPlugin;
223
+ }
224
+ });
225
+ Object.defineProperty(exports, 'UniverRPCNodeWorkerPlugin', {
226
+ enumerable: true,
227
+ get: function () {
228
+ return UniverRPCNodeWorkerPlugin;
229
+ }
230
+ });
package/lib/es/index.js CHANGED
@@ -1 +1,190 @@
1
- import{fork as e}from"node:child_process";import t from"node:process";import{IConfigService as n,ILogService as r,Inject as i,Injector as a,Plugin as o,merge as s}from"@univerjs/core";import{ChannelService as c,DataSyncPrimaryController as l,DataSyncReplicaController as u,IRPCChannelService as d,IRemoteInstanceService as f,IRemoteSyncService as p,RemoteSyncPrimaryService as m,WebWorkerRemoteInstanceService as h}from"@univerjs/rpc";import{Observable as g,shareReplay as _}from"rxjs";var v=`@univerjs/rpc-node`,y=`0.20.1`;const b=`rpc-node.main-thread.config`;Symbol(b);const x={},S=`rpc-node.worker-thread.config`;Symbol(S);const C={};function w(e){"@babel/helpers - typeof";return w=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},w(e)}function T(e,t){if(w(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(w(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function E(e){var t=T(e,`string`);return w(t)==`symbol`?t:t+``}function D(e,t,n){return(t=E(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){return function(n,r){t(n,r,e)}}function k(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let A=class extends o{constructor(e=x,t,n){super(),this._config=e,this._injector=t,this._configService=n,D(this,`_child`,null);let{...r}=s({},x,this._config);this._configService.setConfig(b,r)}onStarting(){let{workerSrc:e}=this._config;if(!e)throw Error(`[UniverRPCNodeMainPlugin] workerSrc is required for UniverRPCNodeMainPlugin`);let[t,n]=M(this._injector,e);[[d,{useFactory:()=>new c(t)}],[l],[p,{useClass:m}]].forEach(e=>this._injector.add(e)),this._injector.get(l),this._child=n}dispose(){if(super.dispose(),this._child){try{this._child.kill()}catch(e){console.error(`Failed to kill child process:`,e)}this._child=null}}};D(A,`pluginName`,`UNIVER_RPC_NODE_MAIN_PLUGIN`),D(A,`packageName`,v),D(A,`version`,y),A=k([O(1,i(a)),O(2,n)],A);let j=class extends o{constructor(e=C,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=s({},C,this._config);this._configService.setConfig(S,r)}onStarting(){[[u],[d,{useFactory:()=>new c(N())}],[f,{useClass:h}]].forEach(e=>this._injector.add(e)),this._injector.get(u)}};D(j,`pluginName`,`UNIVER_RPC_NODE_WORKER_PLUGIN`),D(j,`packageName`,v),D(j,`version`,y),j=k([O(1,i(a)),O(2,n)],j);function M(t,n){let i=t.get(r),a=e(n);return a.on(`spawn`,()=>i.log(`Child computing process spawned!`)),a.on(`error`,e=>i.error(e)),[{send(e){a.send(e)},onMessage:new g(e=>{let t=t=>{e.next(t)};return a.on(`message`,t),()=>a.off(`message`,t)}).pipe(_(1))},a]}function N(){return{send(e){t.send(e)},onMessage:new g(e=>{let n=t=>{e.next(t)};return t.on(`message`,n),()=>t.off(`message`,n)}).pipe(_(1))}}export{A as UniverRPCNodeMainPlugin,j as UniverRPCNodeWorkerPlugin};
1
+ import { fork } from "node:child_process";
2
+ import process from "node:process";
3
+ import { IConfigService, ILogService, Inject, Injector, Plugin, merge } from "@univerjs/core";
4
+ import { ChannelService, DataSyncPrimaryController, DataSyncReplicaController, IRPCChannelService, IRemoteInstanceService, IRemoteSyncService, RemoteSyncPrimaryService, WebWorkerRemoteInstanceService } from "@univerjs/rpc";
5
+ import { Observable, shareReplay } from "rxjs";
6
+
7
+ //#region package.json
8
+ var name = "@univerjs/rpc-node";
9
+ var version = "0.21.0";
10
+
11
+ //#endregion
12
+ //#region src/config/config.ts
13
+ /**
14
+ * Copyright 2023-present DreamNum Co., Ltd.
15
+ *
16
+ * Licensed under the Apache License, Version 2.0 (the "License");
17
+ * you may not use this file except in compliance with the License.
18
+ * You may obtain a copy of the License at
19
+ *
20
+ * http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing, software
23
+ * distributed under the License is distributed on an "AS IS" BASIS,
24
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ * See the License for the specific language governing permissions and
26
+ * limitations under the License.
27
+ */
28
+ const PLUGIN_CONFIG_KEY_MAIN_THREAD = "rpc-node.main-thread.config";
29
+ const configSymbolMainThread = Symbol(PLUGIN_CONFIG_KEY_MAIN_THREAD);
30
+ const defaultPluginMainThreadConfig = {};
31
+ const PLUGIN_CONFIG_KEY_WORKER_THREAD = "rpc-node.worker-thread.config";
32
+ const configSymbolWorkerThread = Symbol(PLUGIN_CONFIG_KEY_WORKER_THREAD);
33
+ const defaultPluginWorkerThreadConfig = {};
34
+
35
+ //#endregion
36
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
37
+ function _typeof(o) {
38
+ "@babel/helpers - typeof";
39
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
40
+ return typeof o;
41
+ } : function(o) {
42
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
43
+ }, _typeof(o);
44
+ }
45
+
46
+ //#endregion
47
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
48
+ function toPrimitive(t, r) {
49
+ if ("object" != _typeof(t) || !t) return t;
50
+ var e = t[Symbol.toPrimitive];
51
+ if (void 0 !== e) {
52
+ var i = e.call(t, r || "default");
53
+ if ("object" != _typeof(i)) return i;
54
+ throw new TypeError("@@toPrimitive must return a primitive value.");
55
+ }
56
+ return ("string" === r ? String : Number)(t);
57
+ }
58
+
59
+ //#endregion
60
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
61
+ function toPropertyKey(t) {
62
+ var i = toPrimitive(t, "string");
63
+ return "symbol" == _typeof(i) ? i : i + "";
64
+ }
65
+
66
+ //#endregion
67
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
68
+ function _defineProperty(e, r, t) {
69
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
70
+ value: t,
71
+ enumerable: !0,
72
+ configurable: !0,
73
+ writable: !0
74
+ }) : e[r] = t, e;
75
+ }
76
+
77
+ //#endregion
78
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
79
+ function __decorateParam(paramIndex, decorator) {
80
+ return function(target, key) {
81
+ decorator(target, key, paramIndex);
82
+ };
83
+ }
84
+
85
+ //#endregion
86
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
87
+ function __decorate(decorators, target, key, desc) {
88
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
89
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
90
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
91
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
92
+ }
93
+
94
+ //#endregion
95
+ //#region src/plugin.ts
96
+ let UniverRPCNodeMainPlugin = class UniverRPCNodeMainPlugin extends Plugin {
97
+ constructor(_config = defaultPluginMainThreadConfig, _injector, _configService) {
98
+ super();
99
+ this._config = _config;
100
+ this._injector = _injector;
101
+ this._configService = _configService;
102
+ _defineProperty(this, "_child", null);
103
+ const { ...rest } = merge({}, defaultPluginMainThreadConfig, this._config);
104
+ this._configService.setConfig(PLUGIN_CONFIG_KEY_MAIN_THREAD, rest);
105
+ }
106
+ onStarting() {
107
+ const { workerSrc } = this._config;
108
+ if (!workerSrc) throw new Error("[UniverRPCNodeMainPlugin] workerSrc is required for UniverRPCNodeMainPlugin");
109
+ const [messageProtocol, child] = createNodeMessagePortOnMain(this._injector, workerSrc);
110
+ [
111
+ [IRPCChannelService, { useFactory: () => new ChannelService(messageProtocol) }],
112
+ [DataSyncPrimaryController],
113
+ [IRemoteSyncService, { useClass: RemoteSyncPrimaryService }]
114
+ ].forEach((dependency) => this._injector.add(dependency));
115
+ this._injector.get(DataSyncPrimaryController);
116
+ this._child = child;
117
+ }
118
+ dispose() {
119
+ super.dispose();
120
+ if (this._child) {
121
+ try {
122
+ this._child.kill();
123
+ } catch (e) {
124
+ console.error("Failed to kill child process:", e);
125
+ }
126
+ this._child = null;
127
+ }
128
+ }
129
+ };
130
+ _defineProperty(UniverRPCNodeMainPlugin, "pluginName", "UNIVER_RPC_NODE_MAIN_PLUGIN");
131
+ _defineProperty(UniverRPCNodeMainPlugin, "packageName", name);
132
+ _defineProperty(UniverRPCNodeMainPlugin, "version", version);
133
+ UniverRPCNodeMainPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverRPCNodeMainPlugin);
134
+ let UniverRPCNodeWorkerPlugin = class UniverRPCNodeWorkerPlugin extends Plugin {
135
+ constructor(_config = defaultPluginWorkerThreadConfig, _injector, _configService) {
136
+ super();
137
+ this._config = _config;
138
+ this._injector = _injector;
139
+ this._configService = _configService;
140
+ const { ...rest } = merge({}, defaultPluginWorkerThreadConfig, this._config);
141
+ this._configService.setConfig(PLUGIN_CONFIG_KEY_WORKER_THREAD, rest);
142
+ }
143
+ onStarting() {
144
+ [
145
+ [DataSyncReplicaController],
146
+ [IRPCChannelService, { useFactory: () => new ChannelService(createNodeWorkerMessageProtocol()) }],
147
+ [IRemoteInstanceService, { useClass: WebWorkerRemoteInstanceService }]
148
+ ].forEach((d) => this._injector.add(d));
149
+ this._injector.get(DataSyncReplicaController);
150
+ }
151
+ };
152
+ _defineProperty(UniverRPCNodeWorkerPlugin, "pluginName", "UNIVER_RPC_NODE_WORKER_PLUGIN");
153
+ _defineProperty(UniverRPCNodeWorkerPlugin, "packageName", name);
154
+ _defineProperty(UniverRPCNodeWorkerPlugin, "version", version);
155
+ UniverRPCNodeWorkerPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverRPCNodeWorkerPlugin);
156
+ function createNodeMessagePortOnMain(injector, path) {
157
+ const logService = injector.get(ILogService);
158
+ const child = fork(path);
159
+ child.on("spawn", () => logService.log("Child computing process spawned!"));
160
+ child.on("error", (error) => logService.error(error));
161
+ return [{
162
+ send(message) {
163
+ child.send(message);
164
+ },
165
+ onMessage: new Observable((subscriber) => {
166
+ const handler = (message) => {
167
+ subscriber.next(message);
168
+ };
169
+ child.on("message", handler);
170
+ return () => child.off("message", handler);
171
+ }).pipe(shareReplay(1))
172
+ }, child];
173
+ }
174
+ function createNodeWorkerMessageProtocol() {
175
+ return {
176
+ send(message) {
177
+ process.send(message);
178
+ },
179
+ onMessage: new Observable((subscriber) => {
180
+ const handler = (event) => {
181
+ subscriber.next(event);
182
+ };
183
+ process.on("message", handler);
184
+ return () => process.off("message", handler);
185
+ }).pipe(shareReplay(1))
186
+ };
187
+ }
188
+
189
+ //#endregion
190
+ export { UniverRPCNodeMainPlugin, UniverRPCNodeWorkerPlugin };
package/lib/index.js CHANGED
@@ -1 +1,190 @@
1
- import{fork as e}from"node:child_process";import t from"node:process";import{IConfigService as n,ILogService as r,Inject as i,Injector as a,Plugin as o,merge as s}from"@univerjs/core";import{ChannelService as c,DataSyncPrimaryController as l,DataSyncReplicaController as u,IRPCChannelService as d,IRemoteInstanceService as f,IRemoteSyncService as p,RemoteSyncPrimaryService as m,WebWorkerRemoteInstanceService as h}from"@univerjs/rpc";import{Observable as g,shareReplay as _}from"rxjs";var v=`@univerjs/rpc-node`,y=`0.20.1`;const b=`rpc-node.main-thread.config`;Symbol(b);const x={},S=`rpc-node.worker-thread.config`;Symbol(S);const C={};function w(e){"@babel/helpers - typeof";return w=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},w(e)}function T(e,t){if(w(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(w(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function E(e){var t=T(e,`string`);return w(t)==`symbol`?t:t+``}function D(e,t,n){return(t=E(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){return function(n,r){t(n,r,e)}}function k(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let A=class extends o{constructor(e=x,t,n){super(),this._config=e,this._injector=t,this._configService=n,D(this,`_child`,null);let{...r}=s({},x,this._config);this._configService.setConfig(b,r)}onStarting(){let{workerSrc:e}=this._config;if(!e)throw Error(`[UniverRPCNodeMainPlugin] workerSrc is required for UniverRPCNodeMainPlugin`);let[t,n]=M(this._injector,e);[[d,{useFactory:()=>new c(t)}],[l],[p,{useClass:m}]].forEach(e=>this._injector.add(e)),this._injector.get(l),this._child=n}dispose(){if(super.dispose(),this._child){try{this._child.kill()}catch(e){console.error(`Failed to kill child process:`,e)}this._child=null}}};D(A,`pluginName`,`UNIVER_RPC_NODE_MAIN_PLUGIN`),D(A,`packageName`,v),D(A,`version`,y),A=k([O(1,i(a)),O(2,n)],A);let j=class extends o{constructor(e=C,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=s({},C,this._config);this._configService.setConfig(S,r)}onStarting(){[[u],[d,{useFactory:()=>new c(N())}],[f,{useClass:h}]].forEach(e=>this._injector.add(e)),this._injector.get(u)}};D(j,`pluginName`,`UNIVER_RPC_NODE_WORKER_PLUGIN`),D(j,`packageName`,v),D(j,`version`,y),j=k([O(1,i(a)),O(2,n)],j);function M(t,n){let i=t.get(r),a=e(n);return a.on(`spawn`,()=>i.log(`Child computing process spawned!`)),a.on(`error`,e=>i.error(e)),[{send(e){a.send(e)},onMessage:new g(e=>{let t=t=>{e.next(t)};return a.on(`message`,t),()=>a.off(`message`,t)}).pipe(_(1))},a]}function N(){return{send(e){t.send(e)},onMessage:new g(e=>{let n=t=>{e.next(t)};return t.on(`message`,n),()=>t.off(`message`,n)}).pipe(_(1))}}export{A as UniverRPCNodeMainPlugin,j as UniverRPCNodeWorkerPlugin};
1
+ import { fork } from "node:child_process";
2
+ import process from "node:process";
3
+ import { IConfigService, ILogService, Inject, Injector, Plugin, merge } from "@univerjs/core";
4
+ import { ChannelService, DataSyncPrimaryController, DataSyncReplicaController, IRPCChannelService, IRemoteInstanceService, IRemoteSyncService, RemoteSyncPrimaryService, WebWorkerRemoteInstanceService } from "@univerjs/rpc";
5
+ import { Observable, shareReplay } from "rxjs";
6
+
7
+ //#region package.json
8
+ var name = "@univerjs/rpc-node";
9
+ var version = "0.21.0";
10
+
11
+ //#endregion
12
+ //#region src/config/config.ts
13
+ /**
14
+ * Copyright 2023-present DreamNum Co., Ltd.
15
+ *
16
+ * Licensed under the Apache License, Version 2.0 (the "License");
17
+ * you may not use this file except in compliance with the License.
18
+ * You may obtain a copy of the License at
19
+ *
20
+ * http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing, software
23
+ * distributed under the License is distributed on an "AS IS" BASIS,
24
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ * See the License for the specific language governing permissions and
26
+ * limitations under the License.
27
+ */
28
+ const PLUGIN_CONFIG_KEY_MAIN_THREAD = "rpc-node.main-thread.config";
29
+ const configSymbolMainThread = Symbol(PLUGIN_CONFIG_KEY_MAIN_THREAD);
30
+ const defaultPluginMainThreadConfig = {};
31
+ const PLUGIN_CONFIG_KEY_WORKER_THREAD = "rpc-node.worker-thread.config";
32
+ const configSymbolWorkerThread = Symbol(PLUGIN_CONFIG_KEY_WORKER_THREAD);
33
+ const defaultPluginWorkerThreadConfig = {};
34
+
35
+ //#endregion
36
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
37
+ function _typeof(o) {
38
+ "@babel/helpers - typeof";
39
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
40
+ return typeof o;
41
+ } : function(o) {
42
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
43
+ }, _typeof(o);
44
+ }
45
+
46
+ //#endregion
47
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
48
+ function toPrimitive(t, r) {
49
+ if ("object" != _typeof(t) || !t) return t;
50
+ var e = t[Symbol.toPrimitive];
51
+ if (void 0 !== e) {
52
+ var i = e.call(t, r || "default");
53
+ if ("object" != _typeof(i)) return i;
54
+ throw new TypeError("@@toPrimitive must return a primitive value.");
55
+ }
56
+ return ("string" === r ? String : Number)(t);
57
+ }
58
+
59
+ //#endregion
60
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
61
+ function toPropertyKey(t) {
62
+ var i = toPrimitive(t, "string");
63
+ return "symbol" == _typeof(i) ? i : i + "";
64
+ }
65
+
66
+ //#endregion
67
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
68
+ function _defineProperty(e, r, t) {
69
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
70
+ value: t,
71
+ enumerable: !0,
72
+ configurable: !0,
73
+ writable: !0
74
+ }) : e[r] = t, e;
75
+ }
76
+
77
+ //#endregion
78
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
79
+ function __decorateParam(paramIndex, decorator) {
80
+ return function(target, key) {
81
+ decorator(target, key, paramIndex);
82
+ };
83
+ }
84
+
85
+ //#endregion
86
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
87
+ function __decorate(decorators, target, key, desc) {
88
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
89
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
90
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
91
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
92
+ }
93
+
94
+ //#endregion
95
+ //#region src/plugin.ts
96
+ let UniverRPCNodeMainPlugin = class UniverRPCNodeMainPlugin extends Plugin {
97
+ constructor(_config = defaultPluginMainThreadConfig, _injector, _configService) {
98
+ super();
99
+ this._config = _config;
100
+ this._injector = _injector;
101
+ this._configService = _configService;
102
+ _defineProperty(this, "_child", null);
103
+ const { ...rest } = merge({}, defaultPluginMainThreadConfig, this._config);
104
+ this._configService.setConfig(PLUGIN_CONFIG_KEY_MAIN_THREAD, rest);
105
+ }
106
+ onStarting() {
107
+ const { workerSrc } = this._config;
108
+ if (!workerSrc) throw new Error("[UniverRPCNodeMainPlugin] workerSrc is required for UniverRPCNodeMainPlugin");
109
+ const [messageProtocol, child] = createNodeMessagePortOnMain(this._injector, workerSrc);
110
+ [
111
+ [IRPCChannelService, { useFactory: () => new ChannelService(messageProtocol) }],
112
+ [DataSyncPrimaryController],
113
+ [IRemoteSyncService, { useClass: RemoteSyncPrimaryService }]
114
+ ].forEach((dependency) => this._injector.add(dependency));
115
+ this._injector.get(DataSyncPrimaryController);
116
+ this._child = child;
117
+ }
118
+ dispose() {
119
+ super.dispose();
120
+ if (this._child) {
121
+ try {
122
+ this._child.kill();
123
+ } catch (e) {
124
+ console.error("Failed to kill child process:", e);
125
+ }
126
+ this._child = null;
127
+ }
128
+ }
129
+ };
130
+ _defineProperty(UniverRPCNodeMainPlugin, "pluginName", "UNIVER_RPC_NODE_MAIN_PLUGIN");
131
+ _defineProperty(UniverRPCNodeMainPlugin, "packageName", name);
132
+ _defineProperty(UniverRPCNodeMainPlugin, "version", version);
133
+ UniverRPCNodeMainPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverRPCNodeMainPlugin);
134
+ let UniverRPCNodeWorkerPlugin = class UniverRPCNodeWorkerPlugin extends Plugin {
135
+ constructor(_config = defaultPluginWorkerThreadConfig, _injector, _configService) {
136
+ super();
137
+ this._config = _config;
138
+ this._injector = _injector;
139
+ this._configService = _configService;
140
+ const { ...rest } = merge({}, defaultPluginWorkerThreadConfig, this._config);
141
+ this._configService.setConfig(PLUGIN_CONFIG_KEY_WORKER_THREAD, rest);
142
+ }
143
+ onStarting() {
144
+ [
145
+ [DataSyncReplicaController],
146
+ [IRPCChannelService, { useFactory: () => new ChannelService(createNodeWorkerMessageProtocol()) }],
147
+ [IRemoteInstanceService, { useClass: WebWorkerRemoteInstanceService }]
148
+ ].forEach((d) => this._injector.add(d));
149
+ this._injector.get(DataSyncReplicaController);
150
+ }
151
+ };
152
+ _defineProperty(UniverRPCNodeWorkerPlugin, "pluginName", "UNIVER_RPC_NODE_WORKER_PLUGIN");
153
+ _defineProperty(UniverRPCNodeWorkerPlugin, "packageName", name);
154
+ _defineProperty(UniverRPCNodeWorkerPlugin, "version", version);
155
+ UniverRPCNodeWorkerPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverRPCNodeWorkerPlugin);
156
+ function createNodeMessagePortOnMain(injector, path) {
157
+ const logService = injector.get(ILogService);
158
+ const child = fork(path);
159
+ child.on("spawn", () => logService.log("Child computing process spawned!"));
160
+ child.on("error", (error) => logService.error(error));
161
+ return [{
162
+ send(message) {
163
+ child.send(message);
164
+ },
165
+ onMessage: new Observable((subscriber) => {
166
+ const handler = (message) => {
167
+ subscriber.next(message);
168
+ };
169
+ child.on("message", handler);
170
+ return () => child.off("message", handler);
171
+ }).pipe(shareReplay(1))
172
+ }, child];
173
+ }
174
+ function createNodeWorkerMessageProtocol() {
175
+ return {
176
+ send(message) {
177
+ process.send(message);
178
+ },
179
+ onMessage: new Observable((subscriber) => {
180
+ const handler = (event) => {
181
+ subscriber.next(event);
182
+ };
183
+ process.on("message", handler);
184
+ return () => process.off("message", handler);
185
+ }).pipe(shareReplay(1))
186
+ };
187
+ }
188
+
189
+ //#endregion
190
+ export { UniverRPCNodeMainPlugin, UniverRPCNodeWorkerPlugin };
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`node:child_process`),require(`node:process`),require(`@univerjs/core`),require(`@univerjs/rpc`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`node:child_process`,`node:process`,`@univerjs/core`,`@univerjs/rpc`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverRpcNode={},e[`Node:child_process`],e[`Node:process`],e.UniverCore,e.UniverRpc,e.rxjs))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=Object.create,s=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,u=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty,f=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=l(t),a=0,o=i.length,u;a<o;a++)u=i[a],!d.call(e,u)&&u!==n&&s(e,u,{get:(e=>t[e]).bind(null,u),enumerable:!(r=c(t,u))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:o(u(e)),f(t||!e||!e.__esModule?s(n,`default`,{value:e,enumerable:!0}):n,e)))(n);var p=`@univerjs/rpc-node`,m=`0.20.1`;let h=`rpc-node.main-thread.config`;Symbol(h);let g={},_=`rpc-node.worker-thread.config`;Symbol(_);let v={};function y(e){"@babel/helpers - typeof";return y=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},y(e)}function b(e,t){if(y(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(y(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function x(e){var t=b(e,`string`);return y(t)==`symbol`?t:t+``}function S(e,t,n){return(t=x(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function C(e,t){return function(n,r){t(n,r,e)}}function w(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let T=class extends r.Plugin{constructor(e=g,t,n){super(),this._config=e,this._injector=t,this._configService=n,S(this,`_child`,null);let{...i}=(0,r.merge)({},g,this._config);this._configService.setConfig(h,i)}onStarting(){let{workerSrc:e}=this._config;if(!e)throw Error(`[UniverRPCNodeMainPlugin] workerSrc is required for UniverRPCNodeMainPlugin`);let[t,n]=D(this._injector,e);[[i.IRPCChannelService,{useFactory:()=>new i.ChannelService(t)}],[i.DataSyncPrimaryController],[i.IRemoteSyncService,{useClass:i.RemoteSyncPrimaryService}]].forEach(e=>this._injector.add(e)),this._injector.get(i.DataSyncPrimaryController),this._child=n}dispose(){if(super.dispose(),this._child){try{this._child.kill()}catch(e){console.error(`Failed to kill child process:`,e)}this._child=null}}};S(T,`pluginName`,`UNIVER_RPC_NODE_MAIN_PLUGIN`),S(T,`packageName`,p),S(T,`version`,m),T=w([C(1,(0,r.Inject)(r.Injector)),C(2,r.IConfigService)],T);let E=class extends r.Plugin{constructor(e=v,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...i}=(0,r.merge)({},v,this._config);this._configService.setConfig(_,i)}onStarting(){[[i.DataSyncReplicaController],[i.IRPCChannelService,{useFactory:()=>new i.ChannelService(O())}],[i.IRemoteInstanceService,{useClass:i.WebWorkerRemoteInstanceService}]].forEach(e=>this._injector.add(e)),this._injector.get(i.DataSyncReplicaController)}};S(E,`pluginName`,`UNIVER_RPC_NODE_WORKER_PLUGIN`),S(E,`packageName`,p),S(E,`version`,m),E=w([C(1,(0,r.Inject)(r.Injector)),C(2,r.IConfigService)],E);function D(e,n){let i=e.get(r.ILogService),o=(0,t.fork)(n);return o.on(`spawn`,()=>i.log(`Child computing process spawned!`)),o.on(`error`,e=>i.error(e)),[{send(e){o.send(e)},onMessage:new a.Observable(e=>{let t=t=>{e.next(t)};return o.on(`message`,t),()=>o.off(`message`,t)}).pipe((0,a.shareReplay)(1))},o]}function O(){return{send(e){n.default.send(e)},onMessage:new a.Observable(e=>{let t=t=>{e.next(t)};return n.default.on(`message`,t),()=>n.default.off(`message`,t)}).pipe((0,a.shareReplay)(1))}}Object.defineProperty(e,`UniverRPCNodeMainPlugin`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(e,`UniverRPCNodeWorkerPlugin`,{enumerable:!0,get:function(){return E}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`node:child_process`),require(`node:process`),require(`@univerjs/core`),require(`@univerjs/rpc`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`node:child_process`,`node:process`,`@univerjs/core`,`@univerjs/rpc`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverRpcNode={},e[`Node:child_process`],e[`Node:process`],e.UniverCore,e.UniverRpc,e.rxjs))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=Object.create,s=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,u=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty,f=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=l(t),a=0,o=i.length,u;a<o;a++)u=i[a],!d.call(e,u)&&u!==n&&s(e,u,{get:(e=>t[e]).bind(null,u),enumerable:!(r=c(t,u))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:o(u(e)),f(t||!e||!e.__esModule?s(n,`default`,{value:e,enumerable:!0}):n,e)))(n);var p=`@univerjs/rpc-node`,m=`0.21.0`;let h=`rpc-node.main-thread.config`;Symbol(h);let g={},_=`rpc-node.worker-thread.config`;Symbol(_);let v={};function y(e){"@babel/helpers - typeof";return y=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},y(e)}function b(e,t){if(y(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(y(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function x(e){var t=b(e,`string`);return y(t)==`symbol`?t:t+``}function S(e,t,n){return(t=x(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function C(e,t){return function(n,r){t(n,r,e)}}function w(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let T=class extends r.Plugin{constructor(e=g,t,n){super(),this._config=e,this._injector=t,this._configService=n,S(this,`_child`,null);let{...i}=(0,r.merge)({},g,this._config);this._configService.setConfig(h,i)}onStarting(){let{workerSrc:e}=this._config;if(!e)throw Error(`[UniverRPCNodeMainPlugin] workerSrc is required for UniverRPCNodeMainPlugin`);let[t,n]=D(this._injector,e);[[i.IRPCChannelService,{useFactory:()=>new i.ChannelService(t)}],[i.DataSyncPrimaryController],[i.IRemoteSyncService,{useClass:i.RemoteSyncPrimaryService}]].forEach(e=>this._injector.add(e)),this._injector.get(i.DataSyncPrimaryController),this._child=n}dispose(){if(super.dispose(),this._child){try{this._child.kill()}catch(e){console.error(`Failed to kill child process:`,e)}this._child=null}}};S(T,`pluginName`,`UNIVER_RPC_NODE_MAIN_PLUGIN`),S(T,`packageName`,p),S(T,`version`,m),T=w([C(1,(0,r.Inject)(r.Injector)),C(2,r.IConfigService)],T);let E=class extends r.Plugin{constructor(e=v,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...i}=(0,r.merge)({},v,this._config);this._configService.setConfig(_,i)}onStarting(){[[i.DataSyncReplicaController],[i.IRPCChannelService,{useFactory:()=>new i.ChannelService(O())}],[i.IRemoteInstanceService,{useClass:i.WebWorkerRemoteInstanceService}]].forEach(e=>this._injector.add(e)),this._injector.get(i.DataSyncReplicaController)}};S(E,`pluginName`,`UNIVER_RPC_NODE_WORKER_PLUGIN`),S(E,`packageName`,p),S(E,`version`,m),E=w([C(1,(0,r.Inject)(r.Injector)),C(2,r.IConfigService)],E);function D(e,n){let i=e.get(r.ILogService),o=(0,t.fork)(n);return o.on(`spawn`,()=>i.log(`Child computing process spawned!`)),o.on(`error`,e=>i.error(e)),[{send(e){o.send(e)},onMessage:new a.Observable(e=>{let t=t=>{e.next(t)};return o.on(`message`,t),()=>o.off(`message`,t)}).pipe((0,a.shareReplay)(1))},o]}function O(){return{send(e){n.default.send(e)},onMessage:new a.Observable(e=>{let t=t=>{e.next(t)};return n.default.on(`message`,t),()=>n.default.off(`message`,t)}).pipe((0,a.shareReplay)(1))}}Object.defineProperty(e,`UniverRPCNodeMainPlugin`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(e,`UniverRPCNodeWorkerPlugin`,{enumerable:!0,get:function(){return E}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/rpc-node",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -46,14 +46,14 @@
46
46
  "rxjs": ">=7.0.0"
47
47
  },
48
48
  "dependencies": {
49
- "@univerjs/core": "0.20.1",
50
- "@univerjs/rpc": "0.20.1"
49
+ "@univerjs/core": "0.21.0",
50
+ "@univerjs/rpc": "0.21.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "rxjs": "^7.8.2",
54
54
  "typescript": "^6.0.2",
55
- "vitest": "^4.1.1",
56
- "@univerjs-infra/shared": "0.20.1"
55
+ "vitest": "^4.1.4",
56
+ "@univerjs-infra/shared": "0.21.0"
57
57
  },
58
58
  "scripts": {
59
59
  "test": "vitest run",