@univerjs/rpc-node 0.4.1-nightly.202410291304

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/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # @univerjs/rpc-node
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@univerjs/rpc-node)](https://npmjs.org/packages/@univerjs/rpc-node)
4
+ [![license](https://img.shields.io/npm/l/@univerjs/rpc-node)](https://img.shields.io/npm/l/@univerjs/rpc-node)
5
+
6
+ ## Introduction
7
+
8
+ > TODO: Introduction
9
+
10
+ ## Usage
11
+
12
+ ### Installation
13
+
14
+ ```shell
15
+ npm i @univerjs/rpc-node
16
+ ```
@@ -0,0 +1 @@
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 node_child_process=require("node:child_process"),process=require("node:process"),core=require("@univerjs/core"),rpc=require("@univerjs/rpc"),rxjs=require("rxjs");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");const UNIVER_RPC_NODE_MAIN_PLUGIN_CONFIG_KEY="node-rpc.main.config";var _a;exports.UniverRPCNodeMainPlugin=(_a=class extends core.Plugin{constructor(_config,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService,this._configService.setConfig(UNIVER_RPC_NODE_MAIN_PLUGIN_CONFIG_KEY,this._config)}onStarting(){const{workerSrc}=this._config,messageProtocol=createNodeMessagePortOnMain(this._injector,workerSrc);[[rpc.IRPCChannelService,{useFactory:__name(()=>new rpc.ChannelService(messageProtocol),"useFactory")}],[rpc.DataSyncPrimaryController],[rpc.IRemoteSyncService,{useClass:rpc.RemoteSyncPrimaryService}]].forEach(dependency=>this._injector.add(dependency)),this._injector.get(rpc.DataSyncPrimaryController)}},__name(_a,"UniverRPCNodeMainPlugin"),__publicField(_a,"pluginName","UNIVER_RPC_NODE_MAIN_PLUGIN"),_a);exports.UniverRPCNodeMainPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverRPCNodeMainPlugin);var _a2;exports.UniverRPCNodeWorkerPlugin=(_a2=class extends core.Plugin{constructor(_config,_injector){super(),this._config=_config,this._injector=_injector}onStarting(){[[rpc.DataSyncReplicaController],[rpc.IRPCChannelService,{useFactory:__name(()=>new rpc.ChannelService(createNodeWorkerMessageProtocol()),"useFactory")}],[rpc.IRemoteInstanceService,{useClass:rpc.WebWorkerRemoteInstanceService}]].forEach(d=>this._injector.add(d)),this._injector.get(rpc.DataSyncReplicaController)}},__name(_a2,"UniverRPCNodeWorkerPlugin"),__publicField(_a2,"pluginName","UNIVER_RPC_NODE_WORKER_PLUGIN"),_a2);exports.UniverRPCNodeWorkerPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector))],exports.UniverRPCNodeWorkerPlugin);function createNodeMessagePortOnMain(injector,path){const logService=injector.get(core.ILogService),child=node_child_process.fork(path);return child.on("spawn",()=>logService.log("Child computing process spawned!")),child.on("error",error=>logService.error(error)),{send(message){child.send(message)},onMessage:new rxjs.Observable(subscriber=>{const handler=__name(message=>{subscriber.next(message)},"handler");return child.on("message",handler),()=>child.off("message",handler)}).pipe(rxjs.shareReplay(1))}}__name(createNodeMessagePortOnMain,"createNodeMessagePortOnMain");function createNodeWorkerMessageProtocol(){return{send(message){process.send(message)},onMessage:new rxjs.Observable(subscriber=>{const handler=__name(event=>{subscriber.next(event)},"handler");return process.on("message",handler),()=>process.off("message",handler)}).pipe(rxjs.shareReplay(1))}}__name(createNodeWorkerMessageProtocol,"createNodeWorkerMessageProtocol");
@@ -0,0 +1,86 @@
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 { fork } from "node:child_process";
6
+ import process from "node:process";
7
+ import { Inject, Injector, Plugin, IConfigService, ILogService } from "@univerjs/core";
8
+ import { DataSyncPrimaryController, DataSyncReplicaController, IRPCChannelService, ChannelService, IRemoteInstanceService, WebWorkerRemoteInstanceService, IRemoteSyncService, RemoteSyncPrimaryService } from "@univerjs/rpc";
9
+ import { Observable, shareReplay } from "rxjs";
10
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
11
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
12
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
13
+ return kind && result && __defProp2(target, key, result), result;
14
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam");
15
+ const UNIVER_RPC_NODE_MAIN_PLUGIN_CONFIG_KEY = "node-rpc.main.config";
16
+ var _a;
17
+ let UniverRPCNodeMainPlugin = (_a = class extends Plugin {
18
+ constructor(_config, _injector, _configService) {
19
+ super(), this._config = _config, this._injector = _injector, this._configService = _configService, this._configService.setConfig(UNIVER_RPC_NODE_MAIN_PLUGIN_CONFIG_KEY, this._config);
20
+ }
21
+ onStarting() {
22
+ const { workerSrc } = this._config, messageProtocol = createNodeMessagePortOnMain(this._injector, workerSrc);
23
+ [
24
+ [IRPCChannelService, {
25
+ useFactory: /* @__PURE__ */ __name(() => new ChannelService(messageProtocol), "useFactory")
26
+ }],
27
+ [DataSyncPrimaryController],
28
+ [IRemoteSyncService, { useClass: RemoteSyncPrimaryService }]
29
+ ].forEach((dependency) => this._injector.add(dependency)), this._injector.get(DataSyncPrimaryController);
30
+ }
31
+ }, __name(_a, "UniverRPCNodeMainPlugin"), __publicField(_a, "pluginName", "UNIVER_RPC_NODE_MAIN_PLUGIN"), _a);
32
+ UniverRPCNodeMainPlugin = __decorateClass([
33
+ __decorateParam(1, Inject(Injector)),
34
+ __decorateParam(2, IConfigService)
35
+ ], UniverRPCNodeMainPlugin);
36
+ var _a2;
37
+ let UniverRPCNodeWorkerPlugin = (_a2 = class extends Plugin {
38
+ constructor(_config, _injector) {
39
+ super(), this._config = _config, this._injector = _injector;
40
+ }
41
+ onStarting() {
42
+ [
43
+ [DataSyncReplicaController],
44
+ [IRPCChannelService, {
45
+ useFactory: /* @__PURE__ */ __name(() => new ChannelService(createNodeWorkerMessageProtocol()), "useFactory")
46
+ }],
47
+ [IRemoteInstanceService, { useClass: WebWorkerRemoteInstanceService }]
48
+ ].forEach((d) => this._injector.add(d)), this._injector.get(DataSyncReplicaController);
49
+ }
50
+ }, __name(_a2, "UniverRPCNodeWorkerPlugin"), __publicField(_a2, "pluginName", "UNIVER_RPC_NODE_WORKER_PLUGIN"), _a2);
51
+ UniverRPCNodeWorkerPlugin = __decorateClass([
52
+ __decorateParam(1, Inject(Injector))
53
+ ], UniverRPCNodeWorkerPlugin);
54
+ function createNodeMessagePortOnMain(injector, path) {
55
+ const logService = injector.get(ILogService), child = fork(path);
56
+ return child.on("spawn", () => logService.log("Child computing process spawned!")), child.on("error", (error) => logService.error(error)), {
57
+ send(message) {
58
+ child.send(message);
59
+ },
60
+ onMessage: new Observable((subscriber) => {
61
+ const handler = /* @__PURE__ */ __name((message) => {
62
+ subscriber.next(message);
63
+ }, "handler");
64
+ return child.on("message", handler), () => child.off("message", handler);
65
+ }).pipe(shareReplay(1))
66
+ };
67
+ }
68
+ __name(createNodeMessagePortOnMain, "createNodeMessagePortOnMain");
69
+ function createNodeWorkerMessageProtocol() {
70
+ return {
71
+ send(message) {
72
+ process.send(message);
73
+ },
74
+ onMessage: new Observable((subscriber) => {
75
+ const handler = /* @__PURE__ */ __name((event) => {
76
+ subscriber.next(event);
77
+ }, "handler");
78
+ return process.on("message", handler), () => process.off("message", handler);
79
+ }).pipe(shareReplay(1))
80
+ };
81
+ }
82
+ __name(createNodeWorkerMessageProtocol, "createNodeWorkerMessageProtocol");
83
+ export {
84
+ UniverRPCNodeMainPlugin,
85
+ UniverRPCNodeWorkerPlugin
86
+ };
@@ -0,0 +1,16 @@
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 { UniverRPCNodeMainPlugin, UniverRPCNodeWorkerPlugin } from './plugin';
@@ -0,0 +1,20 @@
1
+ import { IConfigService, Injector, Plugin } from '@univerjs/core';
2
+ export interface IUniverRPCNodeMainConfig {
3
+ /** Path of the computing worker scripts. */
4
+ workerSrc: string;
5
+ }
6
+ export declare class UniverRPCNodeMainPlugin extends Plugin {
7
+ private readonly _config;
8
+ protected readonly _injector: Injector;
9
+ private readonly _configService;
10
+ static pluginName: string;
11
+ constructor(_config: IUniverRPCNodeMainConfig, _injector: Injector, _configService: IConfigService);
12
+ onStarting(): void;
13
+ }
14
+ export declare class UniverRPCNodeWorkerPlugin extends Plugin {
15
+ private readonly _config;
16
+ protected readonly _injector: Injector;
17
+ static pluginName: string;
18
+ constructor(_config: undefined, _injector: Injector);
19
+ onStarting(): void;
20
+ }
@@ -0,0 +1 @@
1
+ (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(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"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverRpcNode={},global.node_child_process,global.process,global.UniverCore,global.UniverRpc,global.rxjs))})(this,function(exports2,node_child_process,process,core,rpc,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;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");const UNIVER_RPC_NODE_MAIN_PLUGIN_CONFIG_KEY="node-rpc.main.config";exports2.UniverRPCNodeMainPlugin=(_a=class extends core.Plugin{constructor(_config,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService,this._configService.setConfig(UNIVER_RPC_NODE_MAIN_PLUGIN_CONFIG_KEY,this._config)}onStarting(){const{workerSrc}=this._config,messageProtocol=createNodeMessagePortOnMain(this._injector,workerSrc);[[rpc.IRPCChannelService,{useFactory:__name(()=>new rpc.ChannelService(messageProtocol),"useFactory")}],[rpc.DataSyncPrimaryController],[rpc.IRemoteSyncService,{useClass:rpc.RemoteSyncPrimaryService}]].forEach(dependency=>this._injector.add(dependency)),this._injector.get(rpc.DataSyncPrimaryController)}},__name(_a,"UniverRPCNodeMainPlugin"),__publicField(_a,"pluginName","UNIVER_RPC_NODE_MAIN_PLUGIN"),_a),exports2.UniverRPCNodeMainPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverRPCNodeMainPlugin),exports2.UniverRPCNodeWorkerPlugin=(_b=class extends core.Plugin{constructor(_config,_injector){super(),this._config=_config,this._injector=_injector}onStarting(){[[rpc.DataSyncReplicaController],[rpc.IRPCChannelService,{useFactory:__name(()=>new rpc.ChannelService(createNodeWorkerMessageProtocol()),"useFactory")}],[rpc.IRemoteInstanceService,{useClass:rpc.WebWorkerRemoteInstanceService}]].forEach(d=>this._injector.add(d)),this._injector.get(rpc.DataSyncReplicaController)}},__name(_b,"UniverRPCNodeWorkerPlugin"),__publicField(_b,"pluginName","UNIVER_RPC_NODE_WORKER_PLUGIN"),_b),exports2.UniverRPCNodeWorkerPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector))],exports2.UniverRPCNodeWorkerPlugin);function createNodeMessagePortOnMain(injector,path){const logService=injector.get(core.ILogService),child=node_child_process.fork(path);return child.on("spawn",()=>logService.log("Child computing process spawned!")),child.on("error",error=>logService.error(error)),{send(message){child.send(message)},onMessage:new rxjs.Observable(subscriber=>{const handler=__name(message=>{subscriber.next(message)},"handler");return child.on("message",handler),()=>child.off("message",handler)}).pipe(rxjs.shareReplay(1))}}__name(createNodeMessagePortOnMain,"createNodeMessagePortOnMain");function createNodeWorkerMessageProtocol(){return{send(message){process.send(message)},onMessage:new rxjs.Observable(subscriber=>{const handler=__name(event=>{subscriber.next(event)},"handler");return process.on("message",handler),()=>process.off("message",handler)}).pipe(rxjs.shareReplay(1))}}__name(createNodeWorkerMessageProtocol,"createNodeWorkerMessageProtocol"),Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@univerjs/rpc-node",
3
+ "version": "0.4.1-nightly.202410291304",
4
+ "private": false,
5
+ "description": "",
6
+ "author": "DreamNum <developer@univer.ai>",
7
+ "license": "Apache-2.0",
8
+ "funding": {
9
+ "type": "opencollective",
10
+ "url": "https://opencollective.com/univer"
11
+ },
12
+ "homepage": "https://univer.ai",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/dream-num/univer"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/dream-num/univer/issues"
19
+ },
20
+ "keywords": [],
21
+ "exports": {
22
+ ".": {
23
+ "import": "./lib/es/index.js",
24
+ "require": "./lib/cjs/index.js",
25
+ "types": "./lib/types/index.d.ts"
26
+ },
27
+ "./*": {
28
+ "import": "./lib/es/*",
29
+ "require": "./lib/cjs/*",
30
+ "types": "./lib/types/index.d.ts"
31
+ },
32
+ "./lib/*": "./lib/*"
33
+ },
34
+ "main": "./lib/cjs/index.js",
35
+ "module": "./lib/es/index.js",
36
+ "types": "./lib/types/index.d.ts",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "directories": {
41
+ "lib": "lib"
42
+ },
43
+ "files": [
44
+ "lib"
45
+ ],
46
+ "peerDependencies": {
47
+ "rxjs": ">=7.0.0"
48
+ },
49
+ "dependencies": {
50
+ "rxjs": "^7.8.1",
51
+ "@univerjs/core": "0.4.1-nightly.202410291304",
52
+ "@univerjs/rpc": "0.4.1-nightly.202410291304"
53
+ },
54
+ "devDependencies": {
55
+ "typescript": "^5.6.3",
56
+ "vite": "^5.4.8",
57
+ "vitest": "^2.1.2",
58
+ "@univerjs-infra/shared": "0.4.1",
59
+ "@univerjs/rpc": "0.4.1-nightly.202410291304",
60
+ "@univerjs/core": "0.4.1-nightly.202410291304"
61
+ },
62
+ "univerSpace": {
63
+ ".": {
64
+ "import": "./lib/es/index.js",
65
+ "require": "./lib/cjs/index.js",
66
+ "types": "./lib/types/index.d.ts"
67
+ },
68
+ "./*": {
69
+ "import": "./lib/es/*",
70
+ "require": "./lib/cjs/*",
71
+ "types": "./lib/types/index.d.ts"
72
+ },
73
+ "./lib/*": "./lib/*"
74
+ },
75
+ "scripts": {
76
+ "test": "vitest run",
77
+ "test:watch": "vitest",
78
+ "coverage": "vitest run --coverage",
79
+ "lint:types": "tsc --noEmit",
80
+ "build": "tsc && vite build"
81
+ }
82
+ }