@bbn/bbn 1.0.331 → 1.0.333
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/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/fn/ajax/stream.d.ts +0 -14
- package/dist/fn/ajax/stream.js +25 -10
- package/package.json +1 -1
package/dist/fn/ajax/stream.d.ts
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @method stream
|
|
3
|
-
* @global
|
|
4
|
-
* @memberof bbn.fn
|
|
5
|
-
*
|
|
6
|
-
* @param {String} url The URL to be requested by XHR
|
|
7
|
-
* @param {Function} success The function to execute if the request goes well (200)
|
|
8
|
-
* @param {Object} data The data to send through POST
|
|
9
|
-
* @param {Function} failure The function to execute if the request goes bad
|
|
10
|
-
* @param {Function} abort The function to execute if the request is aborted
|
|
11
|
-
* @param {Function} done The function to execute if the request is finished
|
|
12
|
-
*
|
|
13
|
-
* @returns {Promise} The Promise created by the generated XHR.
|
|
14
|
-
*/
|
|
15
1
|
export default function stream(url: any, success: any, data: any, failure: any, abort: any, finished: any): any;
|
package/dist/fn/ajax/stream.js
CHANGED
|
@@ -22,6 +22,7 @@ import arrayBuffer2String from '../convert/arrayBuffer2String.js';
|
|
|
22
22
|
*
|
|
23
23
|
* @returns {Promise} The Promise created by the generated XHR.
|
|
24
24
|
*/
|
|
25
|
+
var boundary = '<!---------------B-B-N--------------->';
|
|
25
26
|
export default function stream(url, success, data, failure, abort, finished) {
|
|
26
27
|
var requestId = getRequestId(url, data, 'json');
|
|
27
28
|
var loaderObj = getLoader(requestId);
|
|
@@ -37,6 +38,24 @@ export default function stream(url, success, data, failure, abort, finished) {
|
|
|
37
38
|
}
|
|
38
39
|
var aborter = new AbortController();
|
|
39
40
|
var json = '';
|
|
41
|
+
var treatJSON = function (json) {
|
|
42
|
+
if (json.length) {
|
|
43
|
+
if (json.indexOf(boundary) > -1) {
|
|
44
|
+
json = bbn.fn.removeEmpty(json.split(boundary));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
json = [json];
|
|
48
|
+
}
|
|
49
|
+
for (var i in json) {
|
|
50
|
+
try {
|
|
51
|
+
success(JSON.parse(json[i]));
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
40
59
|
var chrono = bbn.fn.startChrono();
|
|
41
60
|
var loader = fetch(url, {
|
|
42
61
|
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
@@ -63,26 +82,19 @@ export default function stream(url, success, data, failure, abort, finished) {
|
|
|
63
82
|
// Do something with last chunk of data then exit reader
|
|
64
83
|
_deleteLoader(requestId, data);
|
|
65
84
|
if (json) {
|
|
66
|
-
|
|
67
|
-
success(JSON.parse(json));
|
|
68
|
-
json = '';
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
throw new Error('Stream ended with data: ' + json);
|
|
72
|
-
}
|
|
85
|
+
treatJSON(json);
|
|
73
86
|
}
|
|
74
87
|
if (finished) {
|
|
75
88
|
finished();
|
|
76
89
|
}
|
|
77
90
|
return;
|
|
78
91
|
}
|
|
79
|
-
bbn.fn.log(["STREAM SUCCESS IS FN: " + isFn_1]);
|
|
80
92
|
if (isFn_1) {
|
|
81
93
|
json += arrayBuffer2String(value).trim();
|
|
82
|
-
bbn.fn.log(["STREAM RESULT", json]);
|
|
94
|
+
bbn.fn.log(["STREAM RESULT", json.length, json]);
|
|
83
95
|
if (json) {
|
|
84
96
|
try {
|
|
85
|
-
|
|
97
|
+
treatJSON(json);
|
|
86
98
|
json = '';
|
|
87
99
|
}
|
|
88
100
|
catch (e) { }
|
|
@@ -91,6 +103,9 @@ export default function stream(url, success, data, failure, abort, finished) {
|
|
|
91
103
|
success();
|
|
92
104
|
}
|
|
93
105
|
}
|
|
106
|
+
else {
|
|
107
|
+
bbn.fn.log(["STREAM SUCCESS IS FN? " + isFn_1]);
|
|
108
|
+
}
|
|
94
109
|
// Read some more, and call this function again
|
|
95
110
|
return reader_1.read().then(pump);
|
|
96
111
|
});
|