@kronos-integration/interceptor 13.2.3 → 13.3.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/package.json CHANGED
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "name": "@kronos-integration/interceptor",
3
- "version": "13.2.3",
3
+ "version": "13.3.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
7
7
  },
8
8
  "packageManager": "npm@11.16.0",
9
- "types": "./types/index.d.mts",
10
9
  "exports": {
11
10
  ".": {
12
- "types": "./types/index.d.mts",
13
11
  "default": "./src/index.mjs"
14
12
  }
15
13
  },
@@ -29,26 +27,22 @@
29
27
  ],
30
28
  "license": "0BSD",
31
29
  "scripts": {
32
- "prepare": "node --run prepare:typescript",
33
- "prepare:typescript": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir types --resolveJsonModule --target esnext -m esnext --module nodenext --moduleResolution nodenext --rootDir src ./src**/*.mjs",
34
30
  "test": "node --run test:ava",
35
31
  "test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
36
32
  "cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
37
33
  "docs": "documentation readme --section=API ./src**/*.mjs",
38
- "lint": "node --run lint:docs && node --run lint:typescript",
39
- "lint:docs": "documentation lint ./src**/*.mjs",
40
- "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
34
+ "lint": "node --run lint:docs",
35
+ "lint:docs": "documentation lint ./src**/*.mjs"
41
36
  },
42
37
  "dependencies": {
43
- "pacc": "^9.2.14"
38
+ "pacc": "^10.0.2"
44
39
  },
45
40
  "devDependencies": {
46
41
  "@kronos-integration/test-interceptor": "^7.0.32",
47
42
  "ava": "^8.0.1",
48
43
  "c8": "^11.0.0",
49
44
  "documentation": "^14.0.3",
50
- "semantic-release": "^25.0.5",
51
- "typescript": "^6.0.3"
45
+ "semantic-release": "^25.0.5"
52
46
  },
53
47
  "overrides": {
54
48
  "c8": {
@@ -69,8 +63,7 @@
69
63
  "template": {
70
64
  "inheritFrom": [
71
65
  "arlac77/template-arlac77-github",
72
- "arlac77/template-kronos-component",
73
- "arlac77/template-typescript"
66
+ "arlac77/template-kronos-component"
74
67
  ]
75
68
  }
76
69
  }
@@ -10,6 +10,7 @@ export class IntervalInterceptor extends Interceptor {
10
10
  {
11
11
  interval: {
12
12
  ...duration_ms_attribute,
13
+ name: "interval",
13
14
  description: "min interval between two requests",
14
15
  default: "60s",
15
16
  }
@@ -33,6 +33,7 @@ export class LimitingInterceptor extends Interceptor {
33
33
  {
34
34
  limits: {
35
35
  ...object_attribute,
36
+ name: "limits",
36
37
  default: [
37
38
  {
38
39
  count: 10
@@ -40,7 +41,7 @@ export class LimitingInterceptor extends Interceptor {
40
41
  ],
41
42
  attributes: {
42
43
  count: count_attribute,
43
- delay: duration_ms_attribute
44
+ delay: { ...duration_ms_attribute, name: "delay" }
44
45
  }
45
46
  }
46
47
  },
@@ -71,7 +72,9 @@ export class LimitingInterceptor extends Interceptor {
71
72
  for (const limit of this.limits) {
72
73
  if (this.ongoingRequests >= limit.count) {
73
74
  if (limit.delay === undefined) {
74
- throw new Error(`Limit of ongoing requests ${limit.count} reached`,{ cause: this.ongoingRequests });
75
+ throw new Error(`Limit of ongoing requests ${limit.count} reached`, {
76
+ cause: this.ongoingRequests
77
+ });
75
78
  }
76
79
 
77
80
  this.ongoingRequests += 1;
@@ -1,5 +1,5 @@
1
1
  import { Interceptor } from "./interceptor.mjs";
2
- import { expand, prepareAttributesDefinitions, default_attribute } from "pacc";
2
+ import { expand, prepareAttributesDefinitions, object_attribute } from "pacc";
3
3
 
4
4
  /**
5
5
  * Map params into requests.
@@ -15,8 +15,8 @@ export class TemplateInterceptor extends Interceptor {
15
15
  static attributes = prepareAttributesDefinitions(
16
16
  {
17
17
  request: {
18
- ...default_attribute,
19
- type: "object",
18
+ ...object_attribute,
19
+ name: "request",
20
20
  description: "request template",
21
21
  default: {}
22
22
  }
package/types/index.d.mts DELETED
@@ -1,7 +0,0 @@
1
- export * from "./interceptor.mjs";
2
- export * from "./timeout-interceptor.mjs";
3
- export * from "./stats-collector-interceptor.mjs";
4
- export * from "./limiting-interceptor.mjs";
5
- export * from "./interval-interceptor.mjs";
6
- export * from "./logging-interceptor.mjs";
7
- export * from "./template-interceptor.mjs";
@@ -1,62 +0,0 @@
1
- /**
2
- * @typedef {Object} Endpoint
3
- */
4
- /**
5
- * Base interceptor. The base class for all the interceptors
6
- * Calls configure() and reset().
7
- * @param {Object?} config The interceptor configuration object.
8
- */
9
- export class Interceptor {
10
- /**
11
- * Meta description of the configuration
12
- * @return {Object}
13
- */
14
- static attributes: {};
15
- /**
16
- *
17
- * @param {Object} [config]
18
- */
19
- constructor(config?: Object);
20
- /**
21
- * The instance method returning the type.
22
- * Defaults to the constructors name (class name)
23
- * @return {string}
24
- */
25
- get type(): string;
26
- /**
27
- * Meta description of the configuration.
28
- * @return {Object}
29
- */
30
- get attributes(): Object;
31
- /**
32
- * Takes attribute values from config parameters
33
- * and copies them over to the object.
34
- * Copying is done according to attributes.
35
- * Which means we loop over all configuration attributes
36
- * and then for each attribute decide if we use the default, call
37
- * a setter function or simply assign the attribute value.
38
- * @param {Object} [config]
39
- */
40
- configure(config?: Object): void;
41
- toString(): string;
42
- toJSON(): Object;
43
- /**
44
- * Deliver the json representation.
45
- * @return {Object} json representation
46
- */
47
- toJSONWithOptions(options: any): Object;
48
- /**
49
- * Forget all accumulated information.
50
- */
51
- reset(): void;
52
- /**
53
- * The receive method. This method receives the request from the leading interceptor
54
- * and calls the trailing interceptor.
55
- * @param {Endpoint} endpoint
56
- * @param {Function} next
57
- * @param {any[]} args the request from the leading interceptor
58
- * @return {Promise<any>}
59
- */
60
- receive(endpoint: Endpoint, next: Function, ...args: any[]): Promise<any>;
61
- }
62
- export type Endpoint = Object;
@@ -1,10 +0,0 @@
1
- /**
2
- * Only passes requests after inteval time has passed
3
- * @property {number} interval
4
- */
5
- export class IntervalInterceptor extends Interceptor {
6
- static attributes: Object;
7
- receive(endpoint: any, next: any, ...args: any[]): Promise<any>;
8
- lastTime: Date | undefined;
9
- }
10
- import { Interceptor } from "./interceptor.mjs";
@@ -1,29 +0,0 @@
1
- /**
2
- * Limits the number of concurrent requests.
3
- * Requests can be delayed or rejected.
4
- * Sample config:
5
- * [
6
- * { count: 20 },
7
- * { count: 10, delay: 100 },
8
- * { count: 5, delay: 10 }
9
- * ]
10
- * 1 - 4 : no delay
11
- * 5 - 9 : 10ms delay
12
- * 10 - 19 : 100ms delay
13
- * 20 : reject
14
- * default is to reject when more than 10 requests are on the way
15
- */
16
- export class LimitingInterceptor extends Interceptor {
17
- static attributes: Object;
18
- /**
19
- *
20
- * @param {Object?} config
21
- */
22
- constructor(config: Object | null);
23
- limits: any;
24
- ongoingResponses: Set<any> | undefined;
25
- ongoingRequests: number | undefined;
26
- receive(endpoint: any, next: any, ...args: any[]): Promise<any>;
27
- _processRequest(next: any, ...args: any[]): any;
28
- }
29
- import { Interceptor } from "./interceptor.mjs";
@@ -1,7 +0,0 @@
1
- /**
2
- * logs args and result
3
- */
4
- export class LoggingInterceptor extends Interceptor {
5
- receive(endpoint: any, next: any, ...args: any[]): Promise<any>;
6
- }
7
- import { Interceptor } from "./interceptor.mjs";
@@ -1,16 +0,0 @@
1
- /**
2
- * Interceptor to collect processing time, number of
3
- * processed and failed requests.
4
- */
5
- export class StatsCollectorInterceptor extends Interceptor {
6
- numberOfRequests: number | undefined;
7
- numberOfFailedRequests: number | undefined;
8
- minRequestProcessingTime: number | undefined;
9
- maxRequestProcessingTime: number | undefined;
10
- totalRequestProcessingTime: number | undefined;
11
- /**
12
- * Logs the time the requests takes
13
- */
14
- receive(endpoint: any, next: any, ...args: any[]): Promise<any>;
15
- }
16
- import { Interceptor } from "./interceptor.mjs";
@@ -1,8 +0,0 @@
1
- /**
2
- * Map params into requests.
3
- */
4
- export class TemplateInterceptor extends Interceptor {
5
- static attributes: Object;
6
- receive(endpoint: any, next: any, params: any): Promise<any>;
7
- }
8
- import { Interceptor } from "./interceptor.mjs";
@@ -1,9 +0,0 @@
1
- /**
2
- * Rejects a request if it does not resolve in a given time.
3
- * @property {number} timeout
4
- */
5
- export class TimeoutInterceptor extends Interceptor {
6
- static attributes: Object;
7
- receive(endpoint: any, next: any, ...args: any[]): Promise<any>;
8
- }
9
- import { Interceptor } from "./interceptor.mjs";