@univerjs/network 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/facade.js CHANGED
@@ -1 +1,103 @@
1
- import{FBase as e,FUniver as t}from"@univerjs/core/facade";import{HTTPService as n,WebSocketService as r}from"@univerjs/network";import{Inject as i,Injector as a}from"@univerjs/core";function o(e,t){return function(n,r){t(n,r,e)}}function s(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 c=class extends e{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,n){return this._httpService.getSSE(e,t,n)}};c=s([o(0,i(a)),o(1,i(n))],c);var l=class extends t{getNetwork(){return this._injector.createInstance(c)}createSocket(e){let t=this._injector.createInstance(r).createSocket(e);if(!t)throw Error(`[WebSocketService]: failed to create socket!`);return t}};t.extend(l);export{};
1
+ import { FBase, FUniver } from "@univerjs/core/facade";
2
+ import { HTTPService, WebSocketService } from "@univerjs/network";
3
+ import { Inject, Injector } from "@univerjs/core";
4
+
5
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
6
+ function __decorateParam(paramIndex, decorator) {
7
+ return function(target, key) {
8
+ decorator(target, key, paramIndex);
9
+ };
10
+ }
11
+
12
+ //#endregion
13
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
14
+ function __decorate(decorators, target, key, desc) {
15
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
+ 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;
18
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
19
+ }
20
+
21
+ //#endregion
22
+ //#region src/facade/f-network.ts
23
+ let FNetwork = class FNetwork extends FBase {
24
+ constructor(_injector, _httpService) {
25
+ super();
26
+ this._injector = _injector;
27
+ this._httpService = _httpService;
28
+ }
29
+ /**
30
+ * Send a GET request to the server.
31
+ * @param {string} url - The requested URL.
32
+ * @param {IRequestParams} [params] - Query parameters.
33
+ * @returns {Promise<HTTPResponse>} Network response.
34
+ */
35
+ get(url, params) {
36
+ return this._httpService.get(url, params);
37
+ }
38
+ /**
39
+ * Send a POST request to the server.
40
+ * @param {string} url - The requested URL.
41
+ * @param {IPostRequestParams} [params] - Query parameters.
42
+ * @returns {Promise<HTTPResponse>} Network response.
43
+ */
44
+ post(url, params) {
45
+ return this._httpService.post(url, params);
46
+ }
47
+ /**
48
+ * Send a PUT request to the server.
49
+ * @param {string} url - The requested URL
50
+ * @param {IPostRequestParams} [params] - Query parameters
51
+ * @returns {Promise<HTTPResponse>} Network response
52
+ */
53
+ put(url, params) {
54
+ return this._httpService.put(url, params);
55
+ }
56
+ /**
57
+ * Send DELETE request to the server.
58
+ * @param {string} url - The requested URL
59
+ * @param {IRequestParams} [params] - Query parameters
60
+ * @returns {Promise<HTTPResponse>} Network response
61
+ */
62
+ delete(url, params) {
63
+ return this._httpService.delete(url, params);
64
+ }
65
+ /**
66
+ * Send PATCH request to the server.
67
+ * @param {string} url - The requested URL
68
+ * @param {IPostRequestParams} [params] - Query parameters
69
+ * @returns {Promise<HTTPResponse>} Network response
70
+ */
71
+ patch(url, params) {
72
+ return this._httpService.patch(url, params);
73
+ }
74
+ /**
75
+ * Request for a stream of server-sent events. Instead of a single response, the server sends a stream of responses,
76
+ * Univer wraps the stream in an [`Observable`](https://rxjs.dev/guide/observable) which you can call `subscribe` on.
77
+ * @param {HTTPRequestMethod} method - HTTP request method
78
+ * @param {string} url - The requested URL
79
+ * @param {IPostRequestParams} [params] - params Query parameters
80
+ * @returns {Observable<HTTPEvent>} An observable that emits the network response.
81
+ */
82
+ getSSE(method, url, params) {
83
+ return this._httpService.getSSE(method, url, params);
84
+ }
85
+ };
86
+ FNetwork = __decorate([__decorateParam(0, Inject(Injector)), __decorateParam(1, Inject(HTTPService))], FNetwork);
87
+
88
+ //#endregion
89
+ //#region src/facade/f-univer.ts
90
+ var FUniverNetworkMixin = class extends FUniver {
91
+ getNetwork() {
92
+ return this._injector.createInstance(FNetwork);
93
+ }
94
+ createSocket(url) {
95
+ const ws = this._injector.createInstance(WebSocketService).createSocket(url);
96
+ if (!ws) throw new Error("[WebSocketService]: failed to create socket!");
97
+ return ws;
98
+ }
99
+ };
100
+ FUniver.extend(FUniverNetworkMixin);
101
+
102
+ //#endregion
103
+ export { };