@toa.io/extensions.exposition 1.0.0-alpha.151 → 1.0.0-alpha.153

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.
Files changed (124) hide show
  1. package/components/identity.bans/operations/tsconfig.tsbuildinfo +1 -1
  2. package/components/identity.basic/operations/tsconfig.tsbuildinfo +1 -1
  3. package/components/identity.federation/operations/tsconfig.tsbuildinfo +1 -1
  4. package/components/identity.keys/operations/tsconfig.tsbuildinfo +1 -1
  5. package/components/identity.otp/operations/tsconfig.tsbuildinfo +1 -1
  6. package/components/identity.passkeys/operations/tsconfig.tsbuildinfo +1 -1
  7. package/components/identity.roles/operations/tsconfig.tsbuildinfo +1 -1
  8. package/components/identity.tokens/operations/tsconfig.tsbuildinfo +1 -1
  9. package/documentation/io.md +42 -2
  10. package/documentation/map.md +10 -0
  11. package/documentation/notes/desync.jpg +0 -0
  12. package/documentation/notes/peers.md +59 -0
  13. package/documentation/notes/throttling.md +82 -0
  14. package/features/io.throttle.feature +40 -0
  15. package/features/map.feature +24 -0
  16. package/package.json +4 -3
  17. package/schemas/io/throttle.cos.yaml +36 -0
  18. package/source/Directive.test.ts +4 -2
  19. package/source/Directive.ts +16 -1
  20. package/source/Gateway.ts +2 -0
  21. package/source/HTTP/Server.ts +47 -21
  22. package/source/HTTP/exceptions.ts +21 -15
  23. package/source/RTD/Directives.ts +4 -0
  24. package/source/RTD/Route.ts +8 -2
  25. package/source/RTD/Tree.ts +4 -0
  26. package/source/RTD/segment.ts +2 -0
  27. package/source/directives/io/Directive.ts +5 -2
  28. package/source/directives/io/IO.ts +17 -5
  29. package/source/directives/io/Input.ts +1 -1
  30. package/source/directives/io/Output.ts +1 -1
  31. package/source/directives/io/Throttle.ts +32 -0
  32. package/source/directives/io/lib/throttle/Configuration.test.ts +40 -0
  33. package/source/directives/io/lib/throttle/Configuration.ts +58 -0
  34. package/source/directives/io/lib/throttle/Interval.ts +31 -0
  35. package/source/directives/io/lib/throttle/Keys.ts +40 -0
  36. package/source/directives/io/lib/throttle/Quota.ts +22 -0
  37. package/source/directives/io/lib/throttle/Quotas.test.ts +132 -0
  38. package/source/directives/io/lib/throttle/Quotas.ts +83 -0
  39. package/source/directives/io/lib/throttle/components/Component.ts +5 -0
  40. package/source/directives/io/lib/throttle/components/IP.ts +40 -0
  41. package/source/directives/io/lib/throttle/components/Path.ts +8 -0
  42. package/source/directives/io/lib/throttle/components/index.ts +13 -0
  43. package/source/directives/io/lib/throttle/conditions/Condition.ts +5 -0
  44. package/source/directives/io/lib/throttle/conditions/Status.ts +17 -0
  45. package/source/directives/io/lib/throttle/conditions/index.ts +11 -0
  46. package/source/directives/io/lib/throttle/index.ts +2 -0
  47. package/source/directives/io/schemas.test.ts +9 -0
  48. package/source/directives/io/schemas.ts +3 -0
  49. package/transpiled/Directive.d.ts +3 -0
  50. package/transpiled/Directive.js +12 -1
  51. package/transpiled/Directive.js.map +1 -1
  52. package/transpiled/Gateway.js +1 -0
  53. package/transpiled/Gateway.js.map +1 -1
  54. package/transpiled/HTTP/Server.js +41 -16
  55. package/transpiled/HTTP/Server.js.map +1 -1
  56. package/transpiled/HTTP/exceptions.d.ts +11 -8
  57. package/transpiled/HTTP/exceptions.js +23 -17
  58. package/transpiled/HTTP/exceptions.js.map +1 -1
  59. package/transpiled/RTD/Directives.d.ts +3 -0
  60. package/transpiled/RTD/Route.d.ts +1 -0
  61. package/transpiled/RTD/Route.js +7 -2
  62. package/transpiled/RTD/Route.js.map +1 -1
  63. package/transpiled/RTD/Tree.d.ts +1 -0
  64. package/transpiled/RTD/Tree.js +3 -0
  65. package/transpiled/RTD/Tree.js.map +1 -1
  66. package/transpiled/RTD/segment.d.ts +1 -0
  67. package/transpiled/RTD/segment.js +2 -0
  68. package/transpiled/RTD/segment.js.map +1 -1
  69. package/transpiled/directives/io/Directive.d.ts +5 -2
  70. package/transpiled/directives/io/IO.d.ts +4 -2
  71. package/transpiled/directives/io/IO.js +13 -3
  72. package/transpiled/directives/io/IO.js.map +1 -1
  73. package/transpiled/directives/io/Input.d.ts +1 -1
  74. package/transpiled/directives/io/Input.js +1 -1
  75. package/transpiled/directives/io/Input.js.map +1 -1
  76. package/transpiled/directives/io/Output.d.ts +1 -1
  77. package/transpiled/directives/io/Output.js +1 -1
  78. package/transpiled/directives/io/Output.js.map +1 -1
  79. package/transpiled/directives/io/Throttle.d.ts +11 -0
  80. package/transpiled/directives/io/Throttle.js +51 -0
  81. package/transpiled/directives/io/Throttle.js.map +1 -0
  82. package/transpiled/directives/io/lib/throttle/Configuration.d.ts +23 -0
  83. package/transpiled/directives/io/lib/throttle/Configuration.js +27 -0
  84. package/transpiled/directives/io/lib/throttle/Configuration.js.map +1 -0
  85. package/transpiled/directives/io/lib/throttle/Interval.d.ts +9 -0
  86. package/transpiled/directives/io/lib/throttle/Interval.js +31 -0
  87. package/transpiled/directives/io/lib/throttle/Interval.js.map +1 -0
  88. package/transpiled/directives/io/lib/throttle/Keys.d.ts +12 -0
  89. package/transpiled/directives/io/lib/throttle/Keys.js +34 -0
  90. package/transpiled/directives/io/lib/throttle/Keys.js.map +1 -0
  91. package/transpiled/directives/io/lib/throttle/Quota.d.ts +8 -0
  92. package/transpiled/directives/io/lib/throttle/Quota.js +22 -0
  93. package/transpiled/directives/io/lib/throttle/Quota.js.map +1 -0
  94. package/transpiled/directives/io/lib/throttle/Quotas.d.ts +26 -0
  95. package/transpiled/directives/io/lib/throttle/Quotas.js +61 -0
  96. package/transpiled/directives/io/lib/throttle/Quotas.js.map +1 -0
  97. package/transpiled/directives/io/lib/throttle/components/Component.d.ts +4 -0
  98. package/transpiled/directives/io/lib/throttle/components/Component.js +3 -0
  99. package/transpiled/directives/io/lib/throttle/components/Component.js.map +1 -0
  100. package/transpiled/directives/io/lib/throttle/components/IP.d.ts +6 -0
  101. package/transpiled/directives/io/lib/throttle/components/IP.js +33 -0
  102. package/transpiled/directives/io/lib/throttle/components/IP.js.map +1 -0
  103. package/transpiled/directives/io/lib/throttle/components/Path.d.ts +5 -0
  104. package/transpiled/directives/io/lib/throttle/components/Path.js +10 -0
  105. package/transpiled/directives/io/lib/throttle/components/Path.js.map +1 -0
  106. package/transpiled/directives/io/lib/throttle/components/index.d.ts +5 -0
  107. package/transpiled/directives/io/lib/throttle/components/index.js +10 -0
  108. package/transpiled/directives/io/lib/throttle/components/index.js.map +1 -0
  109. package/transpiled/directives/io/lib/throttle/conditions/Condition.d.ts +4 -0
  110. package/transpiled/directives/io/lib/throttle/conditions/Condition.js +3 -0
  111. package/transpiled/directives/io/lib/throttle/conditions/Condition.js.map +1 -0
  112. package/transpiled/directives/io/lib/throttle/conditions/Status.d.ts +7 -0
  113. package/transpiled/directives/io/lib/throttle/conditions/Status.js +19 -0
  114. package/transpiled/directives/io/lib/throttle/conditions/Status.js.map +1 -0
  115. package/transpiled/directives/io/lib/throttle/conditions/index.d.ts +5 -0
  116. package/transpiled/directives/io/lib/throttle/conditions/index.js +8 -0
  117. package/transpiled/directives/io/lib/throttle/conditions/index.js.map +1 -0
  118. package/transpiled/directives/io/lib/throttle/index.d.ts +2 -0
  119. package/transpiled/directives/io/lib/throttle/index.js +8 -0
  120. package/transpiled/directives/io/lib/throttle/index.js.map +1 -0
  121. package/transpiled/directives/io/schemas.d.ts +2 -0
  122. package/transpiled/directives/io/schemas.js +2 -1
  123. package/transpiled/directives/io/schemas.js.map +1 -1
  124. package/transpiled/tsconfig.tsbuildinfo +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RequestEntityTooLarge = exports.PreconditionFailed = exports.UnsupportedMediaType = exports.NotAcceptable = exports.MethodNotAllowed = exports.UnprocessableEntity = exports.Conflict = exports.NotFound = exports.Forbidden = exports.Unauthorized = exports.BadRequest = exports.ClientError = exports.Exception = void 0;
3
+ exports.TooManyRequests = exports.UnprocessableEntity = exports.UnsupportedMediaType = exports.RequestEntityTooLarge = exports.PreconditionFailed = exports.Conflict = exports.NotAcceptable = exports.MethodNotAllowed = exports.NotFound = exports.Forbidden = exports.Unauthorized = exports.BadRequest = exports.ClientError = exports.Exception = void 0;
4
4
  class Exception extends Error {
5
5
  status;
6
6
  body;
@@ -38,18 +38,6 @@ class NotFound extends ClientError {
38
38
  }
39
39
  }
40
40
  exports.NotFound = NotFound;
41
- class Conflict extends ClientError {
42
- constructor(body) {
43
- super(409, body);
44
- }
45
- }
46
- exports.Conflict = Conflict;
47
- class UnprocessableEntity extends ClientError {
48
- constructor(body) {
49
- super(422, body);
50
- }
51
- }
52
- exports.UnprocessableEntity = UnprocessableEntity;
53
41
  class MethodNotAllowed extends ClientError {
54
42
  constructor() {
55
43
  super(405);
@@ -62,12 +50,12 @@ class NotAcceptable extends ClientError {
62
50
  }
63
51
  }
64
52
  exports.NotAcceptable = NotAcceptable;
65
- class UnsupportedMediaType extends ClientError {
66
- constructor() {
67
- super(415);
53
+ class Conflict extends ClientError {
54
+ constructor(body) {
55
+ super(409, body);
68
56
  }
69
57
  }
70
- exports.UnsupportedMediaType = UnsupportedMediaType;
58
+ exports.Conflict = Conflict;
71
59
  class PreconditionFailed extends ClientError {
72
60
  constructor() {
73
61
  super(412);
@@ -80,4 +68,22 @@ class RequestEntityTooLarge extends ClientError {
80
68
  }
81
69
  }
82
70
  exports.RequestEntityTooLarge = RequestEntityTooLarge;
71
+ class UnsupportedMediaType extends ClientError {
72
+ constructor() {
73
+ super(415);
74
+ }
75
+ }
76
+ exports.UnsupportedMediaType = UnsupportedMediaType;
77
+ class UnprocessableEntity extends ClientError {
78
+ constructor(body) {
79
+ super(422, body);
80
+ }
81
+ }
82
+ exports.UnprocessableEntity = UnprocessableEntity;
83
+ class TooManyRequests extends ClientError {
84
+ constructor() {
85
+ super(429);
86
+ }
87
+ }
88
+ exports.TooManyRequests = TooManyRequests;
83
89
  //# sourceMappingURL=exceptions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../source/HTTP/exceptions.ts"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CAAA;IAClB,CAAC;CACF;AAJD,4BAIC;AAED,MAAa,gBAAiB,SAAQ,WAAW;IAC/C;QACE,KAAK,CAAC,GAAG,CAAC,CAAA;IACZ,CAAC;CACF;AAJD,4CAIC;AAED,MAAa,aAAc,SAAQ,WAAW;IAC5C;QACE,KAAK,CAAC,GAAG,CAAC,CAAA;IACZ,CAAC;CACF;AAJD,sCAIC;AAED,MAAa,QAAS,SAAQ,WAAW;IACvC,YAAoB,IAAU;QAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAClB,CAAC;CACF;AAJD,4BAIC;AAED,MAAa,kBAAmB,SAAQ,WAAW;IACjD;QACE,KAAK,CAAC,GAAG,CAAC,CAAA;IACZ,CAAC;CACF;AAJD,gDAIC;AAED,MAAa,qBAAsB,SAAQ,WAAW;IACpD,YAAoB,IAAU;QAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAClB,CAAC;CACF;AAJD,sDAIC;AAED,MAAa,oBAAqB,SAAQ,WAAW;IACnD;QACE,KAAK,CAAC,GAAG,CAAC,CAAA;IACZ,CAAC;CACF;AAJD,oDAIC;AAED,MAAa,mBAAoB,SAAQ,WAAW;IAClD,YAAoB,IAAU;QAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAClB,CAAC;CACF;AAJD,kDAIC;AAED,MAAa,eAAgB,SAAQ,WAAW;IAC9C;QACE,KAAK,CAAC,GAAG,CAAC,CAAA;IACZ,CAAC;CACF;AAJD,0CAIC"}
@@ -5,9 +5,11 @@ import type { Output } from '../io';
5
5
  export interface Directives {
6
6
  preflight: (context: Context, parameters: Parameter[]) => Promise<Output>;
7
7
  settle: (context: Context, response: OutgoingMessage) => Promise<void>;
8
+ dispose: () => void;
8
9
  }
9
10
  export interface DirectiveFactory {
10
11
  create: (directives: syntax.Directive[]) => Directives;
12
+ dispose: () => void;
11
13
  }
12
14
  export interface DirectiveSet {
13
15
  family: DirectiveFamily;
@@ -19,4 +21,5 @@ export interface DirectiveFamily<TDirective = any, TExtension = any> {
19
21
  create: (name: string, ...rest: any[]) => TDirective;
20
22
  preflight?: (directives: TDirective[], request: Context & TExtension, parameters: Parameter[]) => Output | Promise<Output>;
21
23
  settle?: (directives: TDirective[], request: Context & TExtension, response: OutgoingMessage) => void | Promise<void>;
24
+ dispose?: (directives: TDirective[]) => void;
22
25
  }
@@ -6,6 +6,7 @@ export declare class Route {
6
6
  readonly variables: number;
7
7
  readonly segments: Segment[];
8
8
  private readonly node;
9
+ private readonly wildcard;
9
10
  constructor(segments: Segment[], node: Node);
10
11
  match(fragments: string[], parameters: Parameter[]): Match | null;
11
12
  equals(route: Route): boolean;
@@ -6,13 +6,16 @@ class Route {
6
6
  variables = 0;
7
7
  segments;
8
8
  node;
9
+ wildcard = false;
9
10
  constructor(segments, node) {
10
11
  this.root = segments.length === 0;
11
12
  this.segments = segments;
12
13
  this.node = node;
13
14
  for (const segment of segments)
14
- if (segment.fragment === null)
15
+ if (segment.fragment === null) {
15
16
  this.variables++;
17
+ this.wildcard ||= segment.wildcard === true;
18
+ }
16
19
  }
17
20
  match(fragments, parameters) {
18
21
  for (let i = 0; i < this.segments.length; i++) {
@@ -21,9 +24,11 @@ class Route {
21
24
  return null;
22
25
  if (segment.fragment === null && segment.placeholder !== null)
23
26
  parameters.push({ name: segment.placeholder, value: fragments[i] });
27
+ if (segment.fragment === null && segment.wildcard === true)
28
+ parameters.push({ name: '**', value: fragments.slice(this.segments.length - 1).join('/') });
24
29
  }
25
30
  const exact = this.segments.length === fragments.length;
26
- if (exact && !this.node.intermediate)
31
+ if ((exact && !this.node.intermediate) || this.wildcard)
27
32
  return { node: this.node, parameters };
28
33
  else
29
34
  return this.matchNested(fragments, parameters);
@@ -1 +1 @@
1
- {"version":3,"file":"Route.js","sourceRoot":"","sources":["../../source/RTD/Route.ts"],"names":[],"mappings":";;;AAIA,MAAa,KAAK;IACA,IAAI,CAAS;IACb,SAAS,GAAW,CAAC,CAAA;IAC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AE,CAAA;;YAEtC,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;IAClD,CAAC;IAEM,MAAM,CAAE,KAAY;QACzB,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,QAAQ,CAAC,MAAM;YAChD,OAAO,KAAK,CAAA;QAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE;YAC3C,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ;gBAC1D,OAAO,KAAK,CAAA;QAEhB,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,KAAK,CAAE,KAAY;QACxB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAEO,WAAW,CAAE,SAAmB,EAAE,UAAuB;QAC/D,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QAEjD,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;IAC/C,CAAC;CACF;AA7DD,sBA6DC"}
@@ -10,5 +10,6 @@ export declare class Tree {
10
10
  constructor(node: syntax.Node, endpoints: EndpointsFactory, directives: DirectiveFactory);
11
11
  match(path: string): Match | null;
12
12
  merge(node: syntax.Node, extension: unknown): void;
13
+ dispose(): void;
13
14
  private createNode;
14
15
  }
@@ -27,6 +27,9 @@ class Tree {
27
27
  const branch = this.createNode(node, !PROTECTED, extension);
28
28
  this.trunk.merge(branch);
29
29
  }
30
+ dispose() {
31
+ this.directives.dispose();
32
+ }
30
33
  createNode(node, protect, extension) {
31
34
  const context = {
32
35
  protected: protect,
@@ -1 +1 @@
1
- {"version":3,"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B,SAAS,EAAE,OAAO;YAClB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,UAAU,EAAE;gBACV,OAAO,EAAE,IAAI,CAAC,UAAU;gBACxB,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE;aACnC;YACD,SAAS;SACV,CAAA;QAED,OAAO,IAAA,oBAAU,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAClC,CAAC;CACF;AAlDD,oBAkDC;AAED,MAAM,SAAS,GAAG,IAAI,CAAA"}
@@ -5,4 +5,5 @@ export type Segment = {
5
5
  } | {
6
6
  fragment: null;
7
7
  placeholder: string | null;
8
+ wildcard?: boolean;
8
9
  };
@@ -19,6 +19,8 @@ function parse(segment) {
19
19
  return { fragment: null, placeholder: segment.substring(1) };
20
20
  else if (segment === '*')
21
21
  return { fragment: null, placeholder: null };
22
+ else if (segment === '**')
23
+ return { fragment: null, placeholder: null, wildcard: true };
22
24
  else
23
25
  return { fragment: segment };
24
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"segment.js","sourceRoot":"","sources":["../../source/RTD/segment.ts"],"names":[],"mappings":";;;AAAA,SAAgB,OAAO,CAAE,IAAY;IACnC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AAClC,CAAC;AAFD,0BAEC;AAED,SAAgB,QAAQ,CAAE,IAAY;IACpC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE7B,iBAAiB;IACjB,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,CAAC,MAAM,EAAE,CAAA;IAElD,gBAAgB;IAChB,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AACxB,CAAC;AARD,4BAQC;AAED,SAAS,KAAK,CAAE,OAAe;IAC7B,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE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OAAO,EAAE,CAAA;AACnC,CAAC"}
@@ -1,6 +1,9 @@
1
- import type { Input } from '../../io';
1
+ import type { Input as Context } from '../../io';
2
+ import type * as http from '../../HTTP';
2
3
  export interface Directive {
3
- attach: (context: Input) => void;
4
+ preflight: (context: Context) => void;
5
+ settle?: (context: Context, response: http.OutgoingMessage) => Promise<void> | void;
6
+ dispose?: () => void;
4
7
  }
5
8
  export interface Constructor {
6
9
  validate: (value: unknown) => void;
@@ -1,9 +1,11 @@
1
+ import type * as http from '../../HTTP';
1
2
  import type { Directive } from './Directive';
2
- import type { Input as Context } from '../../io';
3
3
  import type { DirectiveFamily } from '../../RTD';
4
4
  export declare class IO implements DirectiveFamily<Directive> {
5
5
  readonly name = "io";
6
6
  readonly mandatory = true;
7
7
  create(name: string, value: unknown): Directive;
8
- preflight(directives: Directive[], context: Context): null;
8
+ preflight(directives: Directive[], context: http.Context): null;
9
+ settle(directives: Directive[], context: http.Context, output: http.OutgoingMessage): Promise<void>;
10
+ dispose(directives: Directive[]): void;
9
11
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IO = void 0;
4
4
  const Output_1 = require("./Output");
5
5
  const Input_1 = require("./Input");
6
+ const Throttle_1 = require("./Throttle");
6
7
  class IO {
7
8
  name = 'io';
8
9
  mandatory = true;
@@ -17,17 +18,26 @@ class IO {
17
18
  let restricted = false;
18
19
  for (const directive of directives) {
19
20
  restricted ||= directive instanceof Output_1.Output;
20
- directive.attach(context);
21
+ directive.preflight(context);
21
22
  }
22
23
  if (!restricted)
23
- DENIAL.attach(context);
24
+ DENIAL.preflight(context);
24
25
  return null;
25
26
  }
27
+ async settle(directives, context, output) {
28
+ for (const directive of directives)
29
+ await directive.settle?.(context, output);
30
+ }
31
+ dispose(directives) {
32
+ for (const directive of directives)
33
+ directive.dispose?.();
34
+ }
26
35
  }
27
36
  exports.IO = IO;
28
37
  const constructors = {
38
+ input: Input_1.Input,
29
39
  output: Output_1.Output,
30
- input: Input_1.Input
40
+ throttle: Throttle_1.Throttle
31
41
  };
32
42
  const DENIAL = new Output_1.Output([]);
33
43
  //# sourceMappingURL=IO.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IO.js","sourceRoot":"","sources":["../../../source/directives/io/IO.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,mCAA+B;AAK/B,MAAa,EAAE;IACG,IAAI,GAAG,IAAI,CAAA;IACX,SAAS,GAAG,IAAI,CAAA;IAEzB,MAAM,CAAE,IAAY,EAAE,KAAc;QACzC,IAAI,CAAC,CAAC,IAAI,IAAI,YAAY,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,sBAAsB,CAAC,CAAA;QAE9D,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;QAEpC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAEzB,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IAEM,SAAS,CAAE,UAAuB,EAAE,OAAgB;QACzD,IAAI,UAAU,GAAG,KAAK,CAAA;QAEtB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,UAAU,KAAK,SAAS,YAAY,eAAM,CAAA;YAE1C,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAC3B,CAAC;QAED,IAAI,CAAC,UAAU;YACb,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAExB,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA7BD,gBA6BC;AAED,MAAM,YAAY,GAAgC;IAChD,MAAM,EAAE,eAAM;IACd,KAAK,EAAE,aAAK;CACb,CAAA;AAED,MAAM,MAAM,GAAW,IAAI,eAAM,CAAC,EAAE,CAAC,CAAA"}
1
+ {"version":3,"file":"IO.js","sourceRoot":"","sources":["../../../source/directives/io/IO.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,mCAA+B;AAC/B,yCAAqC;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,7 +4,7 @@ export declare class Input implements Directive {
4
4
  private readonly permissions;
5
5
  constructor(permissions: Permissions);
6
6
  static validate(permissions: unknown): asserts permissions is Permissions;
7
- attach(context: Context): void;
7
+ preflight(context: Context): void;
8
8
  private check;
9
9
  private violation;
10
10
  }
@@ -34,7 +34,7 @@ class Input {
34
34
  static validate(permissions) {
35
35
  schemas.input.validate(permissions, 'Incorrect \'io:input\' format');
36
36
  }
37
- attach(context) {
37
+ preflight(context) {
38
38
  context.pipelines.body.push((body) => this.check(body));
39
39
  }
40
40
  check(body) {
@@ -1 +1 @@
1
- {"version":3,"file":"Input.js","sourceRoot":"","sources":["../../../source/directives/io/Input.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAuC;AACvC,mDAAoC;AAKpC,MAAa,KAAK;IACC,WAAW,CAAa;IAEzC,YAAoB,WAAwB;QAC1C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAE,WAAoB;QAC1C,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAc,WAAW,EAAE,+BAA+B,CAAC,CAAA;IACnF,CAAC;IAEM,MAAM,CAAE,OAAgB;QAC7B,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IACzD,CAAC;IAEO,KAAK,CAAE,IAAa;QAC1B,IAAI,IAAI,KAAK,SAAS;YACpB,OAAO,IAAI,CAAA;QAEb,IAAI,CAAC;YACH,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAsB,IAAI,CAAC,CAAA;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,iBAAU,CAAC,sBAAsB,CAAC,CAAA;QAC9C,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QAErC,IAAI,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O,CAAC,OAAO,CAAC,QAAQ,CAAsB,IAAI,CAAC,CAAA;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,iBAAU,CAAC,sBAAsB,CAAC,CAAA;QAC9C,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QAErC,IAAI,QAAQ,KAAK,SAAS;YACxB,MAAM,IAAI,iBAAU,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAA;QAEvD,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,SAAS,CAAE,KAA0B;QAC3C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACvB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;QAE1E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;YAErC,IAAI,QAAQ,KAAK,SAAS;gBACxB,OAAO,QAAQ,CAAA;QACnB,CAAC;IACH,CAAC;CACF;AA5CD,sBA4CC"}
@@ -6,7 +6,7 @@ export declare class Output implements Directive {
6
6
  private readonly permissions;
7
7
  constructor(permissions: Permissions);
8
8
  static validate(permissions: unknown): asserts permissions is Permissions;
9
- attach(context: Context): void;
9
+ preflight(context: Context): void;
10
10
  private restriction;
11
11
  private fit;
12
12
  }
@@ -43,7 +43,7 @@ class Output {
43
43
  static validate(permissions) {
44
44
  schemas.output.validate(permissions, 'Incorrect \'io:output\' format');
45
45
  }
46
- attach(context) {
46
+ preflight(context) {
47
47
  context.pipelines.response.push(this.restriction(context));
48
48
  }
49
49
  restriction(context) {
@@ -1 +1 @@
1
- {"version":3,"file":"Output.js","sourceRoot":"","sources":["../../../source/directives/io/Output.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CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;gBAC7B,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAiB,CAAC,CAAC,CAAA;;gBAExE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACzC,CAAC,CAAA;IACH,CAAC;IAEO,GAAG,CAAE,OAAgB;QAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;aACpC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;QAEpD,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IACpC,CAAC;CACF;AA3DD,wBA2DC"}
@@ -0,0 +1,11 @@
1
+ import { type Declaration } from './lib/throttle';
2
+ import type * as http from '../../HTTP';
3
+ import type { Directive } from './Directive';
4
+ export declare class Throttle implements Directive {
5
+ private readonly quotas;
6
+ constructor(declaration: Declaration);
7
+ static validate(declaration: unknown): asserts declaration is Declaration;
8
+ preflight(context: http.Context): void;
9
+ settle(context: http.Context, output: http.OutgoingMessage): void;
10
+ dispose(): void;
11
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Throttle = void 0;
27
+ const HTTP_1 = require("../../HTTP");
28
+ const schemas = __importStar(require("./schemas"));
29
+ const throttle_1 = require("./lib/throttle");
30
+ class Throttle {
31
+ quotas;
32
+ constructor(declaration) {
33
+ const configuration = (0, throttle_1.parse)(declaration);
34
+ this.quotas = throttle_1.Quotas.create(configuration);
35
+ }
36
+ static validate(declaration) {
37
+ schemas.throttle.validate(declaration, 'Incorrect \'io:throttle\' format');
38
+ }
39
+ preflight(context) {
40
+ if (!this.quotas.ok(context))
41
+ throw new HTTP_1.TooManyRequests();
42
+ }
43
+ settle(context, output) {
44
+ this.quotas.use(context, output);
45
+ }
46
+ dispose() {
47
+ this.quotas.dispose();
48
+ }
49
+ }
50
+ exports.Throttle = Throttle;
51
+ //# sourceMappingURL=Throttle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Throttle.js","sourceRoot":"","sources":["../../../source/directives/io/Throttle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA4C;AAC5C,mDAAoC;AACpC,6CAAgE;AAIhE,MAAa,QAAQ;IACF,MAAM,CAAQ;IAE/B,YAAoB,WAAwB;QAC1C,MAAM,aAAa,GAAG,IAAA,gBAAK,EAAC,WAAW,CAAC,CAAA;QAExC,IAAI,CAAC,MAAM,GAAG,iBAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAA;IAC5C,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAE,WAAoB;QAC1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,kCAAkC,CAAC,CAAA;IAC5E,CAAC;IAEM,SAAS,CAAE,OAAqB;QACrC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC;YAC1B,MAAM,IAAI,sBAAe,EAAE,CAAA;IAC/B,CAAC;IAEM,MAAM,CAAE,OAAqB,EAAE,MAA4B;QAChE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAClC,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAA;IACvB,CAAC;CACF;AAzBD,4BAyBC"}
@@ -0,0 +1,23 @@
1
+ export interface Configuration {
2
+ key: KeyComponent[];
3
+ condition?: KeyCondition[];
4
+ requests: number;
5
+ interval: number;
6
+ cooldown: number;
7
+ }
8
+ interface Rule<T, K = unknown> {
9
+ method: T;
10
+ options?: K;
11
+ }
12
+ export type KeyComponentMethod = 'ip' | 'path';
13
+ export type KeyConditionMethod = 'status';
14
+ export type KeyComponent = Rule<KeyComponentMethod>;
15
+ export type KeyCondition = Rule<KeyConditionMethod>;
16
+ type KeyDeclaration = KeyComponentMethod | KeyComponentMethod[];
17
+ type ConditionDeclaration = Record<KeyConditionMethod, unknown> | Array<Record<KeyConditionMethod, unknown>>;
18
+ export interface Declaration extends Omit<Configuration, 'key' | 'condition'> {
19
+ key: KeyDeclaration;
20
+ condition?: ConditionDeclaration;
21
+ }
22
+ export declare function parse(declaration: Declaration): Configuration;
23
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parse = void 0;
4
+ function parse(declaration) {
5
+ const { key, condition, requests, interval, cooldown } = declaration;
6
+ return {
7
+ key: mapKey(key),
8
+ condition: mapCondition(condition),
9
+ requests,
10
+ interval: interval * 1000,
11
+ cooldown: cooldown * 1000
12
+ };
13
+ }
14
+ exports.parse = parse;
15
+ function mapKey(declaration) {
16
+ const methods = Array.isArray(declaration) ? declaration : [declaration];
17
+ return methods.map((method) => ({ method }));
18
+ }
19
+ function mapCondition(declaration) {
20
+ if (declaration === undefined)
21
+ return;
22
+ // reduce to a single object, then map entries to rules
23
+ const conditions = Array.isArray(declaration) ? declaration : [declaration];
24
+ const single = conditions.reduce((acc, condition) => ({ ...acc, ...condition }), {});
25
+ return Object.entries(single).map(([method, options]) => ({ method, options }));
26
+ }
27
+ //# sourceMappingURL=Configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../../../source/directives/io/lib/throttle/Configuration.ts"],"names":[],"mappings":";;;AA8BA,SAAgB,KAAK,CAAE,WAAwB;IAC7C,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAA;IAEpE,OAAO;QACL,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC;QAChB,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC;QAClC,QAAQ;QACR,QAAQ,EAAE,QAAQ,GAAG,IAAI;QACzB,QAAQ,EAAE,QAAQ,GAAG,IAAI;KAC1B,CAAA;AACH,CAAC;AAVD,sBAUC;AAED,SAAS,MAAM,CAAE,WAA2B;IAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;IAExE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;AAC9C,CAAC;AAED,SAAS,YAAY,CAAE,WAAkC;IACvD,IAAI,WAAW,KAAK,SAAS;QAC3B,OAAM;IAER,uDAAuD;IACvD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;IAC3E,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;IAEpF,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAmB,CAAA;AACnG,CAAC"}
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'node:events';
3
+ export declare class Interval extends EventEmitter {
4
+ number: number;
5
+ private interval;
6
+ constructor(interval: number);
7
+ start(interval: number): void;
8
+ dispose(): void;
9
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Interval = void 0;
7
+ const node_assert_1 = __importDefault(require("node:assert"));
8
+ const node_events_1 = require("node:events");
9
+ class Interval extends node_events_1.EventEmitter {
10
+ number = 0;
11
+ interval = null;
12
+ constructor(interval) {
13
+ super();
14
+ const number = Math.ceil(Date.now() / interval);
15
+ const shift = number * interval - Date.now();
16
+ node_assert_1.default.ok(shift >= 0, 'shift must be positive');
17
+ setTimeout(() => this.start(interval), shift);
18
+ }
19
+ start(interval) {
20
+ this.interval = setInterval(() => this.emit('tick'), interval);
21
+ }
22
+ dispose() {
23
+ if (this.interval !== null) {
24
+ clearInterval(this.interval);
25
+ this.interval = null;
26
+ }
27
+ this.removeAllListeners();
28
+ }
29
+ }
30
+ exports.Interval = Interval;
31
+ //# sourceMappingURL=Interval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Interval.js","sourceRoot":"","sources":["../../../../../source/directives/io/lib/throttle/Interval.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAgC;AAChC,6CAA0C;AAE1C,MAAa,QAAS,SAAQ,0BAAY;IACjC,MAAM,GAAW,CAAC,CAAA;IACjB,QAAQ,GAA0C,IAAI,CAAA;IAE9D,YAAoB,QAAgB;QAClC,KAAK,EAAE,CAAA;QAEP,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAA;QAC/C,MAAM,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAE5C,qBAAM,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,EAAE,wBAAwB,CAAC,CAAA;QAE/C,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAA;IAC/C,CAAC;IAEM,KAAK,CAAE,QAAgB;QAC5B,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAA;IAChE,CAAC;IAEM,OAAO;QACZ,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACtB,CAAC;QAED,IAAI,CAAC,kBAAkB,EAAE,CAAA;IAC3B,CAAC;CACF;AA3BD,4BA2BC"}
@@ -0,0 +1,12 @@
1
+ import { type Component } from './components';
2
+ import { type Condition } from './conditions';
3
+ import type { KeyComponent, KeyCondition } from './Configuration';
4
+ import type { Input as Context, Output } from '../../../../io';
5
+ export declare class Keys {
6
+ private readonly components;
7
+ private readonly conditions?;
8
+ constructor(components: Component[], conditions?: Condition[]);
9
+ static create(componentRules: KeyComponent[], conditionRules?: KeyCondition[]): Keys;
10
+ get(context: Context): string;
11
+ match(input: Context, output: Output): string | null;
12
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Keys = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const components_1 = require("./components");
6
+ const conditions_1 = require("./conditions");
7
+ class Keys {
8
+ components;
9
+ conditions;
10
+ constructor(components, conditions) {
11
+ this.components = components;
12
+ this.conditions = conditions;
13
+ }
14
+ static create(componentRules, conditionRules) {
15
+ const components = componentRules.map((rule) => new components_1.Components[rule.method](rule.options));
16
+ const conditions = conditionRules?.map((rule) => new conditions_1.Conditions[rule.method](rule.options));
17
+ return new this(components, conditions);
18
+ }
19
+ get(context) {
20
+ const hash = (0, node_crypto_1.createHash)('sha256');
21
+ for (const component of this.components)
22
+ hash.update(component.get(context));
23
+ return hash.digest('hex');
24
+ }
25
+ match(input, output) {
26
+ const miss = this.conditions?.some((condition) => !condition.match(input, output));
27
+ if (miss === true)
28
+ return null;
29
+ else
30
+ return this.get(input);
31
+ }
32
+ }
33
+ exports.Keys = Keys;
34
+ //# sourceMappingURL=Keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Keys.js","sourceRoot":"","sources":["../../../../../source/directives/io/lib/throttle/Keys.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,6CAAyD;AACzD,6CAAyD;AAIzD,MAAa,IAAI;IACE,UAAU,CAAa;IACvB,UAAU,CAAc;IAEzC,YAAoB,UAAuB,EAAE,UAAwB;QACnE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAEM,MAAM,CAAC,MAAM,CAAE,cAA8B,EAAE,cAA+B;QACnF,MAAM,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,uBAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAC1F,MAAM,UAAU,GAAG,cAAc,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,uBAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAE3F,OAAO,IAAI,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;IACzC,CAAC;IAEM,GAAG,CAAE,OAAgB;QAC1B,MAAM,IAAI,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAA;QAEjC,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU;YACrC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;QAErC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;IAEM,KAAK,CAAE,KAAc,EAAE,MAAc;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;QAElF,IAAI,IAAI,KAAK,IAAI;YACf,OAAO,IAAI,CAAA;;YAEX,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;CACF;AAjCD,oBAiCC"}
@@ -0,0 +1,8 @@
1
+ export declare class Quota {
2
+ private readonly limit;
3
+ private used;
4
+ constructor(limit: number);
5
+ get idle(): boolean;
6
+ use(count?: number): boolean;
7
+ reset(): void;
8
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Quota = void 0;
4
+ class Quota {
5
+ limit = 0;
6
+ used = 0;
7
+ constructor(limit) {
8
+ this.limit = limit;
9
+ }
10
+ get idle() {
11
+ return this.used === 0;
12
+ }
13
+ use(count = 1) {
14
+ this.used += count;
15
+ return this.used < this.limit;
16
+ }
17
+ reset() {
18
+ this.used = 0;
19
+ }
20
+ }
21
+ exports.Quota = Quota;
22
+ //# sourceMappingURL=Quota.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Quota.js","sourceRoot":"","sources":["../../../../../source/directives/io/lib/throttle/Quota.ts"],"names":[],"mappings":";;;AAAA,MAAa,KAAK;IACC,KAAK,GAAW,CAAC,CAAA;IAC1B,IAAI,GAAW,CAAC,CAAA;IAExB,YAAoB,KAAa;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,IAAI,KAAK,CAAC,CAAA;IACxB,CAAC;IAEM,GAAG,CAAE,KAAK,GAAG,CAAC;QACnB,IAAI,CAAC,IAAI,IAAI,KAAK,CAAA;QAElB,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;IAC/B,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,IAAI,GAAG,CAAC,CAAA;IACf,CAAC;CACF;AArBD,sBAqBC"}
@@ -0,0 +1,26 @@
1
+ import { Keys } from './Keys';
2
+ import { Interval } from './Interval';
3
+ import type { Configuration } from './Configuration';
4
+ import type { Input as Context, Output } from '../../../../io';
5
+ export declare class Quotas {
6
+ private readonly requests;
7
+ private readonly cooldown;
8
+ private readonly interval;
9
+ private readonly keys;
10
+ private readonly quotas;
11
+ private readonly blocked;
12
+ constructor(options: Options);
13
+ static create(configuration: Configuration): Quotas;
14
+ ok(context: Context): boolean;
15
+ use(input: Context, output: Output): void;
16
+ dispose(): void;
17
+ private readonly reset;
18
+ private block;
19
+ }
20
+ interface Options {
21
+ keys: Keys;
22
+ requests: number;
23
+ cooldown: number;
24
+ interval: Interval;
25
+ }
26
+ export {};