@glamboyosa/ore 0.0.1 → 0.0.3
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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +33 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -10
- package/readme.md +79 -0
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,7 @@ declare class Ore {
|
|
|
10
10
|
private maxRetries;
|
|
11
11
|
constructor(options: OreOptions);
|
|
12
12
|
fetchSSE(onBufferReceived: (buffer: string, parts: Array<string>) => void, onStreamEnded?: (streamEnded: boolean) => void, customHeaders?: HeadersInit, retries?: number): void;
|
|
13
|
+
fetchSSEForRSC(customHeaders?: HeadersInit, retries?: number): Promise<ReadableStream<Uint8Array> | null | undefined>;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export { Ore, type OreOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare class Ore {
|
|
|
10
10
|
private maxRetries;
|
|
11
11
|
constructor(options: OreOptions);
|
|
12
12
|
fetchSSE(onBufferReceived: (buffer: string, parts: Array<string>) => void, onStreamEnded?: (streamEnded: boolean) => void, customHeaders?: HeadersInit, retries?: number): void;
|
|
13
|
+
fetchSSEForRSC(customHeaders?: HeadersInit, retries?: number): Promise<ReadableStream<Uint8Array> | null | undefined>;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export { Ore, type OreOptions };
|
package/dist/index.js
CHANGED
|
@@ -59,7 +59,10 @@ var Ore = class {
|
|
|
59
59
|
const reader = response.body?.getReader();
|
|
60
60
|
const decoder = new TextDecoder("utf-8");
|
|
61
61
|
let buffer = "";
|
|
62
|
-
const processText = ({
|
|
62
|
+
const processText = ({
|
|
63
|
+
done,
|
|
64
|
+
value
|
|
65
|
+
}) => {
|
|
63
66
|
if (done) {
|
|
64
67
|
this.streamEnded = true;
|
|
65
68
|
if (onStreamEnded) {
|
|
@@ -79,7 +82,9 @@ var Ore = class {
|
|
|
79
82
|
this.retryCount++;
|
|
80
83
|
setTimeout(fetchWithRetry, 1e3);
|
|
81
84
|
} else {
|
|
82
|
-
console.error(
|
|
85
|
+
console.error(
|
|
86
|
+
"Max retries exceeded. Cannot establish SSE connection."
|
|
87
|
+
);
|
|
83
88
|
this.streamEnded = true;
|
|
84
89
|
if (onStreamEnded) {
|
|
85
90
|
onStreamEnded(this.streamEnded);
|
|
@@ -93,7 +98,9 @@ var Ore = class {
|
|
|
93
98
|
this.retryCount++;
|
|
94
99
|
setTimeout(fetchWithRetry, 1e3);
|
|
95
100
|
} else {
|
|
96
|
-
console.error(
|
|
101
|
+
console.error(
|
|
102
|
+
"Max retries exceeded. Cannot establish SSE connection."
|
|
103
|
+
);
|
|
97
104
|
this.streamEnded = true;
|
|
98
105
|
if (onStreamEnded) {
|
|
99
106
|
onStreamEnded(this.streamEnded);
|
|
@@ -103,6 +110,29 @@ var Ore = class {
|
|
|
103
110
|
};
|
|
104
111
|
fetchWithRetry();
|
|
105
112
|
}
|
|
113
|
+
async fetchSSEForRSC(customHeaders, retries = this.maxRetries) {
|
|
114
|
+
const headers = { ...this.headers, ...customHeaders };
|
|
115
|
+
try {
|
|
116
|
+
const response = await fetch(this.url, {
|
|
117
|
+
method: "GET",
|
|
118
|
+
headers
|
|
119
|
+
});
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
throw new Error("Failed to connect to SSE endpoint");
|
|
122
|
+
}
|
|
123
|
+
this.retryCount = 0;
|
|
124
|
+
return response.body;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (this.retryCount < retries) {
|
|
127
|
+
console.error("Error:", error);
|
|
128
|
+
console.log("Retrying...");
|
|
129
|
+
this.retryCount++;
|
|
130
|
+
setTimeout(() => this.fetchSSEForRSC(customHeaders, retries), 1e3);
|
|
131
|
+
} else {
|
|
132
|
+
console.error("Max retries exceeded. Cannot establish SSE connection.");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
106
136
|
};
|
|
107
137
|
// Annotate the CommonJS export names for ESM import in node:
|
|
108
138
|
0 && (module.exports = {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export * from \"./client\";\n","interface OreOptions {\n url: string;\n headers?: HeadersInit;\n}\n\nclass Ore {\n private url: string;\n private headers?: HeadersInit;\n private streamEnded = false;\n private retryCount = 0;\n private maxRetries = 3;\n\n constructor(options: OreOptions) {\n this.url = options.url;\n this.headers = options.headers\n ? {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n ...options.headers,\n }\n : {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n };\n }\n\n public fetchSSE(\n onBufferReceived: (buffer: string, parts: Array<string>) => void,\n onStreamEnded?: (streamEnded: boolean) => void,\n customHeaders?: HeadersInit,\n retries: number = this.maxRetries
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export * from \"./client\";\n","interface OreOptions {\n url: string;\n headers?: HeadersInit;\n}\n\nclass Ore {\n private url: string;\n private headers?: HeadersInit;\n private streamEnded = false;\n private retryCount = 0;\n private maxRetries = 3;\n\n constructor(options: OreOptions) {\n this.url = options.url;\n this.headers = options.headers\n ? {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n ...options.headers,\n }\n : {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n };\n }\n\n public fetchSSE(\n onBufferReceived: (buffer: string, parts: Array<string>) => void,\n onStreamEnded?: (streamEnded: boolean) => void,\n customHeaders?: HeadersInit,\n retries: number = this.maxRetries\n ): void {\n const headers = { ...this.headers, ...customHeaders };\n\n const fetchWithRetry = async (): Promise<void> => {\n try {\n const response = await fetch(this.url, {\n method: \"GET\",\n headers: headers,\n });\n\n if (!response.ok) {\n throw new Error(\"Failed to connect to SSE endpoint\");\n }\n\n this.retryCount = 0;\n\n const reader = response.body?.getReader();\n const decoder = new TextDecoder(\"utf-8\");\n let buffer = \"\";\n const processText = ({\n done,\n value,\n }: ReadableStreamReadResult<Uint8Array>): any => {\n if (done) {\n this.streamEnded = true;\n if (onStreamEnded) {\n onStreamEnded(this.streamEnded);\n }\n return;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const parts = buffer.split(\"\\n\\n\");\n\n onBufferReceived(buffer, parts);\n\n return reader!.read().then(processText);\n };\n reader\n ?.read()\n .then(processText)\n .catch((error) => {\n if (this.retryCount < retries) {\n console.error(\"Error:\", error);\n console.log(\"Retrying...\");\n this.retryCount++;\n setTimeout(fetchWithRetry, 1000);\n } else {\n console.error(\n \"Max retries exceeded. Cannot establish SSE connection.\"\n );\n this.streamEnded = true;\n if (onStreamEnded) {\n onStreamEnded(this.streamEnded);\n }\n }\n });\n } catch (error) {\n if (this.retryCount < retries) {\n console.error(\"Error:\", error);\n console.log(\"Retrying...\");\n this.retryCount++;\n setTimeout(fetchWithRetry, 1000);\n } else {\n console.error(\n \"Max retries exceeded. Cannot establish SSE connection.\"\n );\n this.streamEnded = true;\n if (onStreamEnded) {\n onStreamEnded(this.streamEnded);\n }\n }\n }\n };\n\n fetchWithRetry();\n }\n public async fetchSSEForRSC(\n customHeaders?: HeadersInit,\n retries: number = this.maxRetries\n ) {\n const headers = { ...this.headers, ...customHeaders };\n\n try {\n const response = await fetch(this.url, {\n method: \"GET\",\n headers: headers,\n });\n\n if (!response.ok) {\n throw new Error(\"Failed to connect to SSE endpoint\");\n }\n\n this.retryCount = 0;\n\n return response.body;\n } catch (error) {\n if (this.retryCount < retries) {\n console.error(\"Error:\", error);\n console.log(\"Retrying...\");\n this.retryCount++;\n setTimeout(() => this.fetchSSEForRSC(customHeaders, retries), 1000);\n } else {\n console.error(\"Max retries exceeded. Cannot establish SSE connection.\");\n }\n }\n }\n}\n\nexport { Ore, type OreOptions };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAM,MAAN,MAAU;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,aAAa;AAAA,EACb,aAAa;AAAA,EAErB,YAAY,SAAqB;AAC/B,SAAK,MAAM,QAAQ;AACnB,SAAK,UAAU,QAAQ,UACnB;AAAA,MACE,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,YAAY;AAAA,MACZ,GAAG,QAAQ;AAAA,IACb,IACA;AAAA,MACE,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,YAAY;AAAA,IACd;AAAA,EACN;AAAA,EAEO,SACL,kBACA,eACA,eACA,UAAkB,KAAK,YACjB;AACN,UAAM,UAAU,EAAE,GAAG,KAAK,SAAS,GAAG,cAAc;AAEpD,UAAM,iBAAiB,YAA2B;AAChD,UAAI;AACF,cAAM,WAAW,MAAM,MAAM,KAAK,KAAK;AAAA,UACrC,QAAQ;AAAA,UACR;AAAA,QACF,CAAC;AAED,YAAI,CAAC,SAAS,IAAI;AAChB,gBAAM,IAAI,MAAM,mCAAmC;AAAA,QACrD;AAEA,aAAK,aAAa;AAElB,cAAM,SAAS,SAAS,MAAM,UAAU;AACxC,cAAM,UAAU,IAAI,YAAY,OAAO;AACvC,YAAI,SAAS;AACb,cAAM,cAAc,CAAC;AAAA,UACnB;AAAA,UACA;AAAA,QACF,MAAiD;AAC/C,cAAI,MAAM;AACR,iBAAK,cAAc;AACnB,gBAAI,eAAe;AACjB,4BAAc,KAAK,WAAW;AAAA,YAChC;AACA;AAAA,UACF;AAEA,oBAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAEhD,gBAAM,QAAQ,OAAO,MAAM,MAAM;AAEjC,2BAAiB,QAAQ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I;AAAA,MACpE,OAAO;AACL,gBAAQ,MAAM,wDAAwD;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -33,7 +33,10 @@ var Ore = class {
|
|
|
33
33
|
const reader = response.body?.getReader();
|
|
34
34
|
const decoder = new TextDecoder("utf-8");
|
|
35
35
|
let buffer = "";
|
|
36
|
-
const processText = ({
|
|
36
|
+
const processText = ({
|
|
37
|
+
done,
|
|
38
|
+
value
|
|
39
|
+
}) => {
|
|
37
40
|
if (done) {
|
|
38
41
|
this.streamEnded = true;
|
|
39
42
|
if (onStreamEnded) {
|
|
@@ -53,7 +56,9 @@ var Ore = class {
|
|
|
53
56
|
this.retryCount++;
|
|
54
57
|
setTimeout(fetchWithRetry, 1e3);
|
|
55
58
|
} else {
|
|
56
|
-
console.error(
|
|
59
|
+
console.error(
|
|
60
|
+
"Max retries exceeded. Cannot establish SSE connection."
|
|
61
|
+
);
|
|
57
62
|
this.streamEnded = true;
|
|
58
63
|
if (onStreamEnded) {
|
|
59
64
|
onStreamEnded(this.streamEnded);
|
|
@@ -67,7 +72,9 @@ var Ore = class {
|
|
|
67
72
|
this.retryCount++;
|
|
68
73
|
setTimeout(fetchWithRetry, 1e3);
|
|
69
74
|
} else {
|
|
70
|
-
console.error(
|
|
75
|
+
console.error(
|
|
76
|
+
"Max retries exceeded. Cannot establish SSE connection."
|
|
77
|
+
);
|
|
71
78
|
this.streamEnded = true;
|
|
72
79
|
if (onStreamEnded) {
|
|
73
80
|
onStreamEnded(this.streamEnded);
|
|
@@ -77,6 +84,29 @@ var Ore = class {
|
|
|
77
84
|
};
|
|
78
85
|
fetchWithRetry();
|
|
79
86
|
}
|
|
87
|
+
async fetchSSEForRSC(customHeaders, retries = this.maxRetries) {
|
|
88
|
+
const headers = { ...this.headers, ...customHeaders };
|
|
89
|
+
try {
|
|
90
|
+
const response = await fetch(this.url, {
|
|
91
|
+
method: "GET",
|
|
92
|
+
headers
|
|
93
|
+
});
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error("Failed to connect to SSE endpoint");
|
|
96
|
+
}
|
|
97
|
+
this.retryCount = 0;
|
|
98
|
+
return response.body;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (this.retryCount < retries) {
|
|
101
|
+
console.error("Error:", error);
|
|
102
|
+
console.log("Retrying...");
|
|
103
|
+
this.retryCount++;
|
|
104
|
+
setTimeout(() => this.fetchSSEForRSC(customHeaders, retries), 1e3);
|
|
105
|
+
} else {
|
|
106
|
+
console.error("Max retries exceeded. Cannot establish SSE connection.");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
80
110
|
};
|
|
81
111
|
export {
|
|
82
112
|
Ore
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["interface OreOptions {\n url: string;\n headers?: HeadersInit;\n}\n\nclass Ore {\n private url: string;\n private headers?: HeadersInit;\n private streamEnded = false;\n private retryCount = 0;\n private maxRetries = 3;\n\n constructor(options: OreOptions) {\n this.url = options.url;\n this.headers = options.headers\n ? {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n ...options.headers,\n }\n : {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n };\n }\n\n public fetchSSE(\n onBufferReceived: (buffer: string, parts: Array<string>) => void,\n onStreamEnded?: (streamEnded: boolean) => void,\n customHeaders?: HeadersInit,\n retries: number = this.maxRetries
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["interface OreOptions {\n url: string;\n headers?: HeadersInit;\n}\n\nclass Ore {\n private url: string;\n private headers?: HeadersInit;\n private streamEnded = false;\n private retryCount = 0;\n private maxRetries = 3;\n\n constructor(options: OreOptions) {\n this.url = options.url;\n this.headers = options.headers\n ? {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n ...options.headers,\n }\n : {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n };\n }\n\n public fetchSSE(\n onBufferReceived: (buffer: string, parts: Array<string>) => void,\n onStreamEnded?: (streamEnded: boolean) => void,\n customHeaders?: HeadersInit,\n retries: number = this.maxRetries\n ): void {\n const headers = { ...this.headers, ...customHeaders };\n\n const fetchWithRetry = async (): Promise<void> => {\n try {\n const response = await fetch(this.url, {\n method: \"GET\",\n headers: headers,\n });\n\n if (!response.ok) {\n throw new Error(\"Failed to connect to SSE endpoint\");\n }\n\n this.retryCount = 0;\n\n const reader = response.body?.getReader();\n const decoder = new TextDecoder(\"utf-8\");\n let buffer = \"\";\n const processText = ({\n done,\n value,\n }: ReadableStreamReadResult<Uint8Array>): any => {\n if (done) {\n this.streamEnded = true;\n if (onStreamEnded) {\n onStreamEnded(this.streamEnded);\n }\n return;\n }\n\n buffer += decoder.decode(value, { stream: true });\n\n const parts = buffer.split(\"\\n\\n\");\n\n onBufferReceived(buffer, parts);\n\n return reader!.read().then(processText);\n };\n reader\n ?.read()\n .then(processText)\n .catch((error) => {\n if (this.retryCount < retries) {\n console.error(\"Error:\", error);\n console.log(\"Retrying...\");\n this.retryCount++;\n setTimeout(fetchWithRetry, 1000);\n } else {\n console.error(\n \"Max retries exceeded. Cannot establish SSE connection.\"\n );\n this.streamEnded = true;\n if (onStreamEnded) {\n onStreamEnded(this.streamEnded);\n }\n }\n });\n } catch (error) {\n if (this.retryCount < retries) {\n console.error(\"Error:\", error);\n console.log(\"Retrying...\");\n this.retryCount++;\n setTimeout(fetchWithRetry, 1000);\n } else {\n console.error(\n \"Max retries exceeded. Cannot establish SSE connection.\"\n );\n this.streamEnded = true;\n if (onStreamEnded) {\n onStreamEnded(this.streamEnded);\n }\n }\n }\n };\n\n fetchWithRetry();\n }\n public async fetchSSEForRSC(\n customHeaders?: HeadersInit,\n retries: number = this.maxRetries\n ) {\n const headers = { ...this.headers, ...customHeaders };\n\n try {\n const response = await fetch(this.url, {\n method: \"GET\",\n headers: headers,\n });\n\n if (!response.ok) {\n throw new Error(\"Failed to connect to SSE endpoint\");\n }\n\n this.retryCount = 0;\n\n return response.body;\n } catch (error) {\n if (this.retryCount < retries) {\n console.error(\"Error:\", error);\n console.log(\"Retrying...\");\n this.retryCount++;\n setTimeout(() => this.fetchSSEForRSC(customHeaders, retries), 1000);\n } else {\n console.error(\"Max retries exceeded. Cannot establish SSE connection.\");\n }\n }\n }\n}\n\nexport { Ore, type OreOptions };\n"],"mappings":";AAKA,IAAM,MAAN,MAAU;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,aAAa;AAAA,EACb,aAAa;AAAA,EAErB,YAAY,SAAqB;AAC/B,SAAK,MAAM,QAAQ;AACnB,SAAK,UAAU,QAAQ,UACnB;AAAA,MACE,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,YAAY;AAAA,MACZ,GAAG,QAAQ;AAAA,IACb,IACA;AAAA,MACE,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,YAAY;AAAA,IACd;AAAA,EACN;AAAA,EAEO,SACL,kBACA,eACA,eACA,UAAkB,KAAK,YACjB;AACN,UAAM,UAAU,EAAE,GAAG,KAAK,SAAS,GAAG,cAAc;AAEpD,UAAM,iBAAiB,YAA2B;AAChD,UAAI;AACF,cAAM,WAAW,MAAM,MAAM,KAAK,KAAK;AAAA,UACrC,QAAQ;AAAA,UACR;AAAA,QACF,CAAC;AAED,YAAI,CAAC,SAAS,IAAI;AAChB,gBAAM,IAAI,MAAM,mCAAmC;AAAA,QACrD;AAEA,aAAK,aAAa;AAElB,cAAM,SAAS,SAAS,MAAM,UAAU;AACxC,cAAM,UAAU,IAAI,YAAY,OAAO;AACvC,YAAI,SAAS;AACb,cAAM,cAAc,CAAC;AAAA,UACnB;AAAA,UACA;AAAA,QACF,MAAiD;A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AAAA,MACrD;AAEA,WAAK,aAAa;AAElB,aAAO,SAAS;AAAA,IAClB,SAAS,OAAO;AACd,UAAI,KAAK,aAAa,SAAS;AAC7B,gBAAQ,MAAM,UAAU,KAAK;AAC7B,gBAAQ,IAAI,aAAa;AACzB,aAAK;AACL,mBAAW,MAAM,KAAK,eAAe,eAAe,OAAO,GAAG,GAAI;AAAA,MACpE,OAAO;AACL,gBAAQ,MAAM,wDAAwD;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glamboyosa/ore",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -9,19 +9,12 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
"@glamboyosa/ore",
|
|
14
|
-
"server-sent events",
|
|
15
|
-
"SSE",
|
|
16
|
-
"api"
|
|
17
|
-
],
|
|
12
|
+
"keywords": ["@glamboyosa/ore", "server-sent events", "SSE", "api"],
|
|
18
13
|
"scripts": {
|
|
19
14
|
"build": "tsup",
|
|
20
15
|
"fmt": "pnpm biome format . --write && pnpm biome check . --apply-unsafe "
|
|
21
16
|
},
|
|
22
|
-
"files": [
|
|
23
|
-
"./dist/**"
|
|
24
|
-
],
|
|
17
|
+
"files": ["./dist/**"],
|
|
25
18
|
"devDependencies": {
|
|
26
19
|
"@biomejs/biome": "^1.6.3",
|
|
27
20
|
"@types/node": "^20.11.30",
|
package/readme.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Ore
|
|
2
|
+
|
|
3
|
+
Ore is a JavaScript / TypeScript package that simplifies the consumption of Server-Sent Events (SSE) in web applications. It provides an easy-to-use interface for establishing SSE connections, handling incoming events, and implementing retry strategies in case of connection failures.
|
|
4
|
+
|
|
5
|
+
## Motivation
|
|
6
|
+
|
|
7
|
+
Consuming Server-Sent Events (SSE) or streaming data in web applications isn't always well-documented and can be complex or just plain unreliable to implement. Ore aims to simplify this process by providing a straightforward and reliable way to consume SSE streams.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Establish SSE connections with ease.
|
|
12
|
+
- Handle incoming SSE events and process them accordingly.
|
|
13
|
+
- Implement retry strategies for reconnecting to the SSE endpoint in case of connection failures.
|
|
14
|
+
- Customizable headers for SSE requests.
|
|
15
|
+
- Set maximum retries for connection attempts.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @glamboyosa/ore
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import Ore from "@glamboyosa/ore";
|
|
27
|
+
|
|
28
|
+
// Initialize Ore with URL and optional headers
|
|
29
|
+
const ore = new Ore({
|
|
30
|
+
url: "http://example.com/sse-endpoint",
|
|
31
|
+
headers: {
|
|
32
|
+
"Cache-Control": "no-cache",
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Start SSE connection
|
|
37
|
+
ore.fetchSSE(
|
|
38
|
+
(buffer, parts) => {
|
|
39
|
+
console.log("Received buffer:", buffer);
|
|
40
|
+
// Process the received buffer
|
|
41
|
+
|
|
42
|
+
const b = parts[parts.length - 1];
|
|
43
|
+
console.log("Received parts i.e. events", parts);
|
|
44
|
+
console.log("Buffer per event", b);
|
|
45
|
+
// process the buffer per event
|
|
46
|
+
},
|
|
47
|
+
() => {
|
|
48
|
+
console.log("Stream ended");
|
|
49
|
+
// Handle stream end
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Class Parameters
|
|
55
|
+
|
|
56
|
+
- `url`: `string` - The URL of the SSE endpoint.
|
|
57
|
+
- `headers`: `HeadersInit` (optional) - Optional headers to include in the SSE request. Must be an object where keys are header names and values are header values.
|
|
58
|
+
|
|
59
|
+
## `fetchSSE` Function Parameters
|
|
60
|
+
|
|
61
|
+
- `onBufferReceived`: `function` - Callback function to handle received SSE buffers. Receives the buffer and the optionally the parts i.e. new events as a parameter.
|
|
62
|
+
- `onStreamEnded`: `function` - Callback function to handle stream end events. Receives the internal state of if the buffer stream is ended.
|
|
63
|
+
- `retries`: `number` (optional) - Optional parameter to specify the maximum number of retry attempts. Default is 3.
|
|
64
|
+
|
|
65
|
+
## Working with React Server Components
|
|
66
|
+
|
|
67
|
+
While Ore is intended to work with client components, it is possible to use it in server components using the `fetchSSEForRSC` function. The function takes optional `retries`: `number` (optional) - Optional parameter to specify the maximum number of retry attempts. Default is 3. and `customHeaders`: `HeadersInit` (optional) - Optional headers to include in the SSE request. Must be an object where keys are header names and values are header values.
|
|
68
|
+
|
|
69
|
+
### Usage with RSCs
|
|
70
|
+
|
|
71
|
+
Checkout the `next-js-example` directory for a full example on how to use it with Server Components [here](https://github.com/glamboyosa/ore/blob/main/examples/next-js-example/src/app/page.tsx)
|
|
72
|
+
|
|
73
|
+
## Contributing
|
|
74
|
+
|
|
75
|
+
Contributions to @glamboyosa/ore are welcome! If you have suggestions for improvements or encounter any issues, feel free to open an issue or submit a pull request on GitHub.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
This project is licensed under the MIT License.
|