librechat-data-provider 0.1.0 → 0.1.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 +117 -112
- package/dist/index.js +117 -112
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/{sse.mjs → sse.js} +52 -47
- package/src/types.ts +1 -1
- package/types/index.d.ts +1 -1
- package/.github/workflows/npm-publish.yml +0 -33
package/dist/index.es.js
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
3
|
|
|
4
|
-
/******************************************************************************
|
|
5
|
-
Copyright (c) Microsoft Corporation.
|
|
6
|
-
|
|
7
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
-
purpose with or without fee is hereby granted.
|
|
9
|
-
|
|
10
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
17
|
-
***************************************************************************** */
|
|
18
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var __assign = function() {
|
|
22
|
-
__assign = Object.assign || function __assign(t) {
|
|
23
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
24
|
-
s = arguments[i];
|
|
25
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
26
|
-
}
|
|
27
|
-
return t;
|
|
28
|
-
};
|
|
29
|
-
return __assign.apply(this, arguments);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function __generator(thisArg, body) {
|
|
43
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
44
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
45
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
46
|
-
function step(op) {
|
|
47
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
48
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
49
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
50
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
51
|
-
switch (op[0]) {
|
|
52
|
-
case 0: case 1: t = op; break;
|
|
53
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
54
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
55
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
56
|
-
default:
|
|
57
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
58
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
59
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
60
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
61
|
-
if (t[2]) _.ops.pop();
|
|
62
|
-
_.trys.pop(); continue;
|
|
63
|
-
}
|
|
64
|
-
op = body.call(thisArg, _);
|
|
65
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
66
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
71
|
-
var e = new Error(message);
|
|
72
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
4
|
+
/******************************************************************************
|
|
5
|
+
Copyright (c) Microsoft Corporation.
|
|
6
|
+
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
+
purpose with or without fee is hereby granted.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
17
|
+
***************************************************************************** */
|
|
18
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var __assign = function() {
|
|
22
|
+
__assign = Object.assign || function __assign(t) {
|
|
23
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
24
|
+
s = arguments[i];
|
|
25
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
26
|
+
}
|
|
27
|
+
return t;
|
|
28
|
+
};
|
|
29
|
+
return __assign.apply(this, arguments);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function __generator(thisArg, body) {
|
|
43
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
44
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
45
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
46
|
+
function step(op) {
|
|
47
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
48
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
49
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
50
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
51
|
+
switch (op[0]) {
|
|
52
|
+
case 0: case 1: t = op; break;
|
|
53
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
54
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
55
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
56
|
+
default:
|
|
57
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
58
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
59
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
60
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
61
|
+
if (t[2]) _.ops.pop();
|
|
62
|
+
_.trys.pop(); continue;
|
|
63
|
+
}
|
|
64
|
+
op = body.call(thisArg, _);
|
|
65
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
66
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
71
|
+
var e = new Error(message);
|
|
72
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
function _get(url, options) {
|
|
@@ -525,6 +525,7 @@ function setTokenHeader(token) {
|
|
|
525
525
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
|
|
526
526
|
}
|
|
527
527
|
|
|
528
|
+
/* eslint-disable */
|
|
528
529
|
/**
|
|
529
530
|
* Copyright (C) 2016 Maxime Petazzoni <maxime.petazzoni@bulix.org>.
|
|
530
531
|
* All rights reserved.
|
|
@@ -545,7 +546,7 @@ var SSE = function (url, options) {
|
|
|
545
546
|
options = options || {};
|
|
546
547
|
this.headers = options.headers || {};
|
|
547
548
|
this.payload = options.payload !== undefined ? options.payload : '';
|
|
548
|
-
this.method = options.method || (this.payload && 'POST' || 'GET'
|
|
549
|
+
this.method = options.method || (this.payload && 'POST') || 'GET';
|
|
549
550
|
this.withCredentials = !!options.withCredentials;
|
|
550
551
|
|
|
551
552
|
this.FIELD_SEPARATOR = ':';
|
|
@@ -556,7 +557,7 @@ var SSE = function (url, options) {
|
|
|
556
557
|
this.progress = 0;
|
|
557
558
|
this.chunk = '';
|
|
558
559
|
|
|
559
|
-
this.addEventListener = function(type, listener) {
|
|
560
|
+
this.addEventListener = function (type, listener) {
|
|
560
561
|
if (this.listeners[type] === undefined) {
|
|
561
562
|
this.listeners[type] = [];
|
|
562
563
|
}
|
|
@@ -566,13 +567,13 @@ var SSE = function (url, options) {
|
|
|
566
567
|
}
|
|
567
568
|
};
|
|
568
569
|
|
|
569
|
-
this.removeEventListener = function(type, listener) {
|
|
570
|
+
this.removeEventListener = function (type, listener) {
|
|
570
571
|
if (this.listeners[type] === undefined) {
|
|
571
572
|
return;
|
|
572
573
|
}
|
|
573
574
|
|
|
574
575
|
var filtered = [];
|
|
575
|
-
this.listeners[type].forEach(function(element) {
|
|
576
|
+
this.listeners[type].forEach(function (element) {
|
|
576
577
|
if (element !== listener) {
|
|
577
578
|
filtered.push(element);
|
|
578
579
|
}
|
|
@@ -584,7 +585,7 @@ var SSE = function (url, options) {
|
|
|
584
585
|
}
|
|
585
586
|
};
|
|
586
587
|
|
|
587
|
-
this.dispatchEvent = function(e) {
|
|
588
|
+
this.dispatchEvent = function (e) {
|
|
588
589
|
if (!e) {
|
|
589
590
|
return true;
|
|
590
591
|
}
|
|
@@ -600,7 +601,7 @@ var SSE = function (url, options) {
|
|
|
600
601
|
}
|
|
601
602
|
|
|
602
603
|
if (this.listeners[e.type]) {
|
|
603
|
-
return this.listeners[e.type].every(function(callback) {
|
|
604
|
+
return this.listeners[e.type].every(function (callback) {
|
|
604
605
|
callback(e);
|
|
605
606
|
return !e.defaultPrevented;
|
|
606
607
|
});
|
|
@@ -609,26 +610,26 @@ var SSE = function (url, options) {
|
|
|
609
610
|
return true;
|
|
610
611
|
};
|
|
611
612
|
|
|
612
|
-
this._setReadyState = function(state) {
|
|
613
|
+
this._setReadyState = function (state) {
|
|
613
614
|
var event = new CustomEvent('readystatechange');
|
|
614
615
|
event.readyState = state;
|
|
615
616
|
this.readyState = state;
|
|
616
617
|
this.dispatchEvent(event);
|
|
617
618
|
};
|
|
618
619
|
|
|
619
|
-
this._onStreamFailure = function(e) {
|
|
620
|
+
this._onStreamFailure = function (e) {
|
|
620
621
|
var event = new CustomEvent('error');
|
|
621
622
|
event.data = e.currentTarget.response;
|
|
622
623
|
this.dispatchEvent(event);
|
|
623
624
|
this.close();
|
|
624
625
|
};
|
|
625
626
|
|
|
626
|
-
this._onStreamAbort = function(e) {
|
|
627
|
+
this._onStreamAbort = function (e) {
|
|
627
628
|
this.dispatchEvent(new CustomEvent('abort'));
|
|
628
629
|
this.close();
|
|
629
630
|
};
|
|
630
631
|
|
|
631
|
-
this._onStreamProgress = function(e) {
|
|
632
|
+
this._onStreamProgress = function (e) {
|
|
632
633
|
if (!this.xhr) {
|
|
633
634
|
return;
|
|
634
635
|
}
|
|
@@ -645,17 +646,19 @@ var SSE = function (url, options) {
|
|
|
645
646
|
|
|
646
647
|
var data = this.xhr.responseText.substring(this.progress);
|
|
647
648
|
this.progress += data.length;
|
|
648
|
-
data.split(/(\r\n|\r|\n){2}/g).forEach(
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
649
|
+
data.split(/(\r\n|\r|\n){2}/g).forEach(
|
|
650
|
+
function (part) {
|
|
651
|
+
if (part.trim().length === 0) {
|
|
652
|
+
this.dispatchEvent(this._parseEventChunk(this.chunk.trim()));
|
|
653
|
+
this.chunk = '';
|
|
654
|
+
} else {
|
|
655
|
+
this.chunk += part;
|
|
656
|
+
}
|
|
657
|
+
}.bind(this),
|
|
658
|
+
);
|
|
656
659
|
};
|
|
657
660
|
|
|
658
|
-
this._onStreamLoaded = function(e) {
|
|
661
|
+
this._onStreamLoaded = function (e) {
|
|
659
662
|
this._onStreamProgress(e);
|
|
660
663
|
|
|
661
664
|
// Parse the last chunk.
|
|
@@ -666,33 +669,35 @@ var SSE = function (url, options) {
|
|
|
666
669
|
/**
|
|
667
670
|
* Parse a received SSE event chunk into a constructed event object.
|
|
668
671
|
*/
|
|
669
|
-
this._parseEventChunk = function(chunk) {
|
|
672
|
+
this._parseEventChunk = function (chunk) {
|
|
670
673
|
if (!chunk || chunk.length === 0) {
|
|
671
674
|
return null;
|
|
672
675
|
}
|
|
673
676
|
|
|
674
|
-
var e = {
|
|
675
|
-
chunk.split(/\n|\r\n|\r/).forEach(
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
677
|
+
var e = { id: null, retry: null, data: '', event: 'message' };
|
|
678
|
+
chunk.split(/\n|\r\n|\r/).forEach(
|
|
679
|
+
function (line) {
|
|
680
|
+
line = line.trimRight();
|
|
681
|
+
var index = line.indexOf(this.FIELD_SEPARATOR);
|
|
682
|
+
if (index <= 0) {
|
|
683
|
+
// Line was either empty, or started with a separator and is a comment.
|
|
684
|
+
// Either way, ignore.
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
683
687
|
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
+
var field = line.substring(0, index);
|
|
689
|
+
if (!(field in e)) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
688
692
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
693
|
+
var value = line.substring(index + 1).trimLeft();
|
|
694
|
+
if (field === 'data') {
|
|
695
|
+
e[field] += value;
|
|
696
|
+
} else {
|
|
697
|
+
e[field] = value;
|
|
698
|
+
}
|
|
699
|
+
}.bind(this),
|
|
700
|
+
);
|
|
696
701
|
|
|
697
702
|
var event = new CustomEvent(e.event);
|
|
698
703
|
event.data = e.data;
|
|
@@ -700,7 +705,7 @@ var SSE = function (url, options) {
|
|
|
700
705
|
return event;
|
|
701
706
|
};
|
|
702
707
|
|
|
703
|
-
this._checkStreamClosed = function() {
|
|
708
|
+
this._checkStreamClosed = function () {
|
|
704
709
|
if (!this.xhr) {
|
|
705
710
|
return;
|
|
706
711
|
}
|
|
@@ -710,7 +715,7 @@ var SSE = function (url, options) {
|
|
|
710
715
|
}
|
|
711
716
|
};
|
|
712
717
|
|
|
713
|
-
this.stream = function() {
|
|
718
|
+
this.stream = function () {
|
|
714
719
|
this._setReadyState(this.CONNECTING);
|
|
715
720
|
|
|
716
721
|
this.xhr = new XMLHttpRequest();
|
|
@@ -727,7 +732,7 @@ var SSE = function (url, options) {
|
|
|
727
732
|
this.xhr.send(this.payload);
|
|
728
733
|
};
|
|
729
734
|
|
|
730
|
-
this.close = function() {
|
|
735
|
+
this.close = function () {
|
|
731
736
|
if (this.readyState === this.CLOSED) {
|
|
732
737
|
return;
|
|
733
738
|
}
|
package/dist/index.js
CHANGED
|
@@ -3,75 +3,75 @@
|
|
|
3
3
|
var axios = require('axios');
|
|
4
4
|
var reactQuery = require('@tanstack/react-query');
|
|
5
5
|
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
|
|
9
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
-
purpose with or without fee is hereby granted.
|
|
11
|
-
|
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var __assign = function() {
|
|
24
|
-
__assign = Object.assign || function __assign(t) {
|
|
25
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
26
|
-
s = arguments[i];
|
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
28
|
-
}
|
|
29
|
-
return t;
|
|
30
|
-
};
|
|
31
|
-
return __assign.apply(this, arguments);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
35
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
36
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
38
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
39
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
40
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function __generator(thisArg, body) {
|
|
45
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
46
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
47
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
48
|
-
function step(op) {
|
|
49
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
50
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
51
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
52
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
53
|
-
switch (op[0]) {
|
|
54
|
-
case 0: case 1: t = op; break;
|
|
55
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
56
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
57
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
58
|
-
default:
|
|
59
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
60
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
61
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
62
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
63
|
-
if (t[2]) _.ops.pop();
|
|
64
|
-
_.trys.pop(); continue;
|
|
65
|
-
}
|
|
66
|
-
op = body.call(thisArg, _);
|
|
67
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
68
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
73
|
-
var e = new Error(message);
|
|
74
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var __assign = function() {
|
|
24
|
+
__assign = Object.assign || function __assign(t) {
|
|
25
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
26
|
+
s = arguments[i];
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
28
|
+
}
|
|
29
|
+
return t;
|
|
30
|
+
};
|
|
31
|
+
return __assign.apply(this, arguments);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
35
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
36
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
38
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
39
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
40
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function __generator(thisArg, body) {
|
|
45
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
46
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
47
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
48
|
+
function step(op) {
|
|
49
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
50
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
51
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
52
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
53
|
+
switch (op[0]) {
|
|
54
|
+
case 0: case 1: t = op; break;
|
|
55
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
56
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
57
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
58
|
+
default:
|
|
59
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
60
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
61
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
62
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
63
|
+
if (t[2]) _.ops.pop();
|
|
64
|
+
_.trys.pop(); continue;
|
|
65
|
+
}
|
|
66
|
+
op = body.call(thisArg, _);
|
|
67
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
68
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
73
|
+
var e = new Error(message);
|
|
74
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
function _get(url, options) {
|
|
@@ -527,6 +527,7 @@ function setTokenHeader(token) {
|
|
|
527
527
|
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
|
|
528
528
|
}
|
|
529
529
|
|
|
530
|
+
/* eslint-disable */
|
|
530
531
|
/**
|
|
531
532
|
* Copyright (C) 2016 Maxime Petazzoni <maxime.petazzoni@bulix.org>.
|
|
532
533
|
* All rights reserved.
|
|
@@ -547,7 +548,7 @@ var SSE = function (url, options) {
|
|
|
547
548
|
options = options || {};
|
|
548
549
|
this.headers = options.headers || {};
|
|
549
550
|
this.payload = options.payload !== undefined ? options.payload : '';
|
|
550
|
-
this.method = options.method || (this.payload && 'POST' || 'GET'
|
|
551
|
+
this.method = options.method || (this.payload && 'POST') || 'GET';
|
|
551
552
|
this.withCredentials = !!options.withCredentials;
|
|
552
553
|
|
|
553
554
|
this.FIELD_SEPARATOR = ':';
|
|
@@ -558,7 +559,7 @@ var SSE = function (url, options) {
|
|
|
558
559
|
this.progress = 0;
|
|
559
560
|
this.chunk = '';
|
|
560
561
|
|
|
561
|
-
this.addEventListener = function(type, listener) {
|
|
562
|
+
this.addEventListener = function (type, listener) {
|
|
562
563
|
if (this.listeners[type] === undefined) {
|
|
563
564
|
this.listeners[type] = [];
|
|
564
565
|
}
|
|
@@ -568,13 +569,13 @@ var SSE = function (url, options) {
|
|
|
568
569
|
}
|
|
569
570
|
};
|
|
570
571
|
|
|
571
|
-
this.removeEventListener = function(type, listener) {
|
|
572
|
+
this.removeEventListener = function (type, listener) {
|
|
572
573
|
if (this.listeners[type] === undefined) {
|
|
573
574
|
return;
|
|
574
575
|
}
|
|
575
576
|
|
|
576
577
|
var filtered = [];
|
|
577
|
-
this.listeners[type].forEach(function(element) {
|
|
578
|
+
this.listeners[type].forEach(function (element) {
|
|
578
579
|
if (element !== listener) {
|
|
579
580
|
filtered.push(element);
|
|
580
581
|
}
|
|
@@ -586,7 +587,7 @@ var SSE = function (url, options) {
|
|
|
586
587
|
}
|
|
587
588
|
};
|
|
588
589
|
|
|
589
|
-
this.dispatchEvent = function(e) {
|
|
590
|
+
this.dispatchEvent = function (e) {
|
|
590
591
|
if (!e) {
|
|
591
592
|
return true;
|
|
592
593
|
}
|
|
@@ -602,7 +603,7 @@ var SSE = function (url, options) {
|
|
|
602
603
|
}
|
|
603
604
|
|
|
604
605
|
if (this.listeners[e.type]) {
|
|
605
|
-
return this.listeners[e.type].every(function(callback) {
|
|
606
|
+
return this.listeners[e.type].every(function (callback) {
|
|
606
607
|
callback(e);
|
|
607
608
|
return !e.defaultPrevented;
|
|
608
609
|
});
|
|
@@ -611,26 +612,26 @@ var SSE = function (url, options) {
|
|
|
611
612
|
return true;
|
|
612
613
|
};
|
|
613
614
|
|
|
614
|
-
this._setReadyState = function(state) {
|
|
615
|
+
this._setReadyState = function (state) {
|
|
615
616
|
var event = new CustomEvent('readystatechange');
|
|
616
617
|
event.readyState = state;
|
|
617
618
|
this.readyState = state;
|
|
618
619
|
this.dispatchEvent(event);
|
|
619
620
|
};
|
|
620
621
|
|
|
621
|
-
this._onStreamFailure = function(e) {
|
|
622
|
+
this._onStreamFailure = function (e) {
|
|
622
623
|
var event = new CustomEvent('error');
|
|
623
624
|
event.data = e.currentTarget.response;
|
|
624
625
|
this.dispatchEvent(event);
|
|
625
626
|
this.close();
|
|
626
627
|
};
|
|
627
628
|
|
|
628
|
-
this._onStreamAbort = function(e) {
|
|
629
|
+
this._onStreamAbort = function (e) {
|
|
629
630
|
this.dispatchEvent(new CustomEvent('abort'));
|
|
630
631
|
this.close();
|
|
631
632
|
};
|
|
632
633
|
|
|
633
|
-
this._onStreamProgress = function(e) {
|
|
634
|
+
this._onStreamProgress = function (e) {
|
|
634
635
|
if (!this.xhr) {
|
|
635
636
|
return;
|
|
636
637
|
}
|
|
@@ -647,17 +648,19 @@ var SSE = function (url, options) {
|
|
|
647
648
|
|
|
648
649
|
var data = this.xhr.responseText.substring(this.progress);
|
|
649
650
|
this.progress += data.length;
|
|
650
|
-
data.split(/(\r\n|\r|\n){2}/g).forEach(
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
651
|
+
data.split(/(\r\n|\r|\n){2}/g).forEach(
|
|
652
|
+
function (part) {
|
|
653
|
+
if (part.trim().length === 0) {
|
|
654
|
+
this.dispatchEvent(this._parseEventChunk(this.chunk.trim()));
|
|
655
|
+
this.chunk = '';
|
|
656
|
+
} else {
|
|
657
|
+
this.chunk += part;
|
|
658
|
+
}
|
|
659
|
+
}.bind(this),
|
|
660
|
+
);
|
|
658
661
|
};
|
|
659
662
|
|
|
660
|
-
this._onStreamLoaded = function(e) {
|
|
663
|
+
this._onStreamLoaded = function (e) {
|
|
661
664
|
this._onStreamProgress(e);
|
|
662
665
|
|
|
663
666
|
// Parse the last chunk.
|
|
@@ -668,33 +671,35 @@ var SSE = function (url, options) {
|
|
|
668
671
|
/**
|
|
669
672
|
* Parse a received SSE event chunk into a constructed event object.
|
|
670
673
|
*/
|
|
671
|
-
this._parseEventChunk = function(chunk) {
|
|
674
|
+
this._parseEventChunk = function (chunk) {
|
|
672
675
|
if (!chunk || chunk.length === 0) {
|
|
673
676
|
return null;
|
|
674
677
|
}
|
|
675
678
|
|
|
676
|
-
var e = {
|
|
677
|
-
chunk.split(/\n|\r\n|\r/).forEach(
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
679
|
+
var e = { id: null, retry: null, data: '', event: 'message' };
|
|
680
|
+
chunk.split(/\n|\r\n|\r/).forEach(
|
|
681
|
+
function (line) {
|
|
682
|
+
line = line.trimRight();
|
|
683
|
+
var index = line.indexOf(this.FIELD_SEPARATOR);
|
|
684
|
+
if (index <= 0) {
|
|
685
|
+
// Line was either empty, or started with a separator and is a comment.
|
|
686
|
+
// Either way, ignore.
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
685
689
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
+
var field = line.substring(0, index);
|
|
691
|
+
if (!(field in e)) {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
690
694
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
695
|
+
var value = line.substring(index + 1).trimLeft();
|
|
696
|
+
if (field === 'data') {
|
|
697
|
+
e[field] += value;
|
|
698
|
+
} else {
|
|
699
|
+
e[field] = value;
|
|
700
|
+
}
|
|
701
|
+
}.bind(this),
|
|
702
|
+
);
|
|
698
703
|
|
|
699
704
|
var event = new CustomEvent(e.event);
|
|
700
705
|
event.data = e.data;
|
|
@@ -702,7 +707,7 @@ var SSE = function (url, options) {
|
|
|
702
707
|
return event;
|
|
703
708
|
};
|
|
704
709
|
|
|
705
|
-
this._checkStreamClosed = function() {
|
|
710
|
+
this._checkStreamClosed = function () {
|
|
706
711
|
if (!this.xhr) {
|
|
707
712
|
return;
|
|
708
713
|
}
|
|
@@ -712,7 +717,7 @@ var SSE = function (url, options) {
|
|
|
712
717
|
}
|
|
713
718
|
};
|
|
714
719
|
|
|
715
|
-
this.stream = function() {
|
|
720
|
+
this.stream = function () {
|
|
716
721
|
this._setReadyState(this.CONNECTING);
|
|
717
722
|
|
|
718
723
|
this.xhr = new XMLHttpRequest();
|
|
@@ -729,7 +734,7 @@ var SSE = function (url, options) {
|
|
|
729
734
|
this.xhr.send(this.payload);
|
|
730
735
|
};
|
|
731
736
|
|
|
732
|
-
this.close = function() {
|
|
737
|
+
this.close = function () {
|
|
733
738
|
if (this.readyState === this.CLOSED) {
|
|
734
739
|
return;
|
|
735
740
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "librechat-data-provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "data services for librechat apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
7
|
-
"types": "types/",
|
|
7
|
+
"types": "types/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"clean": "rimraf dist",
|
|
10
10
|
"build": "npm run clean && rollup -c --silent --bundleConfigAsCjs",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"registry": "https://registry.npmjs.org/"
|
|
48
|
-
}
|
|
48
|
+
}
|
|
49
49
|
}
|
package/src/index.ts
CHANGED
package/src/{sse.mjs → sse.js}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (C) 2016 Maxime Petazzoni <maxime.petazzoni@bulix.org>.
|
|
3
4
|
* All rights reserved.
|
|
@@ -18,7 +19,7 @@ var SSE = function (url, options) {
|
|
|
18
19
|
options = options || {};
|
|
19
20
|
this.headers = options.headers || {};
|
|
20
21
|
this.payload = options.payload !== undefined ? options.payload : '';
|
|
21
|
-
this.method = options.method || (this.payload && 'POST' || 'GET'
|
|
22
|
+
this.method = options.method || (this.payload && 'POST') || 'GET';
|
|
22
23
|
this.withCredentials = !!options.withCredentials;
|
|
23
24
|
|
|
24
25
|
this.FIELD_SEPARATOR = ':';
|
|
@@ -29,7 +30,7 @@ var SSE = function (url, options) {
|
|
|
29
30
|
this.progress = 0;
|
|
30
31
|
this.chunk = '';
|
|
31
32
|
|
|
32
|
-
this.addEventListener = function(type, listener) {
|
|
33
|
+
this.addEventListener = function (type, listener) {
|
|
33
34
|
if (this.listeners[type] === undefined) {
|
|
34
35
|
this.listeners[type] = [];
|
|
35
36
|
}
|
|
@@ -39,13 +40,13 @@ var SSE = function (url, options) {
|
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
this.removeEventListener = function(type, listener) {
|
|
43
|
+
this.removeEventListener = function (type, listener) {
|
|
43
44
|
if (this.listeners[type] === undefined) {
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
var filtered = [];
|
|
48
|
-
this.listeners[type].forEach(function(element) {
|
|
49
|
+
this.listeners[type].forEach(function (element) {
|
|
49
50
|
if (element !== listener) {
|
|
50
51
|
filtered.push(element);
|
|
51
52
|
}
|
|
@@ -57,7 +58,7 @@ var SSE = function (url, options) {
|
|
|
57
58
|
}
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
this.dispatchEvent = function(e) {
|
|
61
|
+
this.dispatchEvent = function (e) {
|
|
61
62
|
if (!e) {
|
|
62
63
|
return true;
|
|
63
64
|
}
|
|
@@ -73,7 +74,7 @@ var SSE = function (url, options) {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
if (this.listeners[e.type]) {
|
|
76
|
-
return this.listeners[e.type].every(function(callback) {
|
|
77
|
+
return this.listeners[e.type].every(function (callback) {
|
|
77
78
|
callback(e);
|
|
78
79
|
return !e.defaultPrevented;
|
|
79
80
|
});
|
|
@@ -82,26 +83,26 @@ var SSE = function (url, options) {
|
|
|
82
83
|
return true;
|
|
83
84
|
};
|
|
84
85
|
|
|
85
|
-
this._setReadyState = function(state) {
|
|
86
|
+
this._setReadyState = function (state) {
|
|
86
87
|
var event = new CustomEvent('readystatechange');
|
|
87
88
|
event.readyState = state;
|
|
88
89
|
this.readyState = state;
|
|
89
90
|
this.dispatchEvent(event);
|
|
90
91
|
};
|
|
91
92
|
|
|
92
|
-
this._onStreamFailure = function(e) {
|
|
93
|
+
this._onStreamFailure = function (e) {
|
|
93
94
|
var event = new CustomEvent('error');
|
|
94
95
|
event.data = e.currentTarget.response;
|
|
95
96
|
this.dispatchEvent(event);
|
|
96
97
|
this.close();
|
|
97
|
-
}
|
|
98
|
+
};
|
|
98
99
|
|
|
99
|
-
this._onStreamAbort = function(e) {
|
|
100
|
+
this._onStreamAbort = function (e) {
|
|
100
101
|
this.dispatchEvent(new CustomEvent('abort'));
|
|
101
102
|
this.close();
|
|
102
|
-
}
|
|
103
|
+
};
|
|
103
104
|
|
|
104
|
-
this._onStreamProgress = function(e) {
|
|
105
|
+
this._onStreamProgress = function (e) {
|
|
105
106
|
if (!this.xhr) {
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
@@ -118,17 +119,19 @@ var SSE = function (url, options) {
|
|
|
118
119
|
|
|
119
120
|
var data = this.xhr.responseText.substring(this.progress);
|
|
120
121
|
this.progress += data.length;
|
|
121
|
-
data.split(/(\r\n|\r|\n){2}/g).forEach(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
data.split(/(\r\n|\r|\n){2}/g).forEach(
|
|
123
|
+
function (part) {
|
|
124
|
+
if (part.trim().length === 0) {
|
|
125
|
+
this.dispatchEvent(this._parseEventChunk(this.chunk.trim()));
|
|
126
|
+
this.chunk = '';
|
|
127
|
+
} else {
|
|
128
|
+
this.chunk += part;
|
|
129
|
+
}
|
|
130
|
+
}.bind(this),
|
|
131
|
+
);
|
|
129
132
|
};
|
|
130
133
|
|
|
131
|
-
this._onStreamLoaded = function(e) {
|
|
134
|
+
this._onStreamLoaded = function (e) {
|
|
132
135
|
this._onStreamProgress(e);
|
|
133
136
|
|
|
134
137
|
// Parse the last chunk.
|
|
@@ -139,33 +142,35 @@ var SSE = function (url, options) {
|
|
|
139
142
|
/**
|
|
140
143
|
* Parse a received SSE event chunk into a constructed event object.
|
|
141
144
|
*/
|
|
142
|
-
this._parseEventChunk = function(chunk) {
|
|
145
|
+
this._parseEventChunk = function (chunk) {
|
|
143
146
|
if (!chunk || chunk.length === 0) {
|
|
144
147
|
return null;
|
|
145
148
|
}
|
|
146
149
|
|
|
147
|
-
var e = {
|
|
148
|
-
chunk.split(/\n|\r\n|\r/).forEach(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
150
|
+
var e = { id: null, retry: null, data: '', event: 'message' };
|
|
151
|
+
chunk.split(/\n|\r\n|\r/).forEach(
|
|
152
|
+
function (line) {
|
|
153
|
+
line = line.trimRight();
|
|
154
|
+
var index = line.indexOf(this.FIELD_SEPARATOR);
|
|
155
|
+
if (index <= 0) {
|
|
156
|
+
// Line was either empty, or started with a separator and is a comment.
|
|
157
|
+
// Either way, ignore.
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
var field = line.substring(0, index);
|
|
162
|
+
if (!(field in e)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
var value = line.substring(index + 1).trimLeft();
|
|
167
|
+
if (field === 'data') {
|
|
168
|
+
e[field] += value;
|
|
169
|
+
} else {
|
|
170
|
+
e[field] = value;
|
|
171
|
+
}
|
|
172
|
+
}.bind(this),
|
|
173
|
+
);
|
|
169
174
|
|
|
170
175
|
var event = new CustomEvent(e.event);
|
|
171
176
|
event.data = e.data;
|
|
@@ -173,7 +178,7 @@ var SSE = function (url, options) {
|
|
|
173
178
|
return event;
|
|
174
179
|
};
|
|
175
180
|
|
|
176
|
-
this._checkStreamClosed = function() {
|
|
181
|
+
this._checkStreamClosed = function () {
|
|
177
182
|
if (!this.xhr) {
|
|
178
183
|
return;
|
|
179
184
|
}
|
|
@@ -183,7 +188,7 @@ var SSE = function (url, options) {
|
|
|
183
188
|
}
|
|
184
189
|
};
|
|
185
190
|
|
|
186
|
-
this.stream = function() {
|
|
191
|
+
this.stream = function () {
|
|
187
192
|
this._setReadyState(this.CONNECTING);
|
|
188
193
|
|
|
189
194
|
this.xhr = new XMLHttpRequest();
|
|
@@ -200,7 +205,7 @@ var SSE = function (url, options) {
|
|
|
200
205
|
this.xhr.send(this.payload);
|
|
201
206
|
};
|
|
202
207
|
|
|
203
|
-
this.close = function() {
|
|
208
|
+
this.close = function () {
|
|
204
209
|
if (this.readyState === this.CLOSED) {
|
|
205
210
|
return;
|
|
206
211
|
}
|
package/src/types.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
-
|
|
4
|
-
name: Node.js Package
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
release:
|
|
8
|
-
types: [created]
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
build:
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v3
|
|
15
|
-
- uses: actions/setup-node@v3
|
|
16
|
-
with:
|
|
17
|
-
node-version: 16
|
|
18
|
-
- run: npm ci
|
|
19
|
-
- run: npm run build
|
|
20
|
-
|
|
21
|
-
publish-npm:
|
|
22
|
-
needs: build
|
|
23
|
-
runs-on: ubuntu-latest
|
|
24
|
-
steps:
|
|
25
|
-
- uses: actions/checkout@v3
|
|
26
|
-
- uses: actions/setup-node@v3
|
|
27
|
-
with:
|
|
28
|
-
node-version: 16
|
|
29
|
-
registry-url: 'https://registry.npmjs.org'
|
|
30
|
-
- run: npm ci
|
|
31
|
-
- run: npm publish
|
|
32
|
-
env:
|
|
33
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|