@kronos-integration/interceptor 12.0.0 → 12.0.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/README.md +5 -5
- package/package.json +1 -1
- package/src/interceptor.mjs +1 -3
- package/src/limiting-interceptor.mjs +16 -20
- package/src/template-interceptor.mjs +8 -12
- package/src/timeout-interceptor.mjs +8 -12
- package/types/interceptor.d.mts +1 -1
- package/types/limiting-interceptor.d.mts +1 -0
- package/types/template-interceptor.d.mts +1 -0
- package/types/timeout-interceptor.d.mts +1 -0
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ const response = interceptor.receive(endpoint, arg1, arg2);
|
|
|
32
32
|
* [Interceptor](#interceptor)
|
|
33
33
|
* [Parameters](#parameters)
|
|
34
34
|
* [type](#type)
|
|
35
|
-
* [
|
|
35
|
+
* [attributes](#attributes)
|
|
36
36
|
* [configure](#configure)
|
|
37
37
|
* [Parameters](#parameters-1)
|
|
38
38
|
* [toJSONWithOptions](#tojsonwithoptions)
|
|
@@ -40,7 +40,7 @@ const response = interceptor.receive(endpoint, arg1, arg2);
|
|
|
40
40
|
* [reset](#reset)
|
|
41
41
|
* [receive](#receive)
|
|
42
42
|
* [Parameters](#parameters-3)
|
|
43
|
-
* [
|
|
43
|
+
* [attributes](#attributes-1)
|
|
44
44
|
* [LimitingInterceptor](#limitinginterceptor)
|
|
45
45
|
* [Parameters](#parameters-4)
|
|
46
46
|
* [name](#name)
|
|
@@ -80,7 +80,7 @@ Defaults to the constructors name (class name)
|
|
|
80
80
|
|
|
81
81
|
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
|
|
82
82
|
|
|
83
|
-
###
|
|
83
|
+
### attributes
|
|
84
84
|
|
|
85
85
|
Meta description of the configuration.
|
|
86
86
|
|
|
@@ -90,7 +90,7 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
|
|
|
90
90
|
|
|
91
91
|
Takes attribute values from config parameters
|
|
92
92
|
and copies them over to the object.
|
|
93
|
-
Copying is done according to
|
|
93
|
+
Copying is done according to attributes.
|
|
94
94
|
Which means we loop over all configuration attributes
|
|
95
95
|
and then for each attribute decide if we use the default, call
|
|
96
96
|
a setter function or simply assign the attribute value.
|
|
@@ -126,7 +126,7 @@ and calls the trailing interceptor.
|
|
|
126
126
|
|
|
127
127
|
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<any>** 
|
|
128
128
|
|
|
129
|
-
###
|
|
129
|
+
### attributes
|
|
130
130
|
|
|
131
131
|
Meta description of the configuration
|
|
132
132
|
|
package/package.json
CHANGED
package/src/interceptor.mjs
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
import { prepareAttributesDefinitions } from "pacc";
|
|
2
2
|
import { Interceptor } from "./interceptor.mjs";
|
|
3
3
|
|
|
4
|
-
const ATTRIBUTES = prepareAttributesDefinitions({
|
|
5
|
-
limits: {
|
|
6
|
-
default: [
|
|
7
|
-
{
|
|
8
|
-
count: 10
|
|
9
|
-
}
|
|
10
|
-
],
|
|
11
|
-
count: {
|
|
12
|
-
type: "unsigned-integer"
|
|
13
|
-
},
|
|
14
|
-
delay: {
|
|
15
|
-
type: "duration"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
...Interceptor.attributes
|
|
19
|
-
});
|
|
20
|
-
|
|
21
4
|
/**
|
|
22
5
|
* Limits the number of concurrent requests.
|
|
23
6
|
* Requests can be delayed or rejected.
|
|
@@ -41,9 +24,22 @@ export class LimitingInterceptor extends Interceptor {
|
|
|
41
24
|
return "request-limit";
|
|
42
25
|
}
|
|
43
26
|
|
|
44
|
-
static
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
static attributes = prepareAttributesDefinitions({
|
|
28
|
+
limits: {
|
|
29
|
+
default: [
|
|
30
|
+
{
|
|
31
|
+
count: 10
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
count: {
|
|
35
|
+
type: "unsigned-integer"
|
|
36
|
+
},
|
|
37
|
+
delay: {
|
|
38
|
+
type: "duration"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
...Interceptor.attributes
|
|
42
|
+
});
|
|
47
43
|
|
|
48
44
|
constructor(config) {
|
|
49
45
|
super(config);
|
|
@@ -2,15 +2,6 @@ import { Interceptor } from "./interceptor.mjs";
|
|
|
2
2
|
import { prepareAttributesDefinitions } from "pacc";
|
|
3
3
|
import { expand } from "./util.mjs";
|
|
4
4
|
|
|
5
|
-
const ATTRIBUTES = prepareAttributesDefinitions({
|
|
6
|
-
request: {
|
|
7
|
-
description: "request template",
|
|
8
|
-
default: {},
|
|
9
|
-
type: "object"
|
|
10
|
-
},
|
|
11
|
-
...Interceptor.attributes
|
|
12
|
-
});
|
|
13
|
-
|
|
14
5
|
/**
|
|
15
6
|
* Map params into requests.
|
|
16
7
|
*/
|
|
@@ -22,9 +13,14 @@ export class TemplateInterceptor extends Interceptor {
|
|
|
22
13
|
return "template";
|
|
23
14
|
}
|
|
24
15
|
|
|
25
|
-
static
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
static attributes = prepareAttributesDefinitions({
|
|
17
|
+
request: {
|
|
18
|
+
description: "request template",
|
|
19
|
+
default: {},
|
|
20
|
+
type: "object"
|
|
21
|
+
},
|
|
22
|
+
...Interceptor.attributes
|
|
23
|
+
});
|
|
28
24
|
|
|
29
25
|
async receive(endpoint, next, params) {
|
|
30
26
|
return next(expand(this.request, params));
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { prepareAttributesDefinitions } from "pacc";
|
|
2
2
|
import { Interceptor } from "./interceptor.mjs";
|
|
3
3
|
|
|
4
|
-
const ATTRIBUTES = prepareAttributesDefinitions({
|
|
5
|
-
timeout: {
|
|
6
|
-
description: "request timeout",
|
|
7
|
-
default: 1,
|
|
8
|
-
type: "duration"
|
|
9
|
-
},
|
|
10
|
-
...Interceptor.attributes
|
|
11
|
-
});
|
|
12
|
-
|
|
13
4
|
/**
|
|
14
5
|
* Rejects a request if it does not resolve in a given time.
|
|
15
6
|
* @property {number} timeout
|
|
16
7
|
*/
|
|
17
8
|
export class TimeoutInterceptor extends Interceptor {
|
|
18
|
-
static
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
static attributes = prepareAttributesDefinitions({
|
|
10
|
+
timeout: {
|
|
11
|
+
description: "request timeout",
|
|
12
|
+
default: 1,
|
|
13
|
+
type: "duration"
|
|
14
|
+
},
|
|
15
|
+
...Interceptor.attributes
|
|
16
|
+
});
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
19
|
* @return {string} 'timeout'
|
package/types/interceptor.d.mts
CHANGED