@ahoo-wang/fetcher-eventstream 0.5.6 → 0.6.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.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { FetchExchange, Interceptor } from '@ahoo-wang/fetcher';
|
|
2
2
|
export declare class EventStreamInterceptor implements Interceptor {
|
|
3
|
+
name: string;
|
|
4
|
+
order: number;
|
|
3
5
|
intercept(exchange: FetchExchange): FetchExchange;
|
|
4
6
|
}
|
|
5
7
|
//# sourceMappingURL=eventStreamInterceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventStreamInterceptor.d.ts","sourceRoot":"","sources":["../src/eventStreamInterceptor.ts"],"names":[],"mappings":"AAcA,OAAO,EAGL,aAAa,EACb,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,sBAAuB,YAAW,WAAW;IACxD,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa;CAgBlD"}
|
|
1
|
+
{"version":3,"file":"eventStreamInterceptor.d.ts","sourceRoot":"","sources":["../src/eventStreamInterceptor.ts"],"names":[],"mappings":"AAcA,OAAO,EAGL,aAAa,EACb,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,sBAAuB,YAAW,WAAW;IACxD,IAAI,SAA4B;IAChC,KAAK,SAA2B;IAEhC,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa;CAgBlD"}
|
package/dist/index.es.js
CHANGED
|
@@ -23,12 +23,12 @@ class d {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class c extends TransformStream {
|
|
27
27
|
constructor() {
|
|
28
28
|
super(new d());
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
var
|
|
31
|
+
var u = /* @__PURE__ */ ((s) => (s.ID = "id", s.RETRY = "retry", s.EVENT = "event", s.DATA = "data", s))(u || {});
|
|
32
32
|
function m(s, t, e) {
|
|
33
33
|
switch (s) {
|
|
34
34
|
case "event":
|
|
@@ -47,7 +47,7 @@ function m(s, t, e) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
class
|
|
50
|
+
class h {
|
|
51
51
|
constructor() {
|
|
52
52
|
this.currentEvent = {
|
|
53
53
|
event: "message",
|
|
@@ -108,31 +108,34 @@ class p {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
class
|
|
111
|
+
class p extends TransformStream {
|
|
112
112
|
constructor() {
|
|
113
|
-
super(new
|
|
113
|
+
super(new h());
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
function
|
|
116
|
+
function T(s) {
|
|
117
117
|
if (!s.body)
|
|
118
118
|
throw new Error("Response body is null");
|
|
119
|
-
return s.body.pipeThrough(new TextDecoderStream("utf-8")).pipeThrough(new
|
|
119
|
+
return s.body.pipeThrough(new TextDecoderStream("utf-8")).pipeThrough(new c()).pipeThrough(new p());
|
|
120
120
|
}
|
|
121
121
|
class v {
|
|
122
|
+
constructor() {
|
|
123
|
+
this.name = "EventStreamInterceptor", this.order = Number.MAX_SAFE_INTEGER;
|
|
124
|
+
}
|
|
122
125
|
intercept(t) {
|
|
123
126
|
const e = t.response;
|
|
124
127
|
if (!e)
|
|
125
128
|
return t;
|
|
126
129
|
const r = e.headers.get(i);
|
|
127
|
-
return r && r.includes(f.TEXT_EVENT_STREAM) && (e.eventStream = () =>
|
|
130
|
+
return r && r.includes(f.TEXT_EVENT_STREAM) && (e.eventStream = () => T(e)), t;
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
export {
|
|
131
134
|
v as EventStreamInterceptor,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
u as ServerSentEventField,
|
|
136
|
+
p as ServerSentEventTransformStream,
|
|
137
|
+
h as ServerSentEventTransformer,
|
|
138
|
+
c as TextLineTransformStream,
|
|
136
139
|
d as TextLineTransformer,
|
|
137
|
-
|
|
140
|
+
T as toServerSentEventStream
|
|
138
141
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
(function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@ahoo-wang/fetcher")):typeof define=="function"&&define.amd?define(["exports","@ahoo-wang/fetcher"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s.FetcherEventStream={},s.Fetcher))})(this,(function(s,o){"use strict";class d{constructor(){this.buffer=""}transform(t,e){try{this.buffer+=t;const r=this.buffer.split(`
|
|
2
|
-
`);this.buffer=r.pop()||"";for(const a of r)e.enqueue(a)}catch(r){e.error(r)}}flush(t){try{this.buffer&&t.enqueue(this.buffer)}catch(e){t.error(e)}}}class u extends TransformStream{constructor(){super(new d)}}var c=(n=>(n.ID="id",n.RETRY="retry",n.EVENT="event",n.DATA="data",n))(c||{});function
|
|
3
|
-
`),id:r.id||"",retry:r.retry}),r.event="message",r.data=[]);return}if(t.startsWith(":"))return;const a=t.indexOf(":");let f,i;a===-1?(f=t.toLowerCase(),i=""):(f=t.substring(0,a).toLowerCase(),i=t.substring(a+1),i.startsWith(" ")&&(i=i.substring(1))),f=f.trim(),i=i.trim(),
|
|
4
|
-
`),id:e.id||"",retry:e.retry})}catch(r){t.error(r instanceof Error?r:new Error(String(r)))}finally{e.event="message",e.id=void 0,e.retry=void 0,e.data=[]}}}class
|
|
2
|
+
`);this.buffer=r.pop()||"";for(const a of r)e.enqueue(a)}catch(r){e.error(r)}}flush(t){try{this.buffer&&t.enqueue(this.buffer)}catch(e){t.error(e)}}}class u extends TransformStream{constructor(){super(new d)}}var c=(n=>(n.ID="id",n.RETRY="retry",n.EVENT="event",n.DATA="data",n))(c||{});function T(n,t,e){switch(n){case"event":e.event=t;break;case"data":e.data.push(t);break;case"id":e.id=t;break;case"retry":{const r=parseInt(t,10);isNaN(r)||(e.retry=r);break}}}class m{constructor(){this.currentEvent={event:"message",id:void 0,retry:void 0,data:[]}}transform(t,e){const r=this.currentEvent;try{if(t.trim()===""){r.data.length>0&&(e.enqueue({event:r.event||"message",data:r.data.join(`
|
|
3
|
+
`),id:r.id||"",retry:r.retry}),r.event="message",r.data=[]);return}if(t.startsWith(":"))return;const a=t.indexOf(":");let f,i;a===-1?(f=t.toLowerCase(),i=""):(f=t.substring(0,a).toLowerCase(),i=t.substring(a+1),i.startsWith(" ")&&(i=i.substring(1))),f=f.trim(),i=i.trim(),T(f,i,r)}catch(a){e.error(a instanceof Error?a:new Error(String(a))),r.event="message",r.id=void 0,r.retry=void 0,r.data=[]}}flush(t){const e=this.currentEvent;try{e.data.length>0&&t.enqueue({event:e.event||"message",data:e.data.join(`
|
|
4
|
+
`),id:e.id||"",retry:e.retry})}catch(r){t.error(r instanceof Error?r:new Error(String(r)))}finally{e.event="message",e.id=void 0,e.retry=void 0,e.data=[]}}}class h extends TransformStream{constructor(){super(new m)}}function v(n){if(!n.body)throw new Error("Response body is null");return n.body.pipeThrough(new TextDecoderStream("utf-8")).pipeThrough(new u).pipeThrough(new h)}class S{constructor(){this.name="EventStreamInterceptor",this.order=Number.MAX_SAFE_INTEGER}intercept(t){const e=t.response;if(!e)return t;const r=e.headers.get(o.ContentTypeHeader);return r&&r.includes(o.ContentTypeValues.TEXT_EVENT_STREAM)&&(e.eventStream=()=>v(e)),t}}s.EventStreamInterceptor=S,s.ServerSentEventField=c,s.ServerSentEventTransformStream=h,s.ServerSentEventTransformer=m,s.TextLineTransformStream=u,s.TextLineTransformer=d,s.toServerSentEventStream=v,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/fetcher-eventstream",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Server-Sent Events (SSE) support for Fetcher HTTP client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@ahoo-wang/fetcher": "0.
|
|
36
|
+
"@ahoo-wang/fetcher": "0.6.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@vitest/coverage-v8": "^3.2.4",
|