@univerjs/network 0.6.4 → 0.6.5

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/facade.js CHANGED
@@ -1 +1 @@
1
- "use strict";const o=require("@univerjs/core/facade"),i=require("@univerjs/core"),v=require("@univerjs/network");var a=Object.getOwnPropertyDescriptor,_=(e,t,r,c)=>{for(var s=c>1?void 0:c?a(t,r):t,n=e.length-1,p;n>=0;n--)(p=e[n])&&(s=p(s)||s);return s},u=(e,t)=>(r,c)=>t(r,c,e);let h=class extends o.FBase{constructor(e,t){super(),this._injector=e,this._httpService=t}get(e,t){return this._httpService.get(e,t)}post(e,t){return this._httpService.post(e,t)}put(e,t){return this._httpService.put(e,t)}delete(e,t){return this._httpService.delete(e,t)}patch(e,t){return this._httpService.patch(e,t)}getSSE(e,t,r){return this._httpService.getSSE(e,t,r)}};h=_([u(0,i.Inject(i.Injector)),u(1,i.Inject(v.HTTPService))],h);class S extends o.FUniver{getNetwork(){return this._injector.createInstance(h)}}o.FUniver.extend(S);
1
+ "use strict";const a=require("@univerjs/core/facade"),S=require("@univerjs/network"),n=require("@univerjs/core");var u=Object.getOwnPropertyDescriptor,p=(t,e,c,r)=>{for(var s=r>1?void 0:r?u(e,c):e,i=t.length-1,h;i>=0;i--)(h=t[i])&&(s=h(s)||s);return s},v=(t,e)=>(c,r)=>e(c,r,t);let o=class extends a.FBase{constructor(t,e){super(),this._injector=t,this._httpService=e}get(t,e){return this._httpService.get(t,e)}post(t,e){return this._httpService.post(t,e)}put(t,e){return this._httpService.put(t,e)}delete(t,e){return this._httpService.delete(t,e)}patch(t,e){return this._httpService.patch(t,e)}getSSE(t,e,c){return this._httpService.getSSE(t,e,c)}};o=p([v(0,n.Inject(n.Injector)),v(1,n.Inject(S.HTTPService))],o);class _ extends a.FUniver{getNetwork(){return this._injector.createInstance(o)}createSocket(e){const r=this._injector.createInstance(S.WebSocketService).createSocket(e);if(!r)throw new Error("[WebSocketService]: failed to create socket!");return r}}a.FUniver.extend(_);
package/lib/es/facade.js CHANGED
@@ -1,12 +1,12 @@
1
- import { FBase as _, FUniver as v } from "@univerjs/core/facade";
2
- import { Inject as h, Injector as a } from "@univerjs/core";
3
- import { HTTPService as u } from "@univerjs/network";
4
- var S = Object.getOwnPropertyDescriptor, l = (t, e, r, i) => {
5
- for (var s = i > 1 ? void 0 : i ? S(e, r) : e, c = t.length - 1, p; c >= 0; c--)
6
- (p = t[c]) && (s = p(s) || s);
7
- return s;
8
- }, o = (t, e) => (r, i) => e(r, i, t);
9
- let n = class extends _ {
1
+ import { FBase as v, FUniver as p } from "@univerjs/core/facade";
2
+ import { HTTPService as S, WebSocketService as _ } from "@univerjs/network";
3
+ import { Inject as h, Injector as u } from "@univerjs/core";
4
+ var w = Object.getOwnPropertyDescriptor, l = (t, e, c, r) => {
5
+ for (var i = r > 1 ? void 0 : r ? w(e, c) : e, s = t.length - 1, o; s >= 0; s--)
6
+ (o = t[s]) && (i = o(i) || i);
7
+ return i;
8
+ }, a = (t, e) => (c, r) => e(c, r, t);
9
+ let n = class extends v {
10
10
  constructor(t, e) {
11
11
  super(), this._injector = t, this._httpService = e;
12
12
  }
@@ -63,17 +63,23 @@ let n = class extends _ {
63
63
  * @param {IPostRequestParams} [params] - params Query parameters
64
64
  * @returns {Observable<HTTPEvent>} An observable that emits the network response.
65
65
  */
66
- getSSE(t, e, r) {
67
- return this._httpService.getSSE(t, e, r);
66
+ getSSE(t, e, c) {
67
+ return this._httpService.getSSE(t, e, c);
68
68
  }
69
69
  };
70
70
  n = l([
71
- o(0, h(a)),
72
- o(1, h(u))
71
+ a(0, h(u)),
72
+ a(1, h(S))
73
73
  ], n);
74
- class g extends v {
74
+ class f extends p {
75
75
  getNetwork() {
76
76
  return this._injector.createInstance(n);
77
77
  }
78
+ createSocket(e) {
79
+ const r = this._injector.createInstance(_).createSocket(e);
80
+ if (!r)
81
+ throw new Error("[WebSocketService]: failed to create socket!");
82
+ return r;
83
+ }
78
84
  }
79
- v.extend(g);
85
+ p.extend(f);
@@ -1,3 +1,4 @@
1
+ import { ISocket } from '@univerjs/network';
1
2
  import { FUniver } from '@univerjs/core/facade';
2
3
  import { FNetwork } from './f-network';
3
4
  /**
@@ -8,9 +9,60 @@ interface IFUniverNetworkMixin {
8
9
  * Get the network API of Univer, with the help of which you can send HTTP requests.
9
10
  */
10
11
  getNetwork(): FNetwork;
12
+ /**
13
+ * Set WebSocket URL for WebSocketService
14
+ *
15
+ * @param {string} url WebSocket URL
16
+ * @returns {ISocket} WebSocket instance
17
+ * @example
18
+ * ```typescript
19
+ * // Replace the URL with the address of your own WebSocket service
20
+ * const ws = univerAPI.createSocket('ws://47.100.177.253:8449/ws');
21
+ *
22
+ * ws.open$.subscribe(() => {
23
+ * console.log('websocket opened');
24
+ * ws.send('hello');
25
+ * });
26
+ *
27
+ * ws.message$.subscribe((message) => {
28
+ * console.log('websocket message', message);
29
+ * const content = JSON.parse(message.data).content;
30
+ * if (!content.includes('command')) {
31
+ * return;
32
+ * }
33
+ *
34
+ * const commandInfo = JSON.parse(content);
35
+ * const { command, options } = commandInfo;
36
+ * const { id, params } = command;
37
+ *
38
+ * // Upon receiving collaborative data, it is locally saved
39
+ * univerAPI.executeCommand(id, params, options);
40
+ * });
41
+ *
42
+ * ws.close$.subscribe(() => {
43
+ * console.log('websocket closed');
44
+ * });
45
+ *
46
+ * ws.error$.subscribe((error) => {
47
+ * console.log('websocket error', error);
48
+ * });
49
+ *
50
+ * univerAPI.onCommandExecuted((command, options) => {
51
+ * // Only synchronize local mutations
52
+ * if (command.type !== 2 || options?.fromCollab || options?.onlyLocal || command.id === 'doc.mutation.rich-text-editing') {
53
+ * return;
54
+ * }
55
+ *
56
+ * const commandInfo = JSON.stringify({ command, options: { fromCollab: true } });
57
+ * ws.send(commandInfo);
58
+ * });
59
+ * ```
60
+ */
61
+ createSocket(url: string): ISocket;
11
62
  }
12
63
  export declare class FUniverNetworkMixin extends FUniver implements IFUniverNetworkMixin {
13
64
  getNetwork(): FNetwork;
65
+ createSocket(url: string): ISocket;
14
66
  }
15
67
  declare module '@univerjs/core/facade' {
16
68
  interface FUniver extends IFUniverNetworkMixin {
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(r,n){typeof exports=="object"&&typeof module<"u"?n(require("@univerjs/core/facade"),require("@univerjs/core"),require("@univerjs/network")):typeof define=="function"&&define.amd?define(["@univerjs/core/facade","@univerjs/core","@univerjs/network"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.UniverCoreFacade,r.UniverCore,r.UniverNetwork))})(this,function(r,n,p){"use strict";var d=Object.getOwnPropertyDescriptor,_=(e,t,i,s)=>{for(var c=s>1?void 0:s?d(t,i):t,o=e.length-1,h;o>=0;o--)(h=e[o])&&(c=h(c)||c);return c},v=(e,t)=>(i,s)=>t(i,s,e);let u=class extends r.FBase{constructor(e,t){super(),this._injector=e,this._httpService=t}get(e,t){return this._httpService.get(e,t)}post(e,t){return this._httpService.post(e,t)}put(e,t){return this._httpService.put(e,t)}delete(e,t){return this._httpService.delete(e,t)}patch(e,t){return this._httpService.patch(e,t)}getSSE(e,t,i){return this._httpService.getSSE(e,t,i)}};u=_([v(0,n.Inject(n.Injector)),v(1,n.Inject(p.HTTPService))],u);class a extends r.FUniver{getNetwork(){return this._injector.createInstance(u)}}r.FUniver.extend(a)});
1
+ (function(r,n){typeof exports=="object"&&typeof module<"u"?n(require("@univerjs/core/facade"),require("@univerjs/network"),require("@univerjs/core")):typeof define=="function"&&define.amd?define(["@univerjs/core/facade","@univerjs/network","@univerjs/core"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.UniverCoreFacade,r.UniverNetwork,r.UniverCore))})(this,function(r,n,o){"use strict";var S=Object.getOwnPropertyDescriptor,a=(t,e,c,i)=>{for(var s=i>1?void 0:i?S(e,c):e,v=t.length-1,p;v>=0;v--)(p=t[v])&&(s=p(s)||s);return s},h=(t,e)=>(c,i)=>e(c,i,t);let u=class extends r.FBase{constructor(t,e){super(),this._injector=t,this._httpService=e}get(t,e){return this._httpService.get(t,e)}post(t,e){return this._httpService.post(t,e)}put(t,e){return this._httpService.put(t,e)}delete(t,e){return this._httpService.delete(t,e)}patch(t,e){return this._httpService.patch(t,e)}getSSE(t,e,c){return this._httpService.getSSE(t,e,c)}};u=a([h(0,o.Inject(o.Injector)),h(1,o.Inject(n.HTTPService))],u);class d extends r.FUniver{getNetwork(){return this._injector.createInstance(u)}createSocket(e){const i=this._injector.createInstance(n.WebSocketService).createSocket(e);if(!i)throw new Error("[WebSocketService]: failed to create socket!");return i}}r.FUniver.extend(d)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/network",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "private": false,
5
5
  "author": "DreamNum <developer@univer.ai>",
6
6
  "license": "Apache-2.0",
@@ -52,14 +52,14 @@
52
52
  "rxjs": ">=7.0.0"
53
53
  },
54
54
  "dependencies": {
55
- "@univerjs/core": "0.6.4"
55
+ "@univerjs/core": "0.6.5"
56
56
  },
57
57
  "devDependencies": {
58
58
  "rxjs": "^7.8.1",
59
59
  "typescript": "^5.8.2",
60
- "vite": "^6.2.0",
61
- "vitest": "^3.0.7",
62
- "@univerjs-infra/shared": "0.6.4"
60
+ "vite": "^6.2.1",
61
+ "vitest": "^3.0.8",
62
+ "@univerjs-infra/shared": "0.6.5"
63
63
  },
64
64
  "scripts": {
65
65
  "test": "vitest run",