@tramvai/module-request-limiter 5.49.1 → 6.59.0

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.
@@ -1,8 +1,8 @@
1
1
  import fp from 'fastify-plugin';
2
+ import { DoubleLinkedList } from '@tramvai/core';
2
3
  import { HttpError } from '@tinkoff/errors';
3
4
  import onFinished from 'on-finished';
4
5
  import { monitorEventLoopDelay } from 'perf_hooks';
5
- import { DoubleLinkedList } from './utils/doubleLinkedList.es.js';
6
6
 
7
7
  const DEFAULT_OPTIONS = {
8
8
  limit: 10,
@@ -12,10 +12,17 @@ const DEFAULT_OPTIONS = {
12
12
  };
13
13
  const resolution = 10;
14
14
  class RequestLimiter {
15
+ currentActive = 0;
16
+ eventLoopDelay = 0;
17
+ queue = new DoubleLinkedList();
18
+ activeRequestLimit;
19
+ queueLimit;
20
+ error;
21
+ minimalActiveRequestLimit;
22
+ maxEventLoopDelay;
23
+ eventLoopHistogram;
24
+ metrics;
15
25
  constructor(options, metrics) {
16
- this.currentActive = 0;
17
- this.eventLoopDelay = 0;
18
- this.queue = new DoubleLinkedList();
19
26
  const { limit, queue, maxEventLoopDelay, error } = options;
20
27
  this.activeRequestLimit = limit;
21
28
  this.minimalActiveRequestLimit = Math.round(limit / 3);
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var fp = require('fastify-plugin');
6
+ var core = require('@tramvai/core');
6
7
  var errors = require('@tinkoff/errors');
7
8
  var onFinished = require('on-finished');
8
9
  var perf_hooks = require('perf_hooks');
9
- var doubleLinkedList = require('./utils/doubleLinkedList.js');
10
10
 
11
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
12
 
@@ -21,10 +21,17 @@ const DEFAULT_OPTIONS = {
21
21
  };
22
22
  const resolution = 10;
23
23
  class RequestLimiter {
24
+ currentActive = 0;
25
+ eventLoopDelay = 0;
26
+ queue = new core.DoubleLinkedList();
27
+ activeRequestLimit;
28
+ queueLimit;
29
+ error;
30
+ minimalActiveRequestLimit;
31
+ maxEventLoopDelay;
32
+ eventLoopHistogram;
33
+ metrics;
24
34
  constructor(options, metrics) {
25
- this.currentActive = 0;
26
- this.eventLoopDelay = 0;
27
- this.queue = new doubleLinkedList.DoubleLinkedList();
28
35
  const { limit, queue, maxEventLoopDelay, error } = options;
29
36
  this.activeRequestLimit = limit;
30
37
  this.minimalActiveRequestLimit = Math.round(limit / 3);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-request-limiter",
3
- "version": "5.49.1",
3
+ "version": "6.59.0",
4
4
  "description": "Enable different rendering modes for pages",
5
5
  "main": "lib/server.js",
6
6
  "module": "lib/server.es.js",
@@ -23,17 +23,16 @@
23
23
  "registry": "https://registry.npmjs.org/"
24
24
  },
25
25
  "dependencies": {
26
- "@tinkoff/errors": "0.6.2",
26
+ "@tinkoff/errors": "0.7.1",
27
+ "@tramvai/tokens-metrics": "6.59.0",
27
28
  "fastify-plugin": "^4.2.1",
28
- "on-finished": "^2.3.0",
29
- "@tramvai/tokens-metrics": "5.49.1"
29
+ "on-finished": "^2.3.0"
30
30
  },
31
- "devDependencies": {},
32
31
  "peerDependencies": {
33
- "@tinkoff/dippy": "0.11.4",
34
- "@tramvai/core": "5.49.1",
35
- "@tramvai/tokens-common": "5.49.1",
36
- "@tramvai/tokens-server-private": "5.49.1",
32
+ "@tinkoff/dippy": "0.12.3",
33
+ "@tramvai/core": "6.59.0",
34
+ "@tramvai/tokens-common": "6.59.0",
35
+ "@tramvai/tokens-server-private": "6.59.0",
37
36
  "fastify": "^4.6.0",
38
37
  "tslib": "^2.4.0"
39
38
  }
@@ -1,16 +0,0 @@
1
- interface ListNode<Value> {
2
- next: ListNode<Value>;
3
- prev: ListNode<Value>;
4
- value: Value;
5
- }
6
- export declare class DoubleLinkedList<Value> {
7
- length: number;
8
- start: null | ListNode<Value>;
9
- end: null | ListNode<Value>;
10
- push(value: Value): void;
11
- pop(): Value;
12
- shift(): Value;
13
- size(): number;
14
- }
15
- export {};
16
- //# sourceMappingURL=doubleLinkedList.d.ts.map
@@ -1,61 +0,0 @@
1
- class DoubleLinkedList {
2
- constructor() {
3
- this.length = 0;
4
- this.start = null;
5
- this.end = null;
6
- }
7
- push(value) {
8
- const newNode = {
9
- value,
10
- next: null,
11
- prev: null,
12
- };
13
- this.length++;
14
- if (this.start === null) {
15
- this.start = newNode;
16
- this.end = newNode;
17
- return;
18
- }
19
- const currentEnd = this.end;
20
- this.end = newNode;
21
- this.end.prev = currentEnd;
22
- currentEnd.next = this.end;
23
- }
24
- pop() {
25
- if (this.end === null) {
26
- return null;
27
- }
28
- this.length--;
29
- // if equal we have only 1 node, so we just remove start
30
- if (this.end === this.start) {
31
- this.start = null;
32
- }
33
- const { value } = this.end;
34
- this.end = this.end.prev;
35
- if (this.end) {
36
- this.end.next = null;
37
- }
38
- return value;
39
- }
40
- shift() {
41
- if (this.start === null) {
42
- return null;
43
- }
44
- this.length--;
45
- // if equal we have only 1 node, so we just remove end
46
- if (this.end === this.start) {
47
- this.end = null;
48
- }
49
- const { value } = this.start;
50
- this.start = this.start.next;
51
- if (this.start) {
52
- this.start.prev = null;
53
- }
54
- return value;
55
- }
56
- size() {
57
- return this.length;
58
- }
59
- }
60
-
61
- export { DoubleLinkedList };
@@ -1,65 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- class DoubleLinkedList {
6
- constructor() {
7
- this.length = 0;
8
- this.start = null;
9
- this.end = null;
10
- }
11
- push(value) {
12
- const newNode = {
13
- value,
14
- next: null,
15
- prev: null,
16
- };
17
- this.length++;
18
- if (this.start === null) {
19
- this.start = newNode;
20
- this.end = newNode;
21
- return;
22
- }
23
- const currentEnd = this.end;
24
- this.end = newNode;
25
- this.end.prev = currentEnd;
26
- currentEnd.next = this.end;
27
- }
28
- pop() {
29
- if (this.end === null) {
30
- return null;
31
- }
32
- this.length--;
33
- // if equal we have only 1 node, so we just remove start
34
- if (this.end === this.start) {
35
- this.start = null;
36
- }
37
- const { value } = this.end;
38
- this.end = this.end.prev;
39
- if (this.end) {
40
- this.end.next = null;
41
- }
42
- return value;
43
- }
44
- shift() {
45
- if (this.start === null) {
46
- return null;
47
- }
48
- this.length--;
49
- // if equal we have only 1 node, so we just remove end
50
- if (this.end === this.start) {
51
- this.end = null;
52
- }
53
- const { value } = this.start;
54
- this.start = this.start.next;
55
- if (this.start) {
56
- this.start.prev = null;
57
- }
58
- return value;
59
- }
60
- size() {
61
- return this.length;
62
- }
63
- }
64
-
65
- exports.DoubleLinkedList = DoubleLinkedList;