@shware/http 2.0.1 → 2.2.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.
Files changed (69) hide show
  1. package/dist/error/parse.cjs +13 -1
  2. package/dist/error/parse.cjs.map +1 -1
  3. package/dist/error/parse.mjs +11 -1
  4. package/dist/error/parse.mjs.map +1 -1
  5. package/dist/hono/geolocation.cjs +30 -30
  6. package/dist/hono/geolocation.cjs.map +1 -1
  7. package/dist/hono/geolocation.d.cts +10 -10
  8. package/dist/hono/geolocation.d.ts +10 -10
  9. package/dist/hono/geolocation.mjs +30 -30
  10. package/dist/hono/geolocation.mjs.map +1 -1
  11. package/dist/index.cjs +0 -18
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +0 -6
  14. package/dist/index.d.ts +0 -6
  15. package/dist/index.mjs +0 -12
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/response.cjs +13 -1
  18. package/dist/response.cjs.map +1 -1
  19. package/dist/response.mjs +11 -1
  20. package/dist/response.mjs.map +1 -1
  21. package/package.json +3 -2
  22. package/dist/utils/__tests__/base62.test.cjs +0 -29
  23. package/dist/utils/__tests__/base62.test.cjs.map +0 -1
  24. package/dist/utils/__tests__/base62.test.d.cts +0 -2
  25. package/dist/utils/__tests__/base62.test.d.ts +0 -2
  26. package/dist/utils/__tests__/base62.test.mjs +0 -27
  27. package/dist/utils/__tests__/base62.test.mjs.map +0 -1
  28. package/dist/utils/__tests__/ip.test.cjs +0 -38
  29. package/dist/utils/__tests__/ip.test.cjs.map +0 -1
  30. package/dist/utils/__tests__/ip.test.d.cts +0 -2
  31. package/dist/utils/__tests__/ip.test.d.ts +0 -2
  32. package/dist/utils/__tests__/ip.test.mjs +0 -36
  33. package/dist/utils/__tests__/ip.test.mjs.map +0 -1
  34. package/dist/utils/base62.cjs +0 -85
  35. package/dist/utils/base62.cjs.map +0 -1
  36. package/dist/utils/base62.d.cts +0 -6
  37. package/dist/utils/base62.d.ts +0 -6
  38. package/dist/utils/base62.mjs +0 -60
  39. package/dist/utils/base62.mjs.map +0 -1
  40. package/dist/utils/fetch.cjs +0 -78
  41. package/dist/utils/fetch.cjs.map +0 -1
  42. package/dist/utils/fetch.d.cts +0 -16
  43. package/dist/utils/fetch.d.ts +0 -16
  44. package/dist/utils/fetch.mjs +0 -53
  45. package/dist/utils/fetch.mjs.map +0 -1
  46. package/dist/utils/invariant.cjs +0 -37
  47. package/dist/utils/invariant.cjs.map +0 -1
  48. package/dist/utils/invariant.d.cts +0 -3
  49. package/dist/utils/invariant.d.ts +0 -3
  50. package/dist/utils/invariant.mjs +0 -12
  51. package/dist/utils/invariant.mjs.map +0 -1
  52. package/dist/utils/promise.cjs +0 -47
  53. package/dist/utils/promise.cjs.map +0 -1
  54. package/dist/utils/promise.d.cts +0 -3
  55. package/dist/utils/promise.d.ts +0 -3
  56. package/dist/utils/promise.mjs +0 -22
  57. package/dist/utils/promise.mjs.map +0 -1
  58. package/dist/utils/string.cjs +0 -33
  59. package/dist/utils/string.cjs.map +0 -1
  60. package/dist/utils/string.d.cts +0 -6
  61. package/dist/utils/string.d.ts +0 -6
  62. package/dist/utils/string.mjs +0 -8
  63. package/dist/utils/string.mjs.map +0 -1
  64. package/dist/utils/token-bucket.cjs +0 -73
  65. package/dist/utils/token-bucket.cjs.map +0 -1
  66. package/dist/utils/token-bucket.d.cts +0 -20
  67. package/dist/utils/token-bucket.d.ts +0 -20
  68. package/dist/utils/token-bucket.mjs +0 -48
  69. package/dist/utils/token-bucket.mjs.map +0 -1
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/utils/promise.ts
21
- var promise_exports = {};
22
- __export(promise_exports, {
23
- once: () => once
24
- });
25
- module.exports = __toCommonJS(promise_exports);
26
- function once(fn) {
27
- let cache = null;
28
- let promise = null;
29
- return async (...args) => {
30
- if (cache !== null) return cache;
31
- if (!promise) {
32
- promise = fn(...args).then((result) => {
33
- cache = result;
34
- return result;
35
- }).catch((error) => {
36
- promise = null;
37
- throw error;
38
- });
39
- }
40
- return promise;
41
- };
42
- }
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- once
46
- });
47
- //# sourceMappingURL=promise.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/promise.ts"],"sourcesContent":["export function once<A extends unknown[], T>(fn: (...args: A) => Promise<T>) {\n let cache: T | null = null;\n let promise: Promise<T> | null = null;\n\n return async (...args: A) => {\n if (cache !== null) return cache;\n if (!promise) {\n promise = fn(...args)\n .then((result) => {\n cache = result;\n return result;\n })\n .catch((error) => {\n promise = null;\n throw error;\n });\n }\n\n return promise;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,KAA6B,IAAgC;AAC3E,MAAI,QAAkB;AACtB,MAAI,UAA6B;AAEjC,SAAO,UAAU,SAAY;AAC3B,QAAI,UAAU,KAAM,QAAO;AAC3B,QAAI,CAAC,SAAS;AACZ,gBAAU,GAAG,GAAG,IAAI,EACjB,KAAK,CAAC,WAAW;AAChB,gBAAQ;AACR,eAAO;AAAA,MACT,CAAC,EACA,MAAM,CAAC,UAAU;AAChB,kBAAU;AACV,cAAM;AAAA,MACR,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,3 +0,0 @@
1
- declare function once<A extends unknown[], T>(fn: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
2
-
3
- export { once };
@@ -1,3 +0,0 @@
1
- declare function once<A extends unknown[], T>(fn: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
2
-
3
- export { once };
@@ -1,22 +0,0 @@
1
- // src/utils/promise.ts
2
- function once(fn) {
3
- let cache = null;
4
- let promise = null;
5
- return async (...args) => {
6
- if (cache !== null) return cache;
7
- if (!promise) {
8
- promise = fn(...args).then((result) => {
9
- cache = result;
10
- return result;
11
- }).catch((error) => {
12
- promise = null;
13
- throw error;
14
- });
15
- }
16
- return promise;
17
- };
18
- }
19
- export {
20
- once
21
- };
22
- //# sourceMappingURL=promise.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/promise.ts"],"sourcesContent":["export function once<A extends unknown[], T>(fn: (...args: A) => Promise<T>) {\n let cache: T | null = null;\n let promise: Promise<T> | null = null;\n\n return async (...args: A) => {\n if (cache !== null) return cache;\n if (!promise) {\n promise = fn(...args)\n .then((result) => {\n cache = result;\n return result;\n })\n .catch((error) => {\n promise = null;\n throw error;\n });\n }\n\n return promise;\n };\n}\n"],"mappings":";AAAO,SAAS,KAA6B,IAAgC;AAC3E,MAAI,QAAkB;AACtB,MAAI,UAA6B;AAEjC,SAAO,UAAU,SAAY;AAC3B,QAAI,UAAU,KAAM,QAAO;AAC3B,QAAI,CAAC,SAAS;AACZ,gBAAU,GAAG,GAAG,IAAI,EACjB,KAAK,CAAC,WAAW;AAChB,gBAAQ;AACR,eAAO;AAAA,MACT,CAAC,EACA,MAAM,CAAC,UAAU;AAChB,kBAAU;AACV,cAAM;AAAA,MACR,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/utils/string.ts
21
- var string_exports = {};
22
- __export(string_exports, {
23
- hasText: () => hasText
24
- });
25
- module.exports = __toCommonJS(string_exports);
26
- function hasText(str) {
27
- return typeof str === "string" && str.trim().length !== 0;
28
- }
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- hasText
32
- });
33
- //# sourceMappingURL=string.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/string.ts"],"sourcesContent":["/**\n * Check whether the given String contains actual text.\n * */\nexport function hasText(str: string | null | undefined): str is string {\n return typeof str === 'string' && str.trim().length !== 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,QAAQ,KAA+C;AACrE,SAAO,OAAO,QAAQ,YAAY,IAAI,KAAK,EAAE,WAAW;AAC1D;","names":[]}
@@ -1,6 +0,0 @@
1
- /**
2
- * Check whether the given String contains actual text.
3
- * */
4
- declare function hasText(str: string | null | undefined): str is string;
5
-
6
- export { hasText };
@@ -1,6 +0,0 @@
1
- /**
2
- * Check whether the given String contains actual text.
3
- * */
4
- declare function hasText(str: string | null | undefined): str is string;
5
-
6
- export { hasText };
@@ -1,8 +0,0 @@
1
- // src/utils/string.ts
2
- function hasText(str) {
3
- return typeof str === "string" && str.trim().length !== 0;
4
- }
5
- export {
6
- hasText
7
- };
8
- //# sourceMappingURL=string.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/string.ts"],"sourcesContent":["/**\n * Check whether the given String contains actual text.\n * */\nexport function hasText(str: string | null | undefined): str is string {\n return typeof str === 'string' && str.trim().length !== 0;\n}\n"],"mappings":";AAGO,SAAS,QAAQ,KAA+C;AACrE,SAAO,OAAO,QAAQ,YAAY,IAAI,KAAK,EAAE,WAAW;AAC1D;","names":[]}
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/utils/token-bucket.ts
21
- var token_bucket_exports = {};
22
- __export(token_bucket_exports, {
23
- TokenBucket: () => TokenBucket
24
- });
25
- module.exports = __toCommonJS(token_bucket_exports);
26
- var INTERVAL_MAP = {
27
- second: 1e3,
28
- minute: 60 * 1e3,
29
- hour: 60 * 60 * 1e3,
30
- day: 24 * 60 * 60 * 1e3
31
- };
32
- var TokenBucket = class {
33
- rate;
34
- capacity;
35
- requested;
36
- timer;
37
- tokens;
38
- constructor({ rate, capacity, requested, interval = "second" }) {
39
- if (rate <= 0) throw new Error("rate must be greater than 0");
40
- if (capacity <= 0) throw new Error("capacity must be greater than 0");
41
- if (requested <= 0) throw new Error("requested must be greater than 0");
42
- if (requested > capacity) throw new Error("requested must be less than or equal to capacity");
43
- this.rate = rate;
44
- this.capacity = capacity;
45
- this.requested = requested;
46
- this.tokens = capacity;
47
- this.timer = setInterval(() => {
48
- if (this.tokens < this.capacity) {
49
- const tokens = this.tokens + this.rate;
50
- this.tokens = Math.min(tokens, this.capacity);
51
- }
52
- }, INTERVAL_MAP[interval]);
53
- }
54
- wait(ms) {
55
- return new Promise((resolve) => setTimeout(resolve, ms));
56
- }
57
- async removeTokens() {
58
- while (this.tokens < this.requested) {
59
- const ms = Math.ceil(1e3 * (this.requested - this.tokens) / this.rate);
60
- await this.wait(ms);
61
- }
62
- this.tokens -= this.requested;
63
- return this.tokens;
64
- }
65
- destroy() {
66
- clearInterval(this.timer);
67
- }
68
- };
69
- // Annotate the CommonJS export names for ESM import in node:
70
- 0 && (module.exports = {
71
- TokenBucket
72
- });
73
- //# sourceMappingURL=token-bucket.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/token-bucket.ts"],"sourcesContent":["type Interval = 'second' | 'minute' | 'hour' | 'day';\n\nconst INTERVAL_MAP: Record<Interval, number> = {\n second: 1000,\n minute: 60 * 1000,\n hour: 60 * 60 * 1000,\n day: 24 * 60 * 60 * 1000,\n};\n\nexport interface TokenBucketOptions {\n rate: number;\n capacity: number;\n requested: number;\n interval?: Interval;\n}\n\nexport class TokenBucket {\n readonly rate: number;\n readonly capacity: number;\n readonly requested: number;\n private readonly timer: number | NodeJS.Timeout;\n private tokens: number;\n\n constructor({ rate, capacity, requested, interval = 'second' }: TokenBucketOptions) {\n if (rate <= 0) throw new Error('rate must be greater than 0');\n if (capacity <= 0) throw new Error('capacity must be greater than 0');\n if (requested <= 0) throw new Error('requested must be greater than 0');\n if (requested > capacity) throw new Error('requested must be less than or equal to capacity');\n\n this.rate = rate;\n this.capacity = capacity;\n this.requested = requested;\n this.tokens = capacity;\n this.timer = setInterval(() => {\n if (this.tokens < this.capacity) {\n const tokens = this.tokens + this.rate;\n this.tokens = Math.min(tokens, this.capacity);\n }\n }, INTERVAL_MAP[interval]);\n }\n\n private wait(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n async removeTokens(): Promise<number> {\n while (this.tokens < this.requested) {\n const ms = Math.ceil((1000 * (this.requested - this.tokens)) / this.rate);\n await this.wait(ms);\n }\n this.tokens -= this.requested;\n return this.tokens;\n }\n\n destroy() {\n clearInterval(this.timer);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAM,eAAyC;AAAA,EAC7C,QAAQ;AAAA,EACR,QAAQ,KAAK;AAAA,EACb,MAAM,KAAK,KAAK;AAAA,EAChB,KAAK,KAAK,KAAK,KAAK;AACtB;AASO,IAAM,cAAN,MAAkB;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACQ;AAAA,EACT;AAAA,EAER,YAAY,EAAE,MAAM,UAAU,WAAW,WAAW,SAAS,GAAuB;AAClF,QAAI,QAAQ,EAAG,OAAM,IAAI,MAAM,6BAA6B;AAC5D,QAAI,YAAY,EAAG,OAAM,IAAI,MAAM,iCAAiC;AACpE,QAAI,aAAa,EAAG,OAAM,IAAI,MAAM,kCAAkC;AACtE,QAAI,YAAY,SAAU,OAAM,IAAI,MAAM,kDAAkD;AAE5F,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,YAAY;AACjB,SAAK,SAAS;AACd,SAAK,QAAQ,YAAY,MAAM;AAC7B,UAAI,KAAK,SAAS,KAAK,UAAU;AAC/B,cAAM,SAAS,KAAK,SAAS,KAAK;AAClC,aAAK,SAAS,KAAK,IAAI,QAAQ,KAAK,QAAQ;AAAA,MAC9C;AAAA,IACF,GAAG,aAAa,QAAQ,CAAC;AAAA,EAC3B;AAAA,EAEQ,KAAK,IAA2B;AACtC,WAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAAA,EACzD;AAAA,EAEA,MAAM,eAAgC;AACpC,WAAO,KAAK,SAAS,KAAK,WAAW;AACnC,YAAM,KAAK,KAAK,KAAM,OAAQ,KAAK,YAAY,KAAK,UAAW,KAAK,IAAI;AACxE,YAAM,KAAK,KAAK,EAAE;AAAA,IACpB;AACA,SAAK,UAAU,KAAK;AACpB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,UAAU;AACR,kBAAc,KAAK,KAAK;AAAA,EAC1B;AACF;","names":[]}
@@ -1,20 +0,0 @@
1
- type Interval = 'second' | 'minute' | 'hour' | 'day';
2
- interface TokenBucketOptions {
3
- rate: number;
4
- capacity: number;
5
- requested: number;
6
- interval?: Interval;
7
- }
8
- declare class TokenBucket {
9
- readonly rate: number;
10
- readonly capacity: number;
11
- readonly requested: number;
12
- private readonly timer;
13
- private tokens;
14
- constructor({ rate, capacity, requested, interval }: TokenBucketOptions);
15
- private wait;
16
- removeTokens(): Promise<number>;
17
- destroy(): void;
18
- }
19
-
20
- export { TokenBucket, type TokenBucketOptions };
@@ -1,20 +0,0 @@
1
- type Interval = 'second' | 'minute' | 'hour' | 'day';
2
- interface TokenBucketOptions {
3
- rate: number;
4
- capacity: number;
5
- requested: number;
6
- interval?: Interval;
7
- }
8
- declare class TokenBucket {
9
- readonly rate: number;
10
- readonly capacity: number;
11
- readonly requested: number;
12
- private readonly timer;
13
- private tokens;
14
- constructor({ rate, capacity, requested, interval }: TokenBucketOptions);
15
- private wait;
16
- removeTokens(): Promise<number>;
17
- destroy(): void;
18
- }
19
-
20
- export { TokenBucket, type TokenBucketOptions };
@@ -1,48 +0,0 @@
1
- // src/utils/token-bucket.ts
2
- var INTERVAL_MAP = {
3
- second: 1e3,
4
- minute: 60 * 1e3,
5
- hour: 60 * 60 * 1e3,
6
- day: 24 * 60 * 60 * 1e3
7
- };
8
- var TokenBucket = class {
9
- rate;
10
- capacity;
11
- requested;
12
- timer;
13
- tokens;
14
- constructor({ rate, capacity, requested, interval = "second" }) {
15
- if (rate <= 0) throw new Error("rate must be greater than 0");
16
- if (capacity <= 0) throw new Error("capacity must be greater than 0");
17
- if (requested <= 0) throw new Error("requested must be greater than 0");
18
- if (requested > capacity) throw new Error("requested must be less than or equal to capacity");
19
- this.rate = rate;
20
- this.capacity = capacity;
21
- this.requested = requested;
22
- this.tokens = capacity;
23
- this.timer = setInterval(() => {
24
- if (this.tokens < this.capacity) {
25
- const tokens = this.tokens + this.rate;
26
- this.tokens = Math.min(tokens, this.capacity);
27
- }
28
- }, INTERVAL_MAP[interval]);
29
- }
30
- wait(ms) {
31
- return new Promise((resolve) => setTimeout(resolve, ms));
32
- }
33
- async removeTokens() {
34
- while (this.tokens < this.requested) {
35
- const ms = Math.ceil(1e3 * (this.requested - this.tokens) / this.rate);
36
- await this.wait(ms);
37
- }
38
- this.tokens -= this.requested;
39
- return this.tokens;
40
- }
41
- destroy() {
42
- clearInterval(this.timer);
43
- }
44
- };
45
- export {
46
- TokenBucket
47
- };
48
- //# sourceMappingURL=token-bucket.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/token-bucket.ts"],"sourcesContent":["type Interval = 'second' | 'minute' | 'hour' | 'day';\n\nconst INTERVAL_MAP: Record<Interval, number> = {\n second: 1000,\n minute: 60 * 1000,\n hour: 60 * 60 * 1000,\n day: 24 * 60 * 60 * 1000,\n};\n\nexport interface TokenBucketOptions {\n rate: number;\n capacity: number;\n requested: number;\n interval?: Interval;\n}\n\nexport class TokenBucket {\n readonly rate: number;\n readonly capacity: number;\n readonly requested: number;\n private readonly timer: number | NodeJS.Timeout;\n private tokens: number;\n\n constructor({ rate, capacity, requested, interval = 'second' }: TokenBucketOptions) {\n if (rate <= 0) throw new Error('rate must be greater than 0');\n if (capacity <= 0) throw new Error('capacity must be greater than 0');\n if (requested <= 0) throw new Error('requested must be greater than 0');\n if (requested > capacity) throw new Error('requested must be less than or equal to capacity');\n\n this.rate = rate;\n this.capacity = capacity;\n this.requested = requested;\n this.tokens = capacity;\n this.timer = setInterval(() => {\n if (this.tokens < this.capacity) {\n const tokens = this.tokens + this.rate;\n this.tokens = Math.min(tokens, this.capacity);\n }\n }, INTERVAL_MAP[interval]);\n }\n\n private wait(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n async removeTokens(): Promise<number> {\n while (this.tokens < this.requested) {\n const ms = Math.ceil((1000 * (this.requested - this.tokens)) / this.rate);\n await this.wait(ms);\n }\n this.tokens -= this.requested;\n return this.tokens;\n }\n\n destroy() {\n clearInterval(this.timer);\n }\n}\n"],"mappings":";AAEA,IAAM,eAAyC;AAAA,EAC7C,QAAQ;AAAA,EACR,QAAQ,KAAK;AAAA,EACb,MAAM,KAAK,KAAK;AAAA,EAChB,KAAK,KAAK,KAAK,KAAK;AACtB;AASO,IAAM,cAAN,MAAkB;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACQ;AAAA,EACT;AAAA,EAER,YAAY,EAAE,MAAM,UAAU,WAAW,WAAW,SAAS,GAAuB;AAClF,QAAI,QAAQ,EAAG,OAAM,IAAI,MAAM,6BAA6B;AAC5D,QAAI,YAAY,EAAG,OAAM,IAAI,MAAM,iCAAiC;AACpE,QAAI,aAAa,EAAG,OAAM,IAAI,MAAM,kCAAkC;AACtE,QAAI,YAAY,SAAU,OAAM,IAAI,MAAM,kDAAkD;AAE5F,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,YAAY;AACjB,SAAK,SAAS;AACd,SAAK,QAAQ,YAAY,MAAM;AAC7B,UAAI,KAAK,SAAS,KAAK,UAAU;AAC/B,cAAM,SAAS,KAAK,SAAS,KAAK;AAClC,aAAK,SAAS,KAAK,IAAI,QAAQ,KAAK,QAAQ;AAAA,MAC9C;AAAA,IACF,GAAG,aAAa,QAAQ,CAAC;AAAA,EAC3B;AAAA,EAEQ,KAAK,IAA2B;AACtC,WAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAAA,EACzD;AAAA,EAEA,MAAM,eAAgC;AACpC,WAAO,KAAK,SAAS,KAAK,WAAW;AACnC,YAAM,KAAK,KAAK,KAAM,OAAQ,KAAK,YAAY,KAAK,UAAW,KAAK,IAAI;AACxE,YAAM,KAAK,KAAK,EAAE;AAAA,IACpB;AACA,SAAK,UAAU,KAAK;AACpB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,UAAU;AACR,kBAAc,KAAK,KAAK;AAAA,EAC1B;AACF;","names":[]}