@snail-js/api 0.1.7 → 0.1.8

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 CHANGED
@@ -380,10 +380,10 @@ export const Sse = Service.createSse(ServerSend);
380
380
  ### 服务端推送装饰器`@Sse`
381
381
 
382
382
  - `@Sse(path:string,options:{withCredentials: boolean})`
383
- - 创建一个服务端推送连接,当被装饰的方法调用时打开连接
384
- - 被装饰的方法调用后会返回`{eventSource:EventSource,close:function}`
385
- - eventSource: sse 连接实例
386
- - close: 关闭此 sse 连接的方法
383
+ - 创建一个服务端推送连接,返回一个函数,用于打开sse连接
384
+ - 返回的打开函数调用后会返回`{eventSource:EventSource,close:function}`
385
+ - eventSource: sse 连接实例
386
+ - close: 关闭此 sse 连接的方法
387
387
 
388
388
  ### 注册`onopen`装饰器`@OnSseOpen`
389
389
 
package/dist/snail-api.js CHANGED
@@ -4143,25 +4143,23 @@ class Snail {
4143
4143
  );
4144
4144
  const sseUrl = this.generateSseUrl(baseURL, versionUrl || url);
4145
4145
  enableLog && console.log("sse-url:", sseUrl);
4146
- const { eventSource, close } = this.initSse(sseUrl, sseOption);
4147
- this.eventSource = eventSource;
4148
- this.setSse(target);
4149
- this.registerSseEvent(target);
4150
- return () => {
4151
- return { eventSource, close };
4152
- };
4146
+ return this.initSse(sseUrl, sseOption, target);
4153
4147
  }
4154
4148
  }
4155
4149
  });
4156
4150
  }
4157
- initSse(url, options) {
4158
- const eventSource = new EventSource(url, {
4159
- withCredentials: options.withCredentials ? options.withCredentials : false
4160
- });
4161
- console.log("EventSource:", eventSource);
4162
- return {
4163
- eventSource,
4164
- close: eventSource.close
4151
+ initSse(url, options, target) {
4152
+ return () => {
4153
+ const eventSource = new EventSource(url, {
4154
+ withCredentials: options.withCredentials ? options.withCredentials : false
4155
+ });
4156
+ this.eventSource = eventSource;
4157
+ this.setSse(target);
4158
+ this.registerSseEvent(target);
4159
+ return {
4160
+ eventSource,
4161
+ close: eventSource.close
4162
+ };
4165
4163
  };
4166
4164
  }
4167
4165
  setSse(target) {
@@ -4147,25 +4147,23 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4147
4147
  );
4148
4148
  const sseUrl = this.generateSseUrl(baseURL, versionUrl || url);
4149
4149
  enableLog && console.log("sse-url:", sseUrl);
4150
- const { eventSource, close } = this.initSse(sseUrl, sseOption);
4151
- this.eventSource = eventSource;
4152
- this.setSse(target);
4153
- this.registerSseEvent(target);
4154
- return () => {
4155
- return { eventSource, close };
4156
- };
4150
+ return this.initSse(sseUrl, sseOption, target);
4157
4151
  }
4158
4152
  }
4159
4153
  });
4160
4154
  }
4161
- initSse(url, options) {
4162
- const eventSource = new EventSource(url, {
4163
- withCredentials: options.withCredentials ? options.withCredentials : false
4164
- });
4165
- console.log("EventSource:", eventSource);
4166
- return {
4167
- eventSource,
4168
- close: eventSource.close
4155
+ initSse(url, options, target) {
4156
+ return () => {
4157
+ const eventSource = new EventSource(url, {
4158
+ withCredentials: options.withCredentials ? options.withCredentials : false
4159
+ });
4160
+ this.eventSource = eventSource;
4161
+ this.setSse(target);
4162
+ this.registerSseEvent(target);
4163
+ return {
4164
+ eventSource,
4165
+ close: eventSource.close
4166
+ };
4169
4167
  };
4170
4168
  }
4171
4169
  setSse(target) {
@@ -1,8 +1,5 @@
1
1
  export type SseProxy<T extends object> = {
2
- [K in keyof T]: T[K] extends (...args: infer A) => any ? () => {
3
- eventSource: EventSource;
4
- close: Function;
5
- } : T[K];
2
+ [K in keyof T]: T[K] extends (...args: infer A) => any ? () => void : T[K];
6
3
  };
7
4
  export declare class RegisterSseEvent {
8
5
  eventName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snail-js/api",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Http Request with Decorators Api, build on axios",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",