@ahoo-wang/fetcher-eventstream 0.11.0 → 0.11.2
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/dist/index.es.js +1 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +1 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/textLineTransformStream.ts","../src/serverSentEventTransformStream.ts","../src/eventStreamConverter.ts","../src/jsonServerSentEventTransformStream.ts","../src/eventStreamInterceptor.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Transformer that splits text into lines.\n *\n * This transformer accumulates chunks of text and splits them by newline characters,\n * emitting each line as a separate chunk while preserving the remaining buffer\n * for the next chunk.\n */\nexport class TextLineTransformer implements Transformer<string, string> {\n private buffer = '';\n\n /**\n * Transform input string chunk by splitting it into lines.\n *\n * @param chunk Input string chunk\n * @param controller Controller for controlling the transform stream\n */\n transform(\n chunk: string,\n controller: TransformStreamDefaultController<string>,\n ) {\n try {\n this.buffer += chunk;\n const lines = this.buffer.split('\\n');\n this.buffer = lines.pop() || '';\n\n for (const line of lines) {\n controller.enqueue(line);\n }\n } catch (error) {\n controller.error(error);\n }\n }\n\n /**\n * Flush remaining buffer when the stream ends.\n *\n * @param controller Controller for controlling the transform stream\n */\n flush(controller: TransformStreamDefaultController<string>) {\n try {\n // Only send when buffer is not empty, avoid sending meaningless empty lines\n if (this.buffer) {\n controller.enqueue(this.buffer);\n }\n } catch (error) {\n controller.error(error);\n }\n }\n}\n\n/**\n * A TransformStream that splits text into lines.\n */\nexport class TextLineTransformStream extends TransformStream<string, string> {\n constructor() {\n super(new TextLineTransformer());\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Represents a message sent in an event stream.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format}\n */\nexport interface ServerSentEvent {\n /** The event ID to set the EventSource object's last event ID value. */\n id?: string;\n /** A string identifying the type of event described. */\n event: string;\n /** The event data */\n data: string;\n /** The reconnection interval (in milliseconds) to wait before retrying the connection */\n retry?: number;\n}\n\nexport enum ServerSentEventField {\n ID = 'id',\n RETRY = 'retry',\n EVENT = 'event',\n DATA = 'data',\n}\n\n/**\n * Process field value\n * @param field Field name\n * @param value Field value\n * @param currentEvent Current event state\n */\nfunction processFieldInternal(\n field: string,\n value: string,\n currentEvent: EventState,\n) {\n switch (field) {\n case ServerSentEventField.EVENT:\n currentEvent.event = value;\n break;\n case ServerSentEventField.DATA:\n currentEvent.data.push(value);\n break;\n case ServerSentEventField.ID:\n currentEvent.id = value;\n break;\n case ServerSentEventField.RETRY: {\n const retryValue = parseInt(value, 10);\n if (!isNaN(retryValue)) {\n currentEvent.retry = retryValue;\n }\n break;\n }\n default:\n // Ignore unknown fields\n break;\n }\n}\n\ninterface EventState {\n event?: string;\n id?: string;\n retry?: number;\n data: string[];\n}\n\nconst DEFAULT_EVENT_TYPE = 'message';\n\n/**\n * Transformer responsible for converting a string stream into a ServerSentEvent object stream.\n *\n * Implements the Transformer interface for processing data transformation in TransformStream.\n */\nexport class ServerSentEventTransformer\n implements Transformer<string, ServerSentEvent>\n{\n // Initialize currentEvent with default values in a closure\n private currentEvent: EventState = {\n event: DEFAULT_EVENT_TYPE,\n id: undefined,\n retry: undefined,\n data: [],\n };\n\n /**\n * Transform input string chunk into ServerSentEvent object.\n *\n * @param chunk Input string chunk\n * @param controller Controller for controlling the transform stream\n */\n transform(\n chunk: string,\n controller: TransformStreamDefaultController<ServerSentEvent>,\n ) {\n const currentEvent = this.currentEvent;\n try {\n // Skip empty lines (event separator)\n if (chunk.trim() === '') {\n // If there is accumulated event data, send event\n if (currentEvent.data.length > 0) {\n controller.enqueue({\n event: currentEvent.event || DEFAULT_EVENT_TYPE,\n data: currentEvent.data.join('\\n'),\n id: currentEvent.id || '',\n retry: currentEvent.retry,\n } as ServerSentEvent);\n\n // Reset current event (preserve id and retry for subsequent events)\n currentEvent.event = DEFAULT_EVENT_TYPE;\n // Preserve id and retry for subsequent events (no need to reassign to themselves)\n currentEvent.data = [];\n }\n return;\n }\n\n // Ignore comment lines (starting with colon)\n if (chunk.startsWith(':')) {\n return;\n }\n\n // Parse fields\n const colonIndex = chunk.indexOf(':');\n let field: string;\n let value: string;\n\n if (colonIndex === -1) {\n // No colon, entire line as field name, value is empty\n field = chunk.toLowerCase();\n value = '';\n } else {\n // Extract field name and value\n field = chunk.substring(0, colonIndex).toLowerCase();\n value = chunk.substring(colonIndex + 1);\n\n // If value starts with space, remove leading space\n if (value.startsWith(' ')) {\n value = value.substring(1);\n }\n }\n\n // Remove trailing newlines from field and value\n field = field.trim();\n value = value.trim();\n\n processFieldInternal(field, value, currentEvent);\n } catch (error) {\n controller.error(\n error instanceof Error ? error : new Error(String(error)),\n );\n // Reset state\n currentEvent.event = DEFAULT_EVENT_TYPE;\n currentEvent.id = undefined;\n currentEvent.retry = undefined;\n currentEvent.data = [];\n }\n }\n\n /**\n * Called when the stream ends, used to process remaining data.\n *\n * @param controller Controller for controlling the transform stream\n */\n flush(controller: TransformStreamDefaultController<ServerSentEvent>) {\n const currentEvent = this.currentEvent;\n try {\n // Send the last event (if any)\n if (currentEvent.data.length > 0) {\n controller.enqueue({\n event: currentEvent.event || DEFAULT_EVENT_TYPE,\n data: currentEvent.data.join('\\n'),\n id: currentEvent.id || '',\n retry: currentEvent.retry,\n } as ServerSentEvent);\n }\n } catch (error) {\n controller.error(\n error instanceof Error ? error : new Error(String(error)),\n );\n } finally {\n // Reset state\n currentEvent.event = DEFAULT_EVENT_TYPE;\n currentEvent.id = undefined;\n currentEvent.retry = undefined;\n currentEvent.data = [];\n }\n }\n}\n\n/**\n * A TransformStream that converts a stream of strings into a stream of ServerSentEvent objects.\n */\nexport class ServerSentEventTransformStream extends TransformStream<\n string,\n ServerSentEvent\n> {\n constructor() {\n super(new ServerSentEventTransformer());\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TextLineTransformStream } from './textLineTransformStream';\nimport {\n ServerSentEvent,\n ServerSentEventTransformStream,\n} from './serverSentEventTransformStream';\n\n/**\n * A ReadableStream of ServerSentEvent objects.\n */\nexport type ServerSentEventStream = ReadableStream<ServerSentEvent>;\n\n/**\n * Converts a Response object to a ServerSentEventStream.\n *\n * Processes the response body through a series of transform streams:\n * 1. TextDecoderStream: Decode Uint8Array data to UTF-8 strings\n * 2. TextLineStream: Split text by lines\n * 3. ServerSentEventStream: Parse line data into server-sent events\n *\n * @param response - The Response object to convert\n * @returns A ReadableStream of ServerSentEvent objects\n * @throws Error if the response body is null\n */\nexport function toServerSentEventStream(\n response: Response,\n): ServerSentEventStream {\n if (!response.body) {\n throw new Error('Response body is null');\n }\n\n return response.body\n .pipeThrough(new TextDecoderStream('utf-8'))\n .pipeThrough(new TextLineTransformStream())\n .pipeThrough(new ServerSentEventTransformStream());\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ServerSentEvent } from './serverSentEventTransformStream';\nimport { ServerSentEventStream } from './eventStreamConverter';\n\nexport interface JsonServerSentEvent<DATA> extends Omit<ServerSentEvent, 'data'> {\n data: DATA;\n}\n\nexport class JsonServerSentEventTransform<DATA> implements Transformer<ServerSentEvent, JsonServerSentEvent<DATA>> {\n transform(\n chunk: ServerSentEvent,\n controller: TransformStreamDefaultController<JsonServerSentEvent<DATA>>,\n ) {\n const json = JSON.parse(chunk.data) as DATA;\n controller.enqueue({\n data: json,\n event: chunk.event,\n id: chunk.id,\n retry: chunk.retry,\n });\n }\n}\n\nexport class JsonServerSentEventTransformStream<DATA> extends TransformStream<ServerSentEvent, JsonServerSentEvent<DATA>> {\n constructor() {\n super(new JsonServerSentEventTransform());\n }\n}\n\nexport type JsonServerSentEventStream<DATA> = ReadableStream<JsonServerSentEvent<DATA>>;\n\nexport function toJsonServerSentEventStream<DATA>(\n serverSentEventStream: ServerSentEventStream,\n): JsonServerSentEventStream<DATA> {\n return serverSentEventStream.pipeThrough(new JsonServerSentEventTransformStream<DATA>());\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { toServerSentEventStream } from './eventStreamConverter';\nimport {\n ContentTypeHeader,\n ContentTypeValues,\n FetchExchange,\n ResponseInterceptor,\n} from '@ahoo-wang/fetcher';\nimport { toJsonServerSentEventStream } from './jsonServerSentEventTransformStream';\n\n/**\n * The name of the EventStreamInterceptor.\n */\nexport const EVENT_STREAM_INTERCEPTOR_NAME = 'EventStreamInterceptor';\n\n/**\n * The order of the EventStreamInterceptor.\n * Set to Number.MAX_SAFE_INTEGER - 1000 to ensure it runs latest among response interceptors.\n */\nexport const EVENT_STREAM_INTERCEPTOR_ORDER = Number.MAX_SAFE_INTEGER - 1000;\n\n/**\n * Interceptor that enhances Response objects with event stream capabilities.\n *\n * This interceptor detects responses with `text/event-stream` content type and adds\n * an `eventStream()` method to the Response object, which returns a readable stream\n * of Server-Sent Events that can be consumed using `for await` syntax.\n *\n * @remarks\n * This interceptor runs at the very end of the response interceptor chain to ensure\n * it runs after all standard response processing is complete, as it adds\n * specialized functionality to the response object. The order is set to\n * EVENT_STREAM_INTERCEPTOR_ORDER to ensure it executes latest among response interceptors,\n * allowing for other response interceptors to run before it if needed. This positioning\n * ensures that all response processing is completed before specialized event stream\n * functionality is added to the response object.\n *\n * @example\n * ```typescript\n * // Using the eventStream method\n * const response = await fetcher.get('/events');\n * if (response.headers.get('content-type')?.includes('text/event-stream')) {\n * const eventStream = response.eventStream();\n * for await (const event of eventStream) {\n * console.log('Received event:', event);\n * }\n * }\n * ```\n */\nexport class EventStreamInterceptor implements ResponseInterceptor {\n readonly name = EVENT_STREAM_INTERCEPTOR_NAME;\n readonly order = EVENT_STREAM_INTERCEPTOR_ORDER;\n\n /**\n * Intercepts responses to add event stream capabilities.\n *\n * This method runs at the very end of the response interceptor chain to ensure\n * it runs after all standard response processing is complete. It detects responses\n * with `text/event-stream` content type and adds an `eventStream()` method to\n * the Response object, which returns a readable stream of Server-Sent Events.\n *\n * @param exchange - The exchange containing the response to enhance\n *\n * @remarks\n * This method executes latest among response interceptors to ensure all response\n * processing is completed before specialized event stream functionality is added.\n * It only enhances responses with `text/event-stream` content type, leaving other\n * responses unchanged. The positioning at the end of the response chain ensures\n * that all response transformations and validations are completed before event\n * stream capabilities are added to the response object.\n */\n intercept(exchange: FetchExchange) {\n // Check if the response is an event stream\n const response = exchange.response;\n if (!response) {\n return;\n }\n const contentType = response.headers.get(ContentTypeHeader);\n if (contentType?.includes(ContentTypeValues.TEXT_EVENT_STREAM)) {\n response.eventStream = () => toServerSentEventStream(response);\n response.jsonEventStream = () => toJsonServerSentEventStream(toServerSentEventStream(response));\n }\n }\n}\n"],"names":["TextLineTransformer","chunk","controller","lines","line","error","TextLineTransformStream","ServerSentEventField","processFieldInternal","field","value","currentEvent","retryValue","DEFAULT_EVENT_TYPE","ServerSentEventTransformer","colonIndex","ServerSentEventTransformStream","toServerSentEventStream","response","JsonServerSentEventTransform","json","JsonServerSentEventTransformStream","toJsonServerSentEventStream","serverSentEventStream","EVENT_STREAM_INTERCEPTOR_NAME","EVENT_STREAM_INTERCEPTOR_ORDER","EventStreamInterceptor","exchange","ContentTypeHeader","ContentTypeValues"],"mappings":";AAoBO,MAAMA,EAA2D;AAAA,EAAjE,cAAA;AACL,SAAQ,SAAS;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjB,UACEC,GACAC,GACA;AACA,QAAI;AACF,WAAK,UAAUD;AACf,YAAME,IAAQ,KAAK,OAAO,MAAM;AAAA,CAAI;AACp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AUE,GAAyB;AAEjC,UAAMT,IAAWS,EAAS;AAC1B,QAAI,CAACT;AACH;AAGF,IADoBA,EAAS,QAAQ,IAAIU,CAAiB,GACzC,SAASC,EAAkB,iBAAiB,MAC3DX,EAAS,cAAc,MAAMD,EAAwBC,CAAQ,GAC7DA,EAAS,kBAAkB,MAAMI,EAA4BL,EAAwBC,CAAQ,CAAC;AAAA,EAElG;AACF;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -2,3 +2,4 @@
|
|
|
2
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 c extends TransformStream{constructor(){super(new d)}}var u=(n=>(n.ID="id",n.RETRY="retry",n.EVENT="event",n.DATA="data",n))(u||{});function b(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}}}const f="message";class S{constructor(){this.currentEvent={event:f,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||f,data:r.data.join(`
|
|
3
3
|
`),id:r.id||"",retry:r.retry}),r.event=f,r.data=[]);return}if(t.startsWith(":"))return;const a=t.indexOf(":");let E,o;a===-1?(E=t.toLowerCase(),o=""):(E=t.substring(0,a).toLowerCase(),o=t.substring(a+1),o.startsWith(" ")&&(o=o.substring(1))),E=E.trim(),o=o.trim(),b(E,o,r)}catch(a){e.error(a instanceof Error?a:new Error(String(a))),r.event=f,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||f,data:e.data.join(`
|
|
4
4
|
`),id:e.id||"",retry:e.retry})}catch(r){t.error(r instanceof Error?r:new Error(String(r)))}finally{e.event=f,e.id=void 0,e.retry=void 0,e.data=[]}}}class m extends TransformStream{constructor(){super(new S)}}function T(n){if(!n.body)throw new Error("Response body is null");return n.body.pipeThrough(new TextDecoderStream("utf-8")).pipeThrough(new c).pipeThrough(new m)}class v{transform(t,e){const r=JSON.parse(t.data);e.enqueue({data:r,event:t.event,id:t.id,retry:t.retry})}}class h extends TransformStream{constructor(){super(new v)}}function y(n){return n.pipeThrough(new h)}const p="EventStreamInterceptor",R=Number.MAX_SAFE_INTEGER-1e3;class l{constructor(){this.name=p,this.order=R}intercept(t){const e=t.response;if(!e)return;e.headers.get(i.ContentTypeHeader)?.includes(i.ContentTypeValues.TEXT_EVENT_STREAM)&&(e.eventStream=()=>T(e),e.jsonEventStream=()=>y(T(e)))}}s.EVENT_STREAM_INTERCEPTOR_NAME=p,s.EVENT_STREAM_INTERCEPTOR_ORDER=R,s.EventStreamInterceptor=l,s.JsonServerSentEventTransform=v,s.JsonServerSentEventTransformStream=h,s.ServerSentEventField=u,s.ServerSentEventTransformStream=m,s.ServerSentEventTransformer=S,s.TextLineTransformStream=c,s.TextLineTransformer=d,s.toJsonServerSentEventStream=y,s.toServerSentEventStream=T,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
|
5
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/textLineTransformStream.ts","../src/serverSentEventTransformStream.ts","../src/eventStreamConverter.ts","../src/jsonServerSentEventTransformStream.ts","../src/eventStreamInterceptor.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Transformer that splits text into lines.\n *\n * This transformer accumulates chunks of text and splits them by newline characters,\n * emitting each line as a separate chunk while preserving the remaining buffer\n * for the next chunk.\n */\nexport class TextLineTransformer implements Transformer<string, string> {\n private buffer = '';\n\n /**\n * Transform input string chunk by splitting it into lines.\n *\n * @param chunk Input string chunk\n * @param controller Controller for controlling the transform stream\n */\n transform(\n chunk: string,\n controller: TransformStreamDefaultController<string>,\n ) {\n try {\n this.buffer += chunk;\n const lines = this.buffer.split('\\n');\n this.buffer = lines.pop() || '';\n\n for (const line of lines) {\n controller.enqueue(line);\n }\n } catch (error) {\n controller.error(error);\n }\n }\n\n /**\n * Flush remaining buffer when the stream ends.\n *\n * @param controller Controller for controlling the transform stream\n */\n flush(controller: TransformStreamDefaultController<string>) {\n try {\n // Only send when buffer is not empty, avoid sending meaningless empty lines\n if (this.buffer) {\n controller.enqueue(this.buffer);\n }\n } catch (error) {\n controller.error(error);\n }\n }\n}\n\n/**\n * A TransformStream that splits text into lines.\n */\nexport class TextLineTransformStream extends TransformStream<string, string> {\n constructor() {\n super(new TextLineTransformer());\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Represents a message sent in an event stream.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format}\n */\nexport interface ServerSentEvent {\n /** The event ID to set the EventSource object's last event ID value. */\n id?: string;\n /** A string identifying the type of event described. */\n event: string;\n /** The event data */\n data: string;\n /** The reconnection interval (in milliseconds) to wait before retrying the connection */\n retry?: number;\n}\n\nexport enum ServerSentEventField {\n ID = 'id',\n RETRY = 'retry',\n EVENT = 'event',\n DATA = 'data',\n}\n\n/**\n * Process field value\n * @param field Field name\n * @param value Field value\n * @param currentEvent Current event state\n */\nfunction processFieldInternal(\n field: string,\n value: string,\n currentEvent: EventState,\n) {\n switch (field) {\n case ServerSentEventField.EVENT:\n currentEvent.event = value;\n break;\n case ServerSentEventField.DATA:\n currentEvent.data.push(value);\n break;\n case ServerSentEventField.ID:\n currentEvent.id = value;\n break;\n case ServerSentEventField.RETRY: {\n const retryValue = parseInt(value, 10);\n if (!isNaN(retryValue)) {\n currentEvent.retry = retryValue;\n }\n break;\n }\n default:\n // Ignore unknown fields\n break;\n }\n}\n\ninterface EventState {\n event?: string;\n id?: string;\n retry?: number;\n data: string[];\n}\n\nconst DEFAULT_EVENT_TYPE = 'message';\n\n/**\n * Transformer responsible for converting a string stream into a ServerSentEvent object stream.\n *\n * Implements the Transformer interface for processing data transformation in TransformStream.\n */\nexport class ServerSentEventTransformer\n implements Transformer<string, ServerSentEvent>\n{\n // Initialize currentEvent with default values in a closure\n private currentEvent: EventState = {\n event: DEFAULT_EVENT_TYPE,\n id: undefined,\n retry: undefined,\n data: [],\n };\n\n /**\n * Transform input string chunk into ServerSentEvent object.\n *\n * @param chunk Input string chunk\n * @param controller Controller for controlling the transform stream\n */\n transform(\n chunk: string,\n controller: TransformStreamDefaultController<ServerSentEvent>,\n ) {\n const currentEvent = this.currentEvent;\n try {\n // Skip empty lines (event separator)\n if (chunk.trim() === '') {\n // If there is accumulated event data, send event\n if (currentEvent.data.length > 0) {\n controller.enqueue({\n event: currentEvent.event || DEFAULT_EVENT_TYPE,\n data: currentEvent.data.join('\\n'),\n id: currentEvent.id || '',\n retry: currentEvent.retry,\n } as ServerSentEvent);\n\n // Reset current event (preserve id and retry for subsequent events)\n currentEvent.event = DEFAULT_EVENT_TYPE;\n // Preserve id and retry for subsequent events (no need to reassign to themselves)\n currentEvent.data = [];\n }\n return;\n }\n\n // Ignore comment lines (starting with colon)\n if (chunk.startsWith(':')) {\n return;\n }\n\n // Parse fields\n const colonIndex = chunk.indexOf(':');\n let field: string;\n let value: string;\n\n if (colonIndex === -1) {\n // No colon, entire line as field name, value is empty\n field = chunk.toLowerCase();\n value = '';\n } else {\n // Extract field name and value\n field = chunk.substring(0, colonIndex).toLowerCase();\n value = chunk.substring(colonIndex + 1);\n\n // If value starts with space, remove leading space\n if (value.startsWith(' ')) {\n value = value.substring(1);\n }\n }\n\n // Remove trailing newlines from field and value\n field = field.trim();\n value = value.trim();\n\n processFieldInternal(field, value, currentEvent);\n } catch (error) {\n controller.error(\n error instanceof Error ? error : new Error(String(error)),\n );\n // Reset state\n currentEvent.event = DEFAULT_EVENT_TYPE;\n currentEvent.id = undefined;\n currentEvent.retry = undefined;\n currentEvent.data = [];\n }\n }\n\n /**\n * Called when the stream ends, used to process remaining data.\n *\n * @param controller Controller for controlling the transform stream\n */\n flush(controller: TransformStreamDefaultController<ServerSentEvent>) {\n const currentEvent = this.currentEvent;\n try {\n // Send the last event (if any)\n if (currentEvent.data.length > 0) {\n controller.enqueue({\n event: currentEvent.event || DEFAULT_EVENT_TYPE,\n data: currentEvent.data.join('\\n'),\n id: currentEvent.id || '',\n retry: currentEvent.retry,\n } as ServerSentEvent);\n }\n } catch (error) {\n controller.error(\n error instanceof Error ? error : new Error(String(error)),\n );\n } finally {\n // Reset state\n currentEvent.event = DEFAULT_EVENT_TYPE;\n currentEvent.id = undefined;\n currentEvent.retry = undefined;\n currentEvent.data = [];\n }\n }\n}\n\n/**\n * A TransformStream that converts a stream of strings into a stream of ServerSentEvent objects.\n */\nexport class ServerSentEventTransformStream extends TransformStream<\n string,\n ServerSentEvent\n> {\n constructor() {\n super(new ServerSentEventTransformer());\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TextLineTransformStream } from './textLineTransformStream';\nimport {\n ServerSentEvent,\n ServerSentEventTransformStream,\n} from './serverSentEventTransformStream';\n\n/**\n * A ReadableStream of ServerSentEvent objects.\n */\nexport type ServerSentEventStream = ReadableStream<ServerSentEvent>;\n\n/**\n * Converts a Response object to a ServerSentEventStream.\n *\n * Processes the response body through a series of transform streams:\n * 1. TextDecoderStream: Decode Uint8Array data to UTF-8 strings\n * 2. TextLineStream: Split text by lines\n * 3. ServerSentEventStream: Parse line data into server-sent events\n *\n * @param response - The Response object to convert\n * @returns A ReadableStream of ServerSentEvent objects\n * @throws Error if the response body is null\n */\nexport function toServerSentEventStream(\n response: Response,\n): ServerSentEventStream {\n if (!response.body) {\n throw new Error('Response body is null');\n }\n\n return response.body\n .pipeThrough(new TextDecoderStream('utf-8'))\n .pipeThrough(new TextLineTransformStream())\n .pipeThrough(new ServerSentEventTransformStream());\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ServerSentEvent } from './serverSentEventTransformStream';\nimport { ServerSentEventStream } from './eventStreamConverter';\n\nexport interface JsonServerSentEvent<DATA> extends Omit<ServerSentEvent, 'data'> {\n data: DATA;\n}\n\nexport class JsonServerSentEventTransform<DATA> implements Transformer<ServerSentEvent, JsonServerSentEvent<DATA>> {\n transform(\n chunk: ServerSentEvent,\n controller: TransformStreamDefaultController<JsonServerSentEvent<DATA>>,\n ) {\n const json = JSON.parse(chunk.data) as DATA;\n controller.enqueue({\n data: json,\n event: chunk.event,\n id: chunk.id,\n retry: chunk.retry,\n });\n }\n}\n\nexport class JsonServerSentEventTransformStream<DATA> extends TransformStream<ServerSentEvent, JsonServerSentEvent<DATA>> {\n constructor() {\n super(new JsonServerSentEventTransform());\n }\n}\n\nexport type JsonServerSentEventStream<DATA> = ReadableStream<JsonServerSentEvent<DATA>>;\n\nexport function toJsonServerSentEventStream<DATA>(\n serverSentEventStream: ServerSentEventStream,\n): JsonServerSentEventStream<DATA> {\n return serverSentEventStream.pipeThrough(new JsonServerSentEventTransformStream<DATA>());\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { toServerSentEventStream } from './eventStreamConverter';\nimport {\n ContentTypeHeader,\n ContentTypeValues,\n FetchExchange,\n ResponseInterceptor,\n} from '@ahoo-wang/fetcher';\nimport { toJsonServerSentEventStream } from './jsonServerSentEventTransformStream';\n\n/**\n * The name of the EventStreamInterceptor.\n */\nexport const EVENT_STREAM_INTERCEPTOR_NAME = 'EventStreamInterceptor';\n\n/**\n * The order of the EventStreamInterceptor.\n * Set to Number.MAX_SAFE_INTEGER - 1000 to ensure it runs latest among response interceptors.\n */\nexport const EVENT_STREAM_INTERCEPTOR_ORDER = Number.MAX_SAFE_INTEGER - 1000;\n\n/**\n * Interceptor that enhances Response objects with event stream capabilities.\n *\n * This interceptor detects responses with `text/event-stream` content type and adds\n * an `eventStream()` method to the Response object, which returns a readable stream\n * of Server-Sent Events that can be consumed using `for await` syntax.\n *\n * @remarks\n * This interceptor runs at the very end of the response interceptor chain to ensure\n * it runs after all standard response processing is complete, as it adds\n * specialized functionality to the response object. The order is set to\n * EVENT_STREAM_INTERCEPTOR_ORDER to ensure it executes latest among response interceptors,\n * allowing for other response interceptors to run before it if needed. This positioning\n * ensures that all response processing is completed before specialized event stream\n * functionality is added to the response object.\n *\n * @example\n * ```typescript\n * // Using the eventStream method\n * const response = await fetcher.get('/events');\n * if (response.headers.get('content-type')?.includes('text/event-stream')) {\n * const eventStream = response.eventStream();\n * for await (const event of eventStream) {\n * console.log('Received event:', event);\n * }\n * }\n * ```\n */\nexport class EventStreamInterceptor implements ResponseInterceptor {\n readonly name = EVENT_STREAM_INTERCEPTOR_NAME;\n readonly order = EVENT_STREAM_INTERCEPTOR_ORDER;\n\n /**\n * Intercepts responses to add event stream capabilities.\n *\n * This method runs at the very end of the response interceptor chain to ensure\n * it runs after all standard response processing is complete. It detects responses\n * with `text/event-stream` content type and adds an `eventStream()` method to\n * the Response object, which returns a readable stream of Server-Sent Events.\n *\n * @param exchange - The exchange containing the response to enhance\n *\n * @remarks\n * This method executes latest among response interceptors to ensure all response\n * processing is completed before specialized event stream functionality is added.\n * It only enhances responses with `text/event-stream` content type, leaving other\n * responses unchanged. The positioning at the end of the response chain ensures\n * that all response transformations and validations are completed before event\n * stream capabilities are added to the response object.\n */\n intercept(exchange: FetchExchange) {\n // Check if the response is an event stream\n const response = exchange.response;\n if (!response) {\n return;\n }\n const contentType = response.headers.get(ContentTypeHeader);\n if (contentType?.includes(ContentTypeValues.TEXT_EVENT_STREAM)) {\n response.eventStream = () => toServerSentEventStream(response);\n response.jsonEventStream = () => toJsonServerSentEventStream(toServerSentEventStream(response));\n }\n }\n}\n"],"names":["TextLineTransformer","chunk","controller","lines","line","error","TextLineTransformStream","ServerSentEventField","processFieldInternal","field","value","currentEvent","retryValue","DEFAULT_EVENT_TYPE","ServerSentEventTransformer","colonIndex","ServerSentEventTransformStream","toServerSentEventStream","response","JsonServerSentEventTransform","json","JsonServerSentEventTransformStream","toJsonServerSentEventStream","serverSentEventStream","EVENT_STREAM_INTERCEPTOR_NAME","EVENT_STREAM_INTERCEPTOR_ORDER","EventStreamInterceptor","exchange","ContentTypeHeader","ContentTypeValues"],"mappings":"0SAoBO,MAAMA,CAA2D,CAAjE,aAAA,CACL,KAAQ,OAAS,EAAA,CAQjB,UACEC,EACAC,EACA,CACA,GAAI,CACF,KAAK,QAAUD,EACf,MAAME,EAAQ,KAAK,OAAO,MAAM;AAAA,CAAI,EACpC,KAAK,OAASA,EAAM,IAAA,GAAS,GAE7B,UAAWC,KAAQD,EACjBD,EAAW,QAAQE,CAAI,CAE3B,OAASC,EAAO,CACdH,EAAW,MAAMG,CAAK,CACxB,CACF,CAOA,MAAMH,EAAsD,CAC1D,GAAI,CAEE,KAAK,QACPA,EAAW,QAAQ,KAAK,MAAM,CAElC,OAASG,EAAO,CACdH,EAAW,MAAMG,CAAK,CACxB,CACF,CACF,CAKO,MAAMC,UAAgC,eAAgC,CAC3E,aAAc,CACZ,MAAM,IAAIN,CAAqB,CACjC,CACF,CCzCO,IAAKO,GAAAA,IACVA,EAAA,GAAK,KACLA,EAAA,MAAQ,QACRA,EAAA,MAAQ,QACRA,EAAA,KAAO,OAJGA,IAAAA,GAAA,CAAA,CAAA,EAaZ,SAASC,EACPC,EACAC,EACAC,EACA,CACA,OAAQF,EAAA,CACN,IAAK,QACHE,EAAa,MAAQD,EACrB,MACF,IAAK,OACHC,EAAa,KAAK,KAAKD,CAAK,EAC5B,MACF,IAAK,KACHC,EAAa,GAAKD,EAClB,MACF,IAAK,QAA4B,CAC/B,MAAME,EAAa,SAASF,EAAO,EAAE,EAChC,MAAME,CAAU,IACnBD,EAAa,MAAQC,GAEvB,KACF,CAGE,CAEN,CASA,MAAMC,EAAqB,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BL,EAAwBC,CAAQ,CAAC,EAElG,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/fetcher-eventstream",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "Server-Sent Events (SSE) support for Fetcher HTTP client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ahoo-wang/fetcher": "0.11.
|
|
37
|
+
"@ahoo-wang/fetcher": "0.11.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@vitest/coverage-v8": "^3.2.4",
|