@shopgate/pwa-core 7.30.0-alpha.8 → 7.30.0-beta.1
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/classes/AppCommand/index.js +17 -15
- package/classes/AppCommand/spec.js +11 -8
- package/classes/AppCommandRequest/index.js +38 -34
- package/classes/AppPermissionsRequest/AppPermissionsRequest.js +21 -15
- package/classes/AppPermissionsRequest/GetAppPermissionsRequest.js +12 -8
- package/classes/AppPermissionsRequest/RequestAppPermissionsRequest.js +12 -8
- package/classes/Bridge/index.js +7 -5
- package/classes/BrightnessRequest/index.js +7 -5
- package/classes/BrightnessRequest/spec.js +2 -2
- package/classes/BrowserConnector/index.js +98 -81
- package/classes/Conditioner/index.js +17 -14
- package/classes/DataRequest/index.js +25 -19
- package/classes/DevServerBridge/index.js +11 -10
- package/classes/DevServerBridge/spec.js +10 -11
- package/classes/ErrorManager/index.js +11 -9
- package/classes/Event/index.js +29 -24
- package/classes/HttpRequest/index.js +39 -33
- package/classes/PipelineDependencies/index.js +11 -9
- package/classes/PipelineDependencies/spec.js +2 -2
- package/classes/PipelineManager/index.js +48 -46
- package/classes/PipelineRequest/index.js +50 -44
- package/classes/PipelineRequest/mock.js +52 -39
- package/classes/PipelineRequest/spec.js +1 -1
- package/classes/PipelineSequence/index.js +11 -9
- package/classes/Request/index.js +15 -13
- package/classes/RequestBuffer/index.js +11 -9
- package/classes/RequestManager/index.js +20 -15
- package/classes/RequestManager/spec.js +40 -25
- package/classes/Scanner/index.js +218 -219
- package/classes/ScannerEvent/index.js +22 -22
- package/classes/ScannerEventHandler/index.js +35 -35
- package/classes/ScannerEventListener/index.js +77 -78
- package/classes/ScannerManager/ScanProcessingError.js +11 -5
- package/classes/ScannerManager/index.js +16 -14
- package/classes/WebStorageRequest/index.js +18 -12
- package/constants/AppEvents.js +1 -0
- package/helpers/index.js +8 -8
- package/package.json +1 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import Request from "../Request";
|
|
2
3
|
import pipelineManager from "../PipelineManager";
|
|
3
4
|
import { CURRENT_VERSION } from "../../constants/Pipeline";
|
|
@@ -17,33 +18,37 @@ export const DEFAULT_HANDLE_ERROR = errorHandleTypes.ERROR_HANDLE_DEFAULT;
|
|
|
17
18
|
* Defines a pipeline request.
|
|
18
19
|
* @class
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
let PipelineRequest = /*#__PURE__*/function (_Request) {
|
|
21
22
|
/**
|
|
22
23
|
* @param {string} name The pipeline name. Excluding the version.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
function PipelineRequest(name) {
|
|
26
|
+
var _this;
|
|
25
27
|
if (!name) throw new Error('The \'name\' parameter is not set!');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
_this = _Request.call(this) || this;
|
|
29
|
+
_this.name = name;
|
|
30
|
+
_this.version = DEFAULT_VERSION;
|
|
31
|
+
_this.input = DEFAULT_INPUT;
|
|
32
|
+
_this.trusted = false;
|
|
33
|
+
_this.retries = DEFAULT_RETRIES;
|
|
34
|
+
_this.timeout = DEFAULT_TIMEOUT;
|
|
35
|
+
_this.process = DEFAULT_PROCESSED;
|
|
36
|
+
_this.handleErrors = DEFAULT_HANDLE_ERROR;
|
|
37
|
+
_this.errorBlacklist = [];
|
|
38
|
+
_this.responseBehavior = {
|
|
37
39
|
success: null,
|
|
38
40
|
error: null
|
|
39
41
|
};
|
|
42
|
+
return _this;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
/**
|
|
43
46
|
* @param {number} version The version number of the pipeline request.
|
|
44
47
|
* @return {PipelineRequest}
|
|
45
48
|
*/
|
|
46
|
-
|
|
49
|
+
_inheritsLoose(PipelineRequest, _Request);
|
|
50
|
+
var _proto = PipelineRequest.prototype;
|
|
51
|
+
_proto.setVersion = function setVersion(version = DEFAULT_VERSION) {
|
|
47
52
|
if (typeof version !== 'number') throw new TypeError(`Expected 'number'. Received: '${typeof version}'`);
|
|
48
53
|
if (version < 0) throw new Error(`Expected positive integer. Received: '${version}'`);
|
|
49
54
|
if (version === 0) throw new Error('Has to be > 0!');
|
|
@@ -54,8 +59,8 @@ class PipelineRequest extends Request {
|
|
|
54
59
|
/**
|
|
55
60
|
* @param {Object} [input={}] The payload to send with the request.
|
|
56
61
|
* @returns {PipelineRequest}
|
|
57
|
-
|
|
58
|
-
setInput(input = DEFAULT_INPUT) {
|
|
62
|
+
*/;
|
|
63
|
+
_proto.setInput = function setInput(input = DEFAULT_INPUT) {
|
|
59
64
|
if (typeof input !== 'object' || input.constructor !== Object) {
|
|
60
65
|
throw new TypeError(`Expected 'object'. Received: '${typeof input}'`);
|
|
61
66
|
}
|
|
@@ -65,8 +70,8 @@ class PipelineRequest extends Request {
|
|
|
65
70
|
|
|
66
71
|
/**
|
|
67
72
|
* @return {PipelineRequest}
|
|
68
|
-
|
|
69
|
-
setTrusted() {
|
|
73
|
+
*/;
|
|
74
|
+
_proto.setTrusted = function setTrusted() {
|
|
70
75
|
this.trusted = true;
|
|
71
76
|
return this;
|
|
72
77
|
}
|
|
@@ -74,8 +79,8 @@ class PipelineRequest extends Request {
|
|
|
74
79
|
/**
|
|
75
80
|
* @param {number} retries The number of retries this pipeline request should perform.
|
|
76
81
|
* @return {PipelineRequest}
|
|
77
|
-
|
|
78
|
-
setRetries(retries = DEFAULT_RETRIES) {
|
|
82
|
+
*/;
|
|
83
|
+
_proto.setRetries = function setRetries(retries = DEFAULT_RETRIES) {
|
|
79
84
|
if (typeof retries !== 'number') throw new TypeError(`Expected 'number'. Received: '${typeof retries}'`);
|
|
80
85
|
if (retries < 0) throw new Error(`Expected positive integer. Received: '${retries}'`);
|
|
81
86
|
if (retries >= DEFAULT_MAX_RETRIES) throw new Error(`Max retries exceeded. Received: '${retries}'`);
|
|
@@ -86,8 +91,8 @@ class PipelineRequest extends Request {
|
|
|
86
91
|
/**
|
|
87
92
|
* @param {number} timeout The timeout (ms) that the request will wait before canceling.
|
|
88
93
|
* @return {PipelineRequest}
|
|
89
|
-
|
|
90
|
-
setTimeout(timeout = DEFAULT_TIMEOUT) {
|
|
94
|
+
*/;
|
|
95
|
+
_proto.setTimeout = function setTimeout(timeout = DEFAULT_TIMEOUT) {
|
|
91
96
|
if (typeof timeout !== 'number') throw new TypeError(`Expected 'number'. Received: '${typeof timeout}'`);
|
|
92
97
|
if (timeout < 0) throw new Error(`Expected positive integer. Received: '${timeout}'`);
|
|
93
98
|
if (timeout > DEFAULT_MAX_TIMEOUT) throw new Error(`Max timeout exceeded. Received: '${timeout}'`);
|
|
@@ -98,8 +103,8 @@ class PipelineRequest extends Request {
|
|
|
98
103
|
/**
|
|
99
104
|
* @param {string} processed The response process type.
|
|
100
105
|
* @return {PipelineRequest}
|
|
101
|
-
|
|
102
|
-
setResponseProcessed(processed = DEFAULT_PROCESSED) {
|
|
106
|
+
*/;
|
|
107
|
+
_proto.setResponseProcessed = function setResponseProcessed(processed = DEFAULT_PROCESSED) {
|
|
103
108
|
if (typeof processed !== 'string') throw new TypeError(`Expected 'string'. Received: '${typeof processed}'`);
|
|
104
109
|
if (!Object.values(processTypes).includes(processed)) {
|
|
105
110
|
throw new Error(`The value '${processed}' is not supported!`);
|
|
@@ -113,8 +118,8 @@ class PipelineRequest extends Request {
|
|
|
113
118
|
* Can be used for custom error handling outside.
|
|
114
119
|
* @param {Object} errors - Array of error codes
|
|
115
120
|
* @return {PipelineRequest}
|
|
116
|
-
|
|
117
|
-
setErrorBlacklist(errors = []) {
|
|
121
|
+
*/;
|
|
122
|
+
_proto.setErrorBlacklist = function setErrorBlacklist(errors = []) {
|
|
118
123
|
this.errorBlacklist = errors;
|
|
119
124
|
return this;
|
|
120
125
|
}
|
|
@@ -122,8 +127,8 @@ class PipelineRequest extends Request {
|
|
|
122
127
|
/**
|
|
123
128
|
* @param {string} handle The handle errors type.
|
|
124
129
|
* @return {PipelineRequest}
|
|
125
|
-
|
|
126
|
-
setHandleErrors(handle = errorHandleTypes.ERROR_HANDLE_DEFAULT) {
|
|
130
|
+
*/;
|
|
131
|
+
_proto.setHandleErrors = function setHandleErrors(handle = errorHandleTypes.ERROR_HANDLE_DEFAULT) {
|
|
127
132
|
if (typeof handle !== 'string') throw new TypeError(`Expected 'string'. Received: '${typeof handle}'`);
|
|
128
133
|
if (!Object.values(errorHandleTypes).includes(handle)) {
|
|
129
134
|
throw new Error(`The value '${handle}' is not supported!`);
|
|
@@ -138,8 +143,8 @@ class PipelineRequest extends Request {
|
|
|
138
143
|
* @param {boolean} value Value.
|
|
139
144
|
* @return {PipelineRequest}
|
|
140
145
|
* @deprecated
|
|
141
|
-
|
|
142
|
-
setSuppressErrors(value) {
|
|
146
|
+
*/;
|
|
147
|
+
_proto.setSuppressErrors = function setSuppressErrors(value) {
|
|
143
148
|
logger.warn('Deprecated: setSuppressErrors() will be removed. Use setHandleErrors() instead!');
|
|
144
149
|
const handle = value ? errorHandleTypes.ERROR_HANDLE_SUPPRESS : errorHandleTypes.ERROR_HANDLE_DEFAULT;
|
|
145
150
|
this.setHandleErrors(handle);
|
|
@@ -150,8 +155,8 @@ class PipelineRequest extends Request {
|
|
|
150
155
|
* @param {Object} errors - Array of error codes
|
|
151
156
|
* @return {PipelineRequest}
|
|
152
157
|
* @deprecated
|
|
153
|
-
|
|
154
|
-
setHandledErrors(errors) {
|
|
158
|
+
*/;
|
|
159
|
+
_proto.setHandledErrors = function setHandledErrors(errors) {
|
|
155
160
|
logger.warn('Deprecated: setHandledErrors() will be removed in favor of setErrorBlacklist()!');
|
|
156
161
|
this.setErrorBlacklist(errors);
|
|
157
162
|
return this;
|
|
@@ -161,8 +166,8 @@ class PipelineRequest extends Request {
|
|
|
161
166
|
* Allows to register callbacks to be executed in case of pipeline response error or success.
|
|
162
167
|
* @param {Object} behaviors The desired behaviors
|
|
163
168
|
* @return {PipelineRequest}
|
|
164
|
-
|
|
165
|
-
setResponseBehavior(behaviors = {}) {
|
|
169
|
+
*/;
|
|
170
|
+
_proto.setResponseBehavior = function setResponseBehavior(behaviors = {}) {
|
|
166
171
|
this.responseBehavior = {
|
|
167
172
|
...this.responseBehavior,
|
|
168
173
|
...behaviors
|
|
@@ -172,32 +177,33 @@ class PipelineRequest extends Request {
|
|
|
172
177
|
|
|
173
178
|
/**
|
|
174
179
|
* @returns {Function|null}
|
|
175
|
-
|
|
176
|
-
getSuccessResponseBehavior() {
|
|
180
|
+
*/;
|
|
181
|
+
_proto.getSuccessResponseBehavior = function getSuccessResponseBehavior() {
|
|
177
182
|
return this.responseBehavior?.success || null;
|
|
178
183
|
}
|
|
179
184
|
|
|
180
185
|
/**
|
|
181
186
|
* @returns {Function|null}
|
|
182
|
-
|
|
183
|
-
getErrorResponseBehavior() {
|
|
187
|
+
*/;
|
|
188
|
+
_proto.getErrorResponseBehavior = function getErrorResponseBehavior() {
|
|
184
189
|
return this.responseBehavior?.error || null;
|
|
185
190
|
}
|
|
186
191
|
|
|
187
192
|
/**
|
|
188
193
|
* Checks if the request has currently running dependencies.
|
|
189
194
|
* @return {boolean}
|
|
190
|
-
|
|
191
|
-
hasRunningDependencies() {
|
|
195
|
+
*/;
|
|
196
|
+
_proto.hasRunningDependencies = function hasRunningDependencies() {
|
|
192
197
|
return pipelineManager.hasRunningDependencies(this.name);
|
|
193
198
|
}
|
|
194
199
|
|
|
195
200
|
/**
|
|
196
201
|
* Dispatches the pipeline.
|
|
197
202
|
* @return {Promise}
|
|
198
|
-
|
|
199
|
-
dispatch() {
|
|
203
|
+
*/;
|
|
204
|
+
_proto.dispatch = function dispatch() {
|
|
200
205
|
return pipelineManager.add(this);
|
|
201
|
-
}
|
|
202
|
-
|
|
206
|
+
};
|
|
207
|
+
return PipelineRequest;
|
|
208
|
+
}(Request);
|
|
203
209
|
export default PipelineRequest;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
1
3
|
import { logger } from "../../helpers";
|
|
2
4
|
import * as errorHandleTypes from "../../constants/ErrorHandleTypes";
|
|
3
5
|
import * as processTypes from "../../constants/ProcessTypes";
|
|
@@ -8,21 +10,12 @@ import * as processTypes from "../../constants/ProcessTypes";
|
|
|
8
10
|
*
|
|
9
11
|
* For more information and usage examples, please check the README.
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Getter for mockedDispatchResolver which is an additional helper function for custom, mock-only
|
|
14
|
-
* `dispatch()` resolver.
|
|
15
|
-
* @return {Function}
|
|
16
|
-
*/
|
|
17
|
-
static get mockedDispatchResolver() {
|
|
18
|
-
return () => {};
|
|
19
|
-
}
|
|
20
|
-
|
|
13
|
+
let MockedPipelineRequest = /*#__PURE__*/function () {
|
|
21
14
|
/**
|
|
22
15
|
* Initializes the MockedPipelineRequest object.
|
|
23
16
|
* @param {string} name The pipeline name.
|
|
24
17
|
*/
|
|
25
|
-
|
|
18
|
+
function MockedPipelineRequest(name) {
|
|
26
19
|
this.name = name;
|
|
27
20
|
this.input = {};
|
|
28
21
|
this.handleErrors = errorHandleTypes.ERROR_HANDLE_DEFAULT;
|
|
@@ -36,7 +29,8 @@ class MockedPipelineRequest {
|
|
|
36
29
|
* @param {Object} [mockedInput={}] The payload to send with the request.
|
|
37
30
|
* @returns {MockedPipelineRequest}
|
|
38
31
|
*/
|
|
39
|
-
|
|
32
|
+
var _proto = MockedPipelineRequest.prototype;
|
|
33
|
+
_proto.setInput = function setInput(mockedInput = {}) {
|
|
40
34
|
this.input = mockedInput;
|
|
41
35
|
return this;
|
|
42
36
|
}
|
|
@@ -45,8 +39,8 @@ class MockedPipelineRequest {
|
|
|
45
39
|
* Sets a timeout.
|
|
46
40
|
* @param {number} timeout Timeout.
|
|
47
41
|
* @returns {MockedPipelineRequest}
|
|
48
|
-
|
|
49
|
-
setTimeout(timeout) {
|
|
42
|
+
*/;
|
|
43
|
+
_proto.setTimeout = function setTimeout(timeout) {
|
|
50
44
|
this.timeout = timeout;
|
|
51
45
|
return this;
|
|
52
46
|
}
|
|
@@ -54,8 +48,8 @@ class MockedPipelineRequest {
|
|
|
54
48
|
/**
|
|
55
49
|
* @param {number} retries The number of retries this pipeline request should perform.
|
|
56
50
|
* @return {PipelineRequest}
|
|
57
|
-
|
|
58
|
-
setRetries(retries = 3) {
|
|
51
|
+
*/;
|
|
52
|
+
_proto.setRetries = function setRetries(retries = 3) {
|
|
59
53
|
if (typeof retries !== 'number') throw new TypeError(`Expected 'number'. Received: '${typeof retries}'`);
|
|
60
54
|
if (retries < 0) throw new Error(`Expected positive integer. Received: '${retries}'`);
|
|
61
55
|
if (retries >= 5) throw new Error(`Max retries exceeded. Received: '${retries}'`);
|
|
@@ -66,8 +60,8 @@ class MockedPipelineRequest {
|
|
|
66
60
|
/**
|
|
67
61
|
* Returns promise and calls `MockedPipelineRequest.mockedDispatchResolver()`.
|
|
68
62
|
* @returns {Promise}
|
|
69
|
-
|
|
70
|
-
dispatch() {
|
|
63
|
+
*/;
|
|
64
|
+
_proto.dispatch = function dispatch() {
|
|
71
65
|
return new Promise((resolve, reject) => {
|
|
72
66
|
this.constructor.mockedDispatchResolver(this, resolve, reject);
|
|
73
67
|
});
|
|
@@ -76,8 +70,8 @@ class MockedPipelineRequest {
|
|
|
76
70
|
/**
|
|
77
71
|
* @param {string} processed The response process type.
|
|
78
72
|
* @return {PipelineRequest}
|
|
79
|
-
|
|
80
|
-
setResponseProcessed(processed = processTypes.DEFAULT_PROCESSED) {
|
|
73
|
+
*/;
|
|
74
|
+
_proto.setResponseProcessed = function setResponseProcessed(processed = processTypes.DEFAULT_PROCESSED) {
|
|
81
75
|
if (typeof processed !== 'string') throw new TypeError(`Expected 'string'. Received: '${typeof processed}'`);
|
|
82
76
|
if (!Object.values(processTypes).includes(processed)) {
|
|
83
77
|
throw new Error(`The value '${processed}' is not supported!`);
|
|
@@ -91,8 +85,8 @@ class MockedPipelineRequest {
|
|
|
91
85
|
* Can be used for custom error handling outside.
|
|
92
86
|
* @param {Object} errors - Array of error codes
|
|
93
87
|
* @return {PipelineRequest}
|
|
94
|
-
|
|
95
|
-
setErrorBlacklist(errors = []) {
|
|
88
|
+
*/;
|
|
89
|
+
_proto.setErrorBlacklist = function setErrorBlacklist(errors = []) {
|
|
96
90
|
this.errorBlacklist = errors;
|
|
97
91
|
return this;
|
|
98
92
|
}
|
|
@@ -100,8 +94,8 @@ class MockedPipelineRequest {
|
|
|
100
94
|
/**
|
|
101
95
|
* @param {string} handle The handle errors type.
|
|
102
96
|
* @return {PipelineRequest}
|
|
103
|
-
|
|
104
|
-
setHandleErrors(handle = errorHandleTypes.ERROR_HANDLE_DEFAULT) {
|
|
97
|
+
*/;
|
|
98
|
+
_proto.setHandleErrors = function setHandleErrors(handle = errorHandleTypes.ERROR_HANDLE_DEFAULT) {
|
|
105
99
|
if (typeof handle !== 'string') throw new TypeError(`Expected 'string'. Received: '${typeof handle}'`);
|
|
106
100
|
if (!Object.values(errorHandleTypes).includes(handle)) {
|
|
107
101
|
throw new Error(`The value '${handle}' is not supported!`);
|
|
@@ -115,8 +109,8 @@ class MockedPipelineRequest {
|
|
|
115
109
|
* @param {Array} errors Blacklisted errors.
|
|
116
110
|
* @returns {MockedPipelineRequest}
|
|
117
111
|
* @deprecated
|
|
118
|
-
|
|
119
|
-
setHandledErrors(errors = []) {
|
|
112
|
+
*/;
|
|
113
|
+
_proto.setHandledErrors = function setHandledErrors(errors = []) {
|
|
120
114
|
logger.warn('Deprecated: setHandledErrors() will be removed in favor of setErrorBlacklist()!');
|
|
121
115
|
this.setErrorBlacklist(errors);
|
|
122
116
|
return this;
|
|
@@ -128,26 +122,45 @@ class MockedPipelineRequest {
|
|
|
128
122
|
* @param {boolean} value Value.
|
|
129
123
|
* @return {PipelineRequest}
|
|
130
124
|
* @deprecated
|
|
131
|
-
|
|
132
|
-
setSuppressErrors(value) {
|
|
125
|
+
*/;
|
|
126
|
+
_proto.setSuppressErrors = function setSuppressErrors(value) {
|
|
133
127
|
logger.warn('Deprecated: setSuppressErrors() will be removed. Use setHandleErrors() instead!');
|
|
134
128
|
const handle = value ? errorHandleTypes.ERROR_HANDLE_SUPPRESS : errorHandleTypes.ERROR_HANDLE_DEFAULT;
|
|
135
129
|
this.setHandleErrors(handle);
|
|
136
130
|
return this;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
131
|
+
};
|
|
132
|
+
return _createClass(MockedPipelineRequest, null, [{
|
|
133
|
+
key: "mockedDispatchResolver",
|
|
134
|
+
get:
|
|
135
|
+
/**
|
|
136
|
+
* Getter for mockedDispatchResolver which is an additional helper function for custom, mock-only
|
|
137
|
+
* `dispatch()` resolver.
|
|
138
|
+
* @return {Function}
|
|
139
|
+
*/
|
|
140
|
+
function () {
|
|
141
|
+
return () => {};
|
|
142
|
+
}
|
|
143
|
+
}]);
|
|
144
|
+
}();
|
|
140
145
|
/**
|
|
141
146
|
* Factory which creates an instance of MockedPipelineRequest.
|
|
142
147
|
* @param {Function} callback Resolver callback.
|
|
143
148
|
* @returns {MockedPipelineRequest}
|
|
144
149
|
*/
|
|
145
|
-
export const mockedPipelineRequestFactory = callback =>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
* @return {Function}
|
|
149
|
-
*/
|
|
150
|
-
static get mockedDispatchResolver() {
|
|
151
|
-
return callback;
|
|
150
|
+
export const mockedPipelineRequestFactory = callback => /*#__PURE__*/function (_MockedPipelineReques) {
|
|
151
|
+
function _class() {
|
|
152
|
+
return _MockedPipelineReques.apply(this, arguments) || this;
|
|
152
153
|
}
|
|
153
|
-
|
|
154
|
+
_inheritsLoose(_class, _MockedPipelineReques);
|
|
155
|
+
return _createClass(_class, null, [{
|
|
156
|
+
key: "mockedDispatchResolver",
|
|
157
|
+
get:
|
|
158
|
+
/**
|
|
159
|
+
* Getter for custom mocked resolver.
|
|
160
|
+
* @return {Function}
|
|
161
|
+
*/
|
|
162
|
+
function () {
|
|
163
|
+
return callback;
|
|
164
|
+
}
|
|
165
|
+
}]);
|
|
166
|
+
}(MockedPipelineRequest);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A sequence of pipeline requests.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
let PipelineSequence = /*#__PURE__*/function () {
|
|
5
5
|
/**
|
|
6
6
|
* Constructor.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
function PipelineSequence() {
|
|
9
9
|
this.sequence = [];
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -13,7 +13,8 @@ class PipelineSequence {
|
|
|
13
13
|
* Adds a new serial to the sequence.
|
|
14
14
|
* @param {string} serial The pipeline request serial.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
var _proto = PipelineSequence.prototype;
|
|
17
|
+
_proto.set = function set(serial) {
|
|
17
18
|
const index = this.sequence.indexOf(serial);
|
|
18
19
|
if (index < 0) {
|
|
19
20
|
this.sequence.push(serial);
|
|
@@ -23,20 +24,21 @@ class PipelineSequence {
|
|
|
23
24
|
/**
|
|
24
25
|
* Returns the sequence.
|
|
25
26
|
* @return {Array}
|
|
26
|
-
|
|
27
|
-
get() {
|
|
27
|
+
*/;
|
|
28
|
+
_proto.get = function get() {
|
|
28
29
|
return this.sequence;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* Removes a serial from the sequence.
|
|
33
34
|
* @param {string} serial The pipeline request serial.
|
|
34
|
-
|
|
35
|
-
remove(serial) {
|
|
35
|
+
*/;
|
|
36
|
+
_proto.remove = function remove(serial) {
|
|
36
37
|
const index = this.sequence.indexOf(serial);
|
|
37
38
|
if (index >= 0) {
|
|
38
39
|
this.sequence.splice(index, 1);
|
|
39
40
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
41
|
+
};
|
|
42
|
+
return PipelineSequence;
|
|
43
|
+
}();
|
|
42
44
|
export default new PipelineSequence();
|
package/classes/Request/index.js
CHANGED
|
@@ -8,12 +8,12 @@ const defaultRequestManager = new RequestManager();
|
|
|
8
8
|
/**
|
|
9
9
|
* The request class.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
let Request = /*#__PURE__*/function () {
|
|
12
12
|
/**
|
|
13
13
|
* The constructor.
|
|
14
14
|
* @param {RequestManager} [manager] The manager for this request.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
function Request(manager) {
|
|
17
17
|
/**
|
|
18
18
|
* Creates the event callback name from the data request serial.
|
|
19
19
|
* @param {string} callbackKey The callback key to use.
|
|
@@ -29,32 +29,33 @@ class Request {
|
|
|
29
29
|
/**
|
|
30
30
|
* @return {boolean} Whether there are pending requests of this type.
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
var _proto = Request.prototype;
|
|
33
|
+
_proto.hasPendingRequests = function hasPendingRequests() {
|
|
33
34
|
return this.manager.pendingRequests > 0;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Generates the serial for this data request.
|
|
38
39
|
* @param {string} serialKey The serial key.
|
|
39
|
-
|
|
40
|
-
createSerial(serialKey) {
|
|
40
|
+
*/;
|
|
41
|
+
_proto.createSerial = function createSerial(serialKey) {
|
|
41
42
|
if (!this.serial) {
|
|
42
43
|
this.serial = CryptoJs.MD5(`${serialKey}${Date.now() + Math.random()}`).toString();
|
|
43
44
|
}
|
|
44
|
-
}
|
|
45
|
+
};
|
|
45
46
|
/**
|
|
46
47
|
* Returns the event callback name.
|
|
47
48
|
* @returns {string}
|
|
48
49
|
*/
|
|
49
|
-
getEventCallbackName() {
|
|
50
|
+
_proto.getEventCallbackName = function getEventCallbackName() {
|
|
50
51
|
return this.callbackName;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* Dispatches the request.
|
|
55
56
|
* @return {Promise} A promise that is fulfilled when a response is received for this request.
|
|
56
|
-
|
|
57
|
-
dispatch() {
|
|
57
|
+
*/;
|
|
58
|
+
_proto.dispatch = function dispatch() {
|
|
58
59
|
return new Promise((resolve, reject) => {
|
|
59
60
|
this.manager.handleDispatch(this, resolve, reject);
|
|
60
61
|
});
|
|
@@ -64,11 +65,12 @@ class Request {
|
|
|
64
65
|
* On timeout log error. Can be overridden by child classes.
|
|
65
66
|
* @param {Function} resolve The resolve() callback of the request promise.
|
|
66
67
|
* @param {Function} reject The reject() callback of the request promise.
|
|
67
|
-
|
|
68
|
-
onTimeout(resolve, reject) {
|
|
68
|
+
*/;
|
|
69
|
+
_proto.onTimeout = function onTimeout(resolve, reject) {
|
|
69
70
|
// eslint-disable-line class-methods-use-this
|
|
70
71
|
logger.error('Request timeout');
|
|
71
72
|
reject('Request timeout');
|
|
72
|
-
}
|
|
73
|
-
|
|
73
|
+
};
|
|
74
|
+
return Request;
|
|
75
|
+
}();
|
|
74
76
|
export default Request;
|
|
@@ -5,17 +5,18 @@ const REQUEST_BUFFER = 'RequestBuffer';
|
|
|
5
5
|
* The RequestBuffer class.
|
|
6
6
|
* It stores instances of performing request.
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
let RequestBuffer = /*#__PURE__*/function () {
|
|
9
|
+
function RequestBuffer() {
|
|
10
10
|
// Holds the ongoing requests.
|
|
11
11
|
this.requests = {};
|
|
12
12
|
}
|
|
13
|
+
var _proto = RequestBuffer.prototype;
|
|
13
14
|
/**
|
|
14
15
|
* Adds a new data request to the buffer store.
|
|
15
16
|
* @param {Object} req The request to store.
|
|
16
17
|
* @param {string} serial The serial for the request.
|
|
17
18
|
*/
|
|
18
|
-
add(req, serial) {
|
|
19
|
+
_proto.add = function add(req, serial) {
|
|
19
20
|
const request = this.requests[serial];
|
|
20
21
|
if (request) {
|
|
21
22
|
logger.error(`${REQUEST_BUFFER}: a request with the serial '${serial}' already exists!`);
|
|
@@ -28,8 +29,8 @@ class RequestBuffer {
|
|
|
28
29
|
* Retrieves a data request from the buffer.
|
|
29
30
|
* @param {string} serial The serial for the request.
|
|
30
31
|
* @returns {DataRequest}
|
|
31
|
-
|
|
32
|
-
get(serial) {
|
|
32
|
+
*/;
|
|
33
|
+
_proto.get = function get(serial) {
|
|
33
34
|
const request = this.requests[serial];
|
|
34
35
|
if (!request) {
|
|
35
36
|
logger.error(`${REQUEST_BUFFER}: no stored request for the serial '${serial}' found!`);
|
|
@@ -41,13 +42,14 @@ class RequestBuffer {
|
|
|
41
42
|
/**
|
|
42
43
|
* Removes the data request from the buffer.
|
|
43
44
|
* @param {string} serial The serial for the request.
|
|
44
|
-
|
|
45
|
-
remove(serial) {
|
|
45
|
+
*/;
|
|
46
|
+
_proto.remove = function remove(serial) {
|
|
46
47
|
try {
|
|
47
48
|
delete this.requests[serial];
|
|
48
49
|
} catch (e) {
|
|
49
50
|
logger.error(e);
|
|
50
51
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
52
|
+
};
|
|
53
|
+
return RequestBuffer;
|
|
54
|
+
}();
|
|
53
55
|
export default new RequestBuffer();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
1
2
|
import { logger } from "../../helpers";
|
|
2
3
|
import { PROCESS_ANY, PROCESS_LAST_REQUEST, PROCESS_FIRST_RESPONSE, PROCESS_SEQUENTIALLY, PROCESS_ORDERED_REQUEST, PROPAGATE_REJECT, PROPAGATE_SINGLE } from "../../constants/RequestManagerModes";
|
|
3
4
|
import { EPIPELINERESPONSEREJECTED } from "../../constants/Pipeline";
|
|
@@ -134,7 +135,7 @@ const processSequentially = (self, response, resolve) => {
|
|
|
134
135
|
* The request manager handles processing of requests and
|
|
135
136
|
* propagation of received responses.
|
|
136
137
|
*/
|
|
137
|
-
|
|
138
|
+
let RequestManager = /*#__PURE__*/function () {
|
|
138
139
|
/**
|
|
139
140
|
* Creates a new request manager.
|
|
140
141
|
* @param {Object} options The options.
|
|
@@ -142,7 +143,7 @@ class RequestManager {
|
|
|
142
143
|
* @param {string} options.propagationMode The propagation mode for queued requests.
|
|
143
144
|
* @param {number|false} options.timeout Requests timeout duration.
|
|
144
145
|
*/
|
|
145
|
-
|
|
146
|
+
function RequestManager({
|
|
146
147
|
processingMode = PROCESS_ANY,
|
|
147
148
|
propagationMode = PROPAGATE_SINGLE,
|
|
148
149
|
timeout = false
|
|
@@ -162,7 +163,8 @@ class RequestManager {
|
|
|
162
163
|
* @param {Function} resolve The resolve() callback of the request promise.
|
|
163
164
|
* @param {Function} reject The reject() callback of the request promise.
|
|
164
165
|
*/
|
|
165
|
-
|
|
166
|
+
var _proto = RequestManager.prototype;
|
|
167
|
+
_proto.enqueueRequest = function enqueueRequest(request, resolve, reject) {
|
|
166
168
|
// Get the current timestamp.
|
|
167
169
|
const timestamp = this.currentTime;
|
|
168
170
|
|
|
@@ -189,8 +191,8 @@ class RequestManager {
|
|
|
189
191
|
* @param {Request} request The request.
|
|
190
192
|
* @param {Function} resolve The resolve() callback of the request promise.
|
|
191
193
|
* @param {Function} reject The reject() callback of the request promise.
|
|
192
|
-
|
|
193
|
-
handleDispatch(request, resolve, reject) {
|
|
194
|
+
*/;
|
|
195
|
+
_proto.handleDispatch = function handleDispatch(request, resolve, reject) {
|
|
194
196
|
if (this.processingMode !== PROCESS_ANY) {
|
|
195
197
|
// Enqueue this request if it requires special handling.
|
|
196
198
|
this.enqueueRequest(request, resolve, reject);
|
|
@@ -211,8 +213,8 @@ class RequestManager {
|
|
|
211
213
|
* @param {Request} request The request this response belongs to.
|
|
212
214
|
* @param {Function} reject The reject() callback of the request promise.
|
|
213
215
|
* @param {Object} [message] The error object.
|
|
214
|
-
|
|
215
|
-
handleError(request, reject, message) {
|
|
216
|
+
*/;
|
|
217
|
+
_proto.handleError = function handleError(request, reject, message) {
|
|
216
218
|
clearTimeout(this.timers[request.serial]);
|
|
217
219
|
delete this.timers[request.serial];
|
|
218
220
|
if (this.processingMode === PROCESS_ANY) {
|
|
@@ -232,8 +234,8 @@ class RequestManager {
|
|
|
232
234
|
* @param {Request} request The request this response belongs to.
|
|
233
235
|
* @param {Function} resolve The resolve() callback of the request promise.
|
|
234
236
|
* @param {Object} response The response.
|
|
235
|
-
|
|
236
|
-
handleResponse(request, resolve, response) {
|
|
237
|
+
*/;
|
|
238
|
+
_proto.handleResponse = function handleResponse(request, resolve, response) {
|
|
237
239
|
clearTimeout(this.timers[request.serial]);
|
|
238
240
|
delete this.timers[request.serial];
|
|
239
241
|
this.pendingRequests -= 1;
|
|
@@ -258,10 +260,13 @@ class RequestManager {
|
|
|
258
260
|
|
|
259
261
|
/**
|
|
260
262
|
* @return {number} The current unix timestamp.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
263
|
+
*/;
|
|
264
|
+
return _createClass(RequestManager, [{
|
|
265
|
+
key: "currentTime",
|
|
266
|
+
get: function () {
|
|
267
|
+
// eslint-disable-line class-methods-use-this
|
|
268
|
+
return Date.now();
|
|
269
|
+
}
|
|
270
|
+
}]);
|
|
271
|
+
}();
|
|
267
272
|
export default RequestManager;
|