ws-process 0.3.28 → 0.3.30
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/index.js +47 -30
- package/package.json +3 -5
package/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// ws-process.js
|
|
2
|
-
import { tryit } from 'ui5-lib-rc';
|
|
3
|
-
import randomize from 'randomatic';
|
|
4
2
|
import axios from 'axios';
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import {
|
|
4
|
+
defined, clone, makeid, tryit,
|
|
5
|
+
} from '@bsgp/lib-core';
|
|
7
6
|
import { ref, Loading, getRef } from './Loading-esm';
|
|
8
7
|
import {
|
|
9
8
|
storeSplittedData,
|
|
@@ -24,7 +23,24 @@ import reducer, { initialState } from './reducer';
|
|
|
24
23
|
import 'url-search-params-polyfill';
|
|
25
24
|
import { cutStringByLength, createSplitPayload } from './lib/split-payload';
|
|
26
25
|
|
|
27
|
-
const local = {
|
|
26
|
+
const local = {
|
|
27
|
+
processes: {},
|
|
28
|
+
wsProcess: initialState,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
local.dispatch = (action) => {
|
|
32
|
+
local.wsProcess = reducer(local.wsProcess, action);
|
|
33
|
+
if (getRef().current) {
|
|
34
|
+
switch (action.type) {
|
|
35
|
+
case storeSplittedData().type:
|
|
36
|
+
case clearDataSplitted().type:
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
getRef().current.setState({ wsProcess: local.wsProcess });
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
28
44
|
|
|
29
45
|
function getType(obj) {
|
|
30
46
|
return Object.prototype.toString.call(obj);
|
|
@@ -34,7 +50,7 @@ function isObject(obj) {
|
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
function getRandomID() {
|
|
37
|
-
return
|
|
53
|
+
return makeid(5);
|
|
38
54
|
}
|
|
39
55
|
|
|
40
56
|
function getUSP(url) {
|
|
@@ -101,7 +117,7 @@ function startBatchProcess(processID) {
|
|
|
101
117
|
return (dispatch, getState) => new Promise((resolve, reject) => {
|
|
102
118
|
dispatch(getWebSocket())
|
|
103
119
|
.then(() => {
|
|
104
|
-
const jsonMSG =
|
|
120
|
+
const jsonMSG = clone(local.wsProcess.processes[processID]);
|
|
105
121
|
jsonMSG.action = 'batchprocess';
|
|
106
122
|
|
|
107
123
|
const user = getState().user.currentUser;
|
|
@@ -359,7 +375,12 @@ function handleResponseHandler(res, getState, isLast = true, isFirst = true) {
|
|
|
359
375
|
res.processID,
|
|
360
376
|
);
|
|
361
377
|
const { resHandler, callback, requestTime } = cProcessItem;
|
|
362
|
-
|
|
378
|
+
|
|
379
|
+
if (process.env.NODE_ENV === 'test') {
|
|
380
|
+
// pass
|
|
381
|
+
} else {
|
|
382
|
+
console.log('%cdistance:', 'color:orange', new Date() - new Date(requestTime), res.processID, prc.count, tryit(() => res.headers['x-log-id']));
|
|
383
|
+
}
|
|
363
384
|
|
|
364
385
|
const result = resHandler
|
|
365
386
|
? local.store.dispatch(
|
|
@@ -483,11 +504,11 @@ function asyncSend(msg) {
|
|
|
483
504
|
|
|
484
505
|
const currentState = getState();
|
|
485
506
|
const {
|
|
486
|
-
AltDomain: altDomain
|
|
487
|
-
} = tryit(() => currentState[
|
|
488
|
-
if(altDomain){
|
|
507
|
+
AltDomain: altDomain,
|
|
508
|
+
} = tryit(() => currentState['api-Configuration'].merged.ui.result) || {};
|
|
509
|
+
if (altDomain) {
|
|
489
510
|
url = [altDomain, msg.url.replace(/^\/{0,}/, '')].join('/');
|
|
490
|
-
}else{
|
|
511
|
+
} else {
|
|
491
512
|
url = ['https://api.bsg.support', msg.url.replace(/^\/{0,}/, '')].join('/');
|
|
492
513
|
}
|
|
493
514
|
}
|
|
@@ -517,7 +538,12 @@ function asyncSend(msg) {
|
|
|
517
538
|
},
|
|
518
539
|
validateStatus: () => true,
|
|
519
540
|
});
|
|
520
|
-
|
|
541
|
+
|
|
542
|
+
if (process.env.NODE_ENV === 'test') {
|
|
543
|
+
// pass
|
|
544
|
+
} else {
|
|
545
|
+
console.log('%csending message:', 'color:green', httpMSG, msg);
|
|
546
|
+
}
|
|
521
547
|
|
|
522
548
|
return axios(httpMSG).catch((ex) => {
|
|
523
549
|
console.log('%conmessage(converted):', 'color:red', ex);
|
|
@@ -543,7 +569,11 @@ function asyncSend(msg) {
|
|
|
543
569
|
}
|
|
544
570
|
return data;
|
|
545
571
|
}).then((data) => {
|
|
546
|
-
|
|
572
|
+
if (process.env.NODE_ENV === 'test') {
|
|
573
|
+
// pass
|
|
574
|
+
} else {
|
|
575
|
+
console.log('%cHTTP.res:', 'color:red', data);
|
|
576
|
+
}
|
|
547
577
|
const processID = tryit(() => data.headers['process-id']) || tryit(() => data.config.headers['bsg-support-process-id']);
|
|
548
578
|
|
|
549
579
|
const newData = {
|
|
@@ -939,7 +969,7 @@ function runProcess(processID, data) {
|
|
|
939
969
|
// const args = leakArguments(arguments, 1);
|
|
940
970
|
|
|
941
971
|
return (dispatch, getState) => {
|
|
942
|
-
console.
|
|
972
|
+
console.debug('run process ', processID);
|
|
943
973
|
return new Promise((resolve, reject) => {
|
|
944
974
|
const { processes } = local.wsProcess;
|
|
945
975
|
|
|
@@ -955,7 +985,7 @@ function runProcess(processID, data) {
|
|
|
955
985
|
if (prc.count === prc.items.length) {
|
|
956
986
|
// process finished
|
|
957
987
|
|
|
958
|
-
console.
|
|
988
|
+
console.debug('process finished ', processID);
|
|
959
989
|
|
|
960
990
|
// const unfinishedProcesses = Object.keys(processes).filter(subKey => {
|
|
961
991
|
// if (processes[subKey].count < processes[subKey].items.length) {
|
|
@@ -1247,20 +1277,7 @@ function init({
|
|
|
1247
1277
|
local.store = store;
|
|
1248
1278
|
local.stage = stage;
|
|
1249
1279
|
local.wsURL = wsURL;
|
|
1250
|
-
|
|
1251
|
-
local.dispatch = (action) => {
|
|
1252
|
-
local.wsProcess = reducer(local.wsProcess, action);
|
|
1253
|
-
if (getRef().current) {
|
|
1254
|
-
switch (action.type) {
|
|
1255
|
-
case storeSplittedData().type:
|
|
1256
|
-
case clearDataSplitted().type:
|
|
1257
|
-
break;
|
|
1258
|
-
default:
|
|
1259
|
-
getRef().current.setState({ wsProcess: local.wsProcess });
|
|
1260
|
-
break;
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1280
|
+
|
|
1264
1281
|
local.beforeEachProcess = beforeEachProcess || (() => {});
|
|
1265
1282
|
local.afterEachProcess = afterEachProcess || (() => {});
|
|
1266
1283
|
local.beforeAllProcesses = beforeAllProcesses || (() => {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ws-process",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.30",
|
|
4
4
|
"description": "Process Management for Web Socket Client",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,12 +23,10 @@
|
|
|
23
23
|
"url": "https://github.com/bsgp/ws-process/issues"
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/bsgp/ws-process#readme",
|
|
26
|
-
"
|
|
27
|
-
"@bsgp/lib-core": "
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@bsgp/lib-core": "0.2.510",
|
|
28
28
|
"axios": "0.21.1",
|
|
29
29
|
"immer": "3.1.3",
|
|
30
|
-
"lodash": "4.17.19",
|
|
31
|
-
"randomatic": "3.1.1",
|
|
32
30
|
"react": "16.8.6",
|
|
33
31
|
"react-dom": "16.8.6",
|
|
34
32
|
"ui5-lib-rc": "0.8.3",
|