@univerjs/rpc 1.0.0-insiders.20260813-7c9aa50 → 1.0.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/LICENSE +176 -0
- package/README.md +5 -2
- package/lib/cjs/index.js +93 -53
- package/lib/es/index.js +94 -54
- package/lib/index.js +94 -54
- package/lib/types/controllers/data-sync/data-sync-primary.controller.d.ts +9 -3
- package/lib/types/services/remote-instance/remote-instance.service.d.ts +3 -2
- package/lib/types/services/rpc/rpc.service.d.ts +3 -0
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -27,9 +27,13 @@ Keep all `@univerjs/*` packages on the same version.
|
|
|
27
27
|
```ts
|
|
28
28
|
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
const worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });
|
|
31
|
+
univer.registerPlugin(UniverRPCMainThreadPlugin, { workerURL: worker });
|
|
32
|
+
univer.onDispose(() => worker.terminate());
|
|
31
33
|
```
|
|
32
34
|
|
|
35
|
+
The referenced worker module must create its own Univer instance and register `UniverRPCWorkerThreadPlugin`; see the [browser worker example](../../examples/src/sheets-mobile/worker.ts).
|
|
36
|
+
|
|
33
37
|
Exported plugin classes:
|
|
34
38
|
|
|
35
39
|
- `UniverRPCMainThreadPlugin`
|
|
@@ -40,4 +44,3 @@ Exported plugin classes:
|
|
|
40
44
|
- [Documentation](https://docs.univer.ai)
|
|
41
45
|
- [NPM package](https://npmjs.com/package/@univerjs/rpc)
|
|
42
46
|
- [GitHub repository](https://github.com/dream-num/univer)
|
|
43
|
-
|
package/lib/cjs/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const configSymbolWorkerThread = Symbol(PLUGIN_CONFIG_KEY_WORKER_THREAD);
|
|
|
27
27
|
const defaultPluginWorkerThreadConfig = {};
|
|
28
28
|
|
|
29
29
|
//#endregion
|
|
30
|
-
//#region \0@oxc-project+runtime@0.
|
|
30
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
|
|
31
31
|
function __decorateParam(paramIndex, decorator) {
|
|
32
32
|
return function(target, key) {
|
|
33
33
|
decorator(target, key, paramIndex);
|
|
@@ -35,7 +35,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
//#endregion
|
|
38
|
-
//#region \0@oxc-project+runtime@0.
|
|
38
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
|
|
39
39
|
function __decorate(decorators, target, key, desc) {
|
|
40
40
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
41
41
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -75,13 +75,15 @@ const RemoteInstanceServiceName = "univer.remote-instance-service";
|
|
|
75
75
|
*/
|
|
76
76
|
const IRemoteInstanceService = (0, _univerjs_core.createIdentifier)(RemoteInstanceServiceName);
|
|
77
77
|
let WebWorkerRemoteInstanceService = class WebWorkerRemoteInstanceService {
|
|
78
|
-
constructor(_univerInstanceService, _commandService, _logService) {
|
|
78
|
+
constructor(_univerInstanceService, _commandService, _logService, _lifecycleService) {
|
|
79
79
|
this._univerInstanceService = _univerInstanceService;
|
|
80
80
|
this._commandService = _commandService;
|
|
81
81
|
this._logService = _logService;
|
|
82
|
+
this._lifecycleService = _lifecycleService;
|
|
82
83
|
}
|
|
83
84
|
whenReady() {
|
|
84
|
-
return Promise.resolve(true);
|
|
85
|
+
if (this._lifecycleService.stage >= _univerjs_core.LifecycleStages.Ready) return Promise.resolve(true);
|
|
86
|
+
return this._lifecycleService.onStage(_univerjs_core.LifecycleStages.Ready).then(() => true);
|
|
85
87
|
}
|
|
86
88
|
async syncMutation(params, options) {
|
|
87
89
|
return this._applyMutation(params.mutationInfo, options);
|
|
@@ -121,11 +123,12 @@ let WebWorkerRemoteInstanceService = class WebWorkerRemoteInstanceService {
|
|
|
121
123
|
WebWorkerRemoteInstanceService = __decorate([
|
|
122
124
|
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
123
125
|
__decorateParam(1, _univerjs_core.ICommandService),
|
|
124
|
-
__decorateParam(2, _univerjs_core.ILogService)
|
|
126
|
+
__decorateParam(2, _univerjs_core.ILogService),
|
|
127
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.LifecycleService))
|
|
125
128
|
], WebWorkerRemoteInstanceService);
|
|
126
129
|
|
|
127
130
|
//#endregion
|
|
128
|
-
//#region \0@oxc-project+runtime@0.
|
|
131
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
129
132
|
function _typeof(o) {
|
|
130
133
|
"@babel/helpers - typeof";
|
|
131
134
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -136,7 +139,7 @@ function _typeof(o) {
|
|
|
136
139
|
}
|
|
137
140
|
|
|
138
141
|
//#endregion
|
|
139
|
-
//#region \0@oxc-project+runtime@0.
|
|
142
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
140
143
|
function toPrimitive(t, r) {
|
|
141
144
|
if ("object" != _typeof(t) || !t) return t;
|
|
142
145
|
var e = t[Symbol.toPrimitive];
|
|
@@ -149,14 +152,14 @@ function toPrimitive(t, r) {
|
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
//#endregion
|
|
152
|
-
//#region \0@oxc-project+runtime@0.
|
|
155
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
153
156
|
function toPropertyKey(t) {
|
|
154
157
|
var i = toPrimitive(t, "string");
|
|
155
158
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
156
159
|
}
|
|
157
160
|
|
|
158
161
|
//#endregion
|
|
159
|
-
//#region \0@oxc-project+runtime@0.
|
|
162
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
160
163
|
function _defineProperty(e, r, t) {
|
|
161
164
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
162
165
|
value: t,
|
|
@@ -219,6 +222,13 @@ function toModule(channel) {
|
|
|
219
222
|
function propertyIsEventSource(name) {
|
|
220
223
|
return name.endsWith("$");
|
|
221
224
|
}
|
|
225
|
+
const CHANNEL_CLIENT_DISPOSED_ERROR_MESSAGE = "[ChannelClient]: client is disposed!";
|
|
226
|
+
var ChannelClientDisposedError = class extends Error {
|
|
227
|
+
constructor() {
|
|
228
|
+
super(CHANNEL_CLIENT_DISPOSED_ERROR_MESSAGE);
|
|
229
|
+
this.name = "ChannelClientDisposedError";
|
|
230
|
+
}
|
|
231
|
+
};
|
|
222
232
|
/**
|
|
223
233
|
* This method provides implementation for `IChannel` and is responsible for
|
|
224
234
|
* transforming a local calling to a RPC calling.
|
|
@@ -234,16 +244,21 @@ var ChannelClient = class extends _univerjs_core.RxDisposable {
|
|
|
234
244
|
this._protocol.onMessage.pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe((message) => this._onMessage(message));
|
|
235
245
|
}
|
|
236
246
|
dispose() {
|
|
247
|
+
if (this._disposed) return;
|
|
248
|
+
const error = new ChannelClientDisposedError();
|
|
249
|
+
this._initialized.error(error);
|
|
250
|
+
for (const responseHandler of this._pendingRequests.values()) responseHandler.dispose(error);
|
|
237
251
|
this._pendingRequests.clear();
|
|
252
|
+
super.dispose();
|
|
238
253
|
}
|
|
239
254
|
getChannel(channelName) {
|
|
240
255
|
return {
|
|
241
256
|
call: (method, args) => {
|
|
242
|
-
if (this._disposed) return Promise.reject(
|
|
257
|
+
if (this._disposed) return Promise.reject(new ChannelClientDisposedError());
|
|
243
258
|
return this._remoteCall(channelName, method, args);
|
|
244
259
|
},
|
|
245
260
|
subscribe: (eventMethod, args) => {
|
|
246
|
-
if (this._disposed) throw new
|
|
261
|
+
if (this._disposed) throw new ChannelClientDisposedError();
|
|
247
262
|
return this._remoteSubscribe(channelName, eventMethod, args);
|
|
248
263
|
}
|
|
249
264
|
};
|
|
@@ -266,19 +281,24 @@ var ChannelClient = class extends _univerjs_core.RxDisposable {
|
|
|
266
281
|
};
|
|
267
282
|
const pendingRequests = this._pendingRequests;
|
|
268
283
|
return new Promise((resolve, reject) => {
|
|
269
|
-
this._pendingRequests.set(sequence, {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
284
|
+
this._pendingRequests.set(sequence, {
|
|
285
|
+
handle(response) {
|
|
286
|
+
switch (response.type) {
|
|
287
|
+
case 201:
|
|
288
|
+
pendingRequests.delete(sequence);
|
|
289
|
+
resolve(response.data);
|
|
290
|
+
break;
|
|
291
|
+
case 202:
|
|
292
|
+
pendingRequests.delete(sequence);
|
|
293
|
+
reject(response.data);
|
|
294
|
+
break;
|
|
295
|
+
default: throw new Error("[ChannelClient]: unknown response type!");
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
dispose(error) {
|
|
299
|
+
reject(error);
|
|
280
300
|
}
|
|
281
|
-
}
|
|
301
|
+
});
|
|
282
302
|
this._sendRequest(request);
|
|
283
303
|
});
|
|
284
304
|
}
|
|
@@ -294,20 +314,25 @@ var ChannelClient = class extends _univerjs_core.RxDisposable {
|
|
|
294
314
|
method,
|
|
295
315
|
args
|
|
296
316
|
};
|
|
297
|
-
this._pendingRequests.set(sequence, {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
317
|
+
this._pendingRequests.set(sequence, {
|
|
318
|
+
handle(response) {
|
|
319
|
+
switch (response.type) {
|
|
320
|
+
case 300:
|
|
321
|
+
subscriber.next(response.data);
|
|
322
|
+
break;
|
|
323
|
+
case 301:
|
|
324
|
+
subscriber.error(response.data);
|
|
325
|
+
break;
|
|
326
|
+
case 302:
|
|
327
|
+
subscriber.complete();
|
|
328
|
+
break;
|
|
329
|
+
default: throw new Error("[ChannelClient]: unknown response type!");
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
dispose(error) {
|
|
333
|
+
subscriber.error(error);
|
|
309
334
|
}
|
|
310
|
-
}
|
|
335
|
+
});
|
|
311
336
|
this._sendRequest(request);
|
|
312
337
|
};
|
|
313
338
|
if (this._initialized.getValue()) doSubscribe();
|
|
@@ -358,6 +383,7 @@ var ChannelServer = class extends _univerjs_core.RxDisposable {
|
|
|
358
383
|
}
|
|
359
384
|
dispose() {
|
|
360
385
|
super.dispose();
|
|
386
|
+
for (const subscription of this._subscriptions.values()) subscription.unsubscribe();
|
|
361
387
|
this._subscriptions.clear();
|
|
362
388
|
this._channels.clear();
|
|
363
389
|
}
|
|
@@ -375,10 +401,7 @@ var ChannelServer = class extends _univerjs_core.RxDisposable {
|
|
|
375
401
|
case 101:
|
|
376
402
|
this._onSubscribe(request);
|
|
377
403
|
break;
|
|
378
|
-
case 102:
|
|
379
|
-
this._onUnsubscribe(request);
|
|
380
|
-
break;
|
|
381
|
-
default: break;
|
|
404
|
+
case 102: this._onUnsubscribe(request);
|
|
382
405
|
}
|
|
383
406
|
}
|
|
384
407
|
_sendInitialize() {
|
|
@@ -501,17 +524,19 @@ var ChannelService = class {
|
|
|
501
524
|
//#endregion
|
|
502
525
|
//#region src/controllers/data-sync/data-sync-primary.controller.ts
|
|
503
526
|
let DataSyncPrimaryController = class DataSyncPrimaryController extends _univerjs_core.RxDisposable {
|
|
504
|
-
constructor(_injector, _commandService, _univerInstanceService, _rpcChannelService, _remoteSyncService) {
|
|
527
|
+
constructor(_injector, _commandService, _univerInstanceService, _rpcChannelService, _remoteSyncService, _logService) {
|
|
505
528
|
super();
|
|
506
529
|
this._injector = _injector;
|
|
507
530
|
this._commandService = _commandService;
|
|
508
531
|
this._univerInstanceService = _univerInstanceService;
|
|
509
532
|
this._rpcChannelService = _rpcChannelService;
|
|
510
533
|
this._remoteSyncService = _remoteSyncService;
|
|
534
|
+
this._logService = _logService;
|
|
511
535
|
_defineProperty(this, "_remoteInstanceService", void 0);
|
|
512
536
|
_defineProperty(this, "_syncingUnits", /* @__PURE__ */ new Set());
|
|
513
537
|
_defineProperty(this, "_syncingMutations", /* @__PURE__ */ new Set());
|
|
514
538
|
_defineProperty(this, "_syncMutationQueue", Promise.resolve());
|
|
539
|
+
_defineProperty(this, "_remoteReady", Promise.resolve(true));
|
|
515
540
|
this._initRPCChannels();
|
|
516
541
|
this._init();
|
|
517
542
|
}
|
|
@@ -526,14 +551,14 @@ let DataSyncPrimaryController = class DataSyncPrimaryController extends _univerj
|
|
|
526
551
|
const alreadySyncing = this._syncingUnits.has(unitId);
|
|
527
552
|
this._syncingUnits.add(unitId);
|
|
528
553
|
const unit = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) ?? this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_BASE);
|
|
529
|
-
if (!alreadySyncing && unit) this._remoteInstanceService.createInstance({
|
|
554
|
+
if (!alreadySyncing && unit) this._handleRemoteRequest(this._remoteInstanceService.createInstance({
|
|
530
555
|
unitID: unit.getUnitId(),
|
|
531
556
|
type: unit.type,
|
|
532
557
|
snapshot: unit.getSnapshot()
|
|
533
|
-
});
|
|
558
|
+
}), "create the remote unit");
|
|
534
559
|
return (0, _univerjs_core.toDisposable)(() => {
|
|
535
560
|
if (!alreadySyncing) this._syncingUnits.delete(unitId);
|
|
536
|
-
if (!alreadySyncing && unit) this._remoteInstanceService.disposeInstance({ unitID: unit.getUnitId() });
|
|
561
|
+
if (!alreadySyncing && unit) this._handleRemoteRequest(this._remoteInstanceService.disposeInstance({ unitID: unit.getUnitId() }), "dispose the remote unit");
|
|
537
562
|
});
|
|
538
563
|
}
|
|
539
564
|
/** Sync registered mutations for a unit without creating a replica unit. */
|
|
@@ -544,41 +569,56 @@ let DataSyncPrimaryController = class DataSyncPrimaryController extends _univerj
|
|
|
544
569
|
if (!alreadySyncing) this._syncingUnits.delete(unitId);
|
|
545
570
|
});
|
|
546
571
|
}
|
|
572
|
+
async syncMutation(commandInfo, options) {
|
|
573
|
+
const sync = () => this._remoteReady.then(() => this._remoteInstanceService.syncMutation({ mutationInfo: commandInfo }, options));
|
|
574
|
+
const result = this._syncMutationQueue.then(sync, sync);
|
|
575
|
+
this._syncMutationQueue = result.catch(() => false);
|
|
576
|
+
return result;
|
|
577
|
+
}
|
|
578
|
+
async waitForPendingMutations() {
|
|
579
|
+
await this._syncMutationQueue.catch(() => false);
|
|
580
|
+
}
|
|
547
581
|
_initRPCChannels() {
|
|
548
582
|
this._rpcChannelService.registerChannel(RemoteSyncServiceName, fromModule(this._remoteSyncService));
|
|
549
583
|
this._injector.add([IRemoteInstanceService, { useFactory: () => toModule(this._rpcChannelService.requestChannel(RemoteInstanceServiceName)) }]);
|
|
550
584
|
this._remoteInstanceService = this._injector.get(IRemoteInstanceService);
|
|
585
|
+
this._remoteReady = this._remoteInstanceService.whenReady();
|
|
586
|
+
this._handleRemoteRequest(this._remoteReady, "initialize the remote instance service");
|
|
551
587
|
}
|
|
552
588
|
_init() {
|
|
553
589
|
this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe((event) => {
|
|
554
590
|
const { unit: sheet } = event;
|
|
555
591
|
this._syncingUnits.add(sheet.getUnitId());
|
|
556
|
-
this._remoteInstanceService.createInstance({
|
|
592
|
+
this._handleRemoteRequest(this._remoteInstanceService.createInstance({
|
|
557
593
|
unitID: sheet.getUnitId(),
|
|
558
594
|
type: _univerjs_core.UniverInstanceType.UNIVER_SHEET,
|
|
559
595
|
snapshot: sheet.getSnapshot()
|
|
560
|
-
});
|
|
596
|
+
}), "create the remote workbook");
|
|
561
597
|
});
|
|
562
598
|
this._univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.takeUntil)(this.dispose$)).subscribe((workbook) => {
|
|
563
599
|
this._syncingUnits.delete(workbook.getUnitId());
|
|
564
|
-
this._remoteInstanceService.disposeInstance({ unitID: workbook.getUnitId() });
|
|
600
|
+
this._handleRemoteRequest(this._remoteInstanceService.disposeInstance({ unitID: workbook.getUnitId() }), "dispose the remote workbook");
|
|
565
601
|
});
|
|
566
602
|
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo, options) => {
|
|
567
603
|
const { type, params, id } = commandInfo;
|
|
568
604
|
const unitId = (params === null || params === void 0 ? void 0 : params.unitId) || "";
|
|
569
|
-
if (type === _univerjs_core.CommandType.MUTATION && (!unitId || this._syncingUnits.has(unitId)) && !(options === null || options === void 0 ? void 0 : options.fromSync) && this._syncingMutations.has(id)) {
|
|
570
|
-
const sync = () => this._remoteInstanceService.syncMutation({ mutationInfo: commandInfo }, options);
|
|
571
|
-
this._syncMutationQueue = this._syncMutationQueue.then(sync, sync).catch(() => false);
|
|
572
|
-
}
|
|
605
|
+
if (type === _univerjs_core.CommandType.MUTATION && (!unitId || this._syncingUnits.has(unitId)) && !(options === null || options === void 0 ? void 0 : options.fromSync) && this._syncingMutations.has(id)) this._handleRemoteRequest(this.syncMutation(commandInfo, options), `sync mutation ${id}`);
|
|
573
606
|
}));
|
|
574
607
|
}
|
|
608
|
+
_handleRemoteRequest(request, operation) {
|
|
609
|
+
request.catch((error) => {
|
|
610
|
+
if (error instanceof ChannelClientDisposedError) return;
|
|
611
|
+
this._logService.error(`[DataSyncPrimaryController]: Failed to ${operation}.`, error);
|
|
612
|
+
});
|
|
613
|
+
}
|
|
575
614
|
};
|
|
576
615
|
DataSyncPrimaryController = __decorate([
|
|
577
616
|
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
578
617
|
__decorateParam(1, _univerjs_core.ICommandService),
|
|
579
618
|
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
580
619
|
__decorateParam(3, IRPCChannelService),
|
|
581
|
-
__decorateParam(4, IRemoteSyncService)
|
|
620
|
+
__decorateParam(4, IRemoteSyncService),
|
|
621
|
+
__decorateParam(5, _univerjs_core.ILogService)
|
|
582
622
|
], DataSyncPrimaryController);
|
|
583
623
|
|
|
584
624
|
//#endregion
|
|
@@ -615,7 +655,7 @@ DataSyncReplicaController = __decorate([
|
|
|
615
655
|
//#endregion
|
|
616
656
|
//#region package.json
|
|
617
657
|
var name = "@univerjs/rpc";
|
|
618
|
-
var version = "1.0.0
|
|
658
|
+
var version = "1.0.0";
|
|
619
659
|
|
|
620
660
|
//#endregion
|
|
621
661
|
//#region src/services/rpc/implementations/web-worker-rpc.service.ts
|