hyperttp 0.1.5

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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -0
  3. package/dist/Hyperttp/Core/CacheManager.d.ts +65 -0
  4. package/dist/Hyperttp/Core/CacheManager.d.ts.map +1 -0
  5. package/dist/Hyperttp/Core/CacheManager.js +80 -0
  6. package/dist/Hyperttp/Core/CacheManager.js.map +1 -0
  7. package/dist/Hyperttp/Core/HttpClientImproved.d.ts +280 -0
  8. package/dist/Hyperttp/Core/HttpClientImproved.d.ts.map +1 -0
  9. package/dist/Hyperttp/Core/HttpClientImproved.js +611 -0
  10. package/dist/Hyperttp/Core/HttpClientImproved.js.map +1 -0
  11. package/dist/Hyperttp/Core/QueueManager.d.ts +49 -0
  12. package/dist/Hyperttp/Core/QueueManager.d.ts.map +1 -0
  13. package/dist/Hyperttp/Core/QueueManager.js +75 -0
  14. package/dist/Hyperttp/Core/QueueManager.js.map +1 -0
  15. package/dist/Hyperttp/Core/RateLimiter.d.ts +53 -0
  16. package/dist/Hyperttp/Core/RateLimiter.d.ts.map +1 -0
  17. package/dist/Hyperttp/Core/RateLimiter.js +70 -0
  18. package/dist/Hyperttp/Core/RateLimiter.js.map +1 -0
  19. package/dist/Hyperttp/Core/index.d.ts +22 -0
  20. package/dist/Hyperttp/Core/index.d.ts.map +1 -0
  21. package/dist/Hyperttp/Core/index.js +29 -0
  22. package/dist/Hyperttp/Core/index.js.map +1 -0
  23. package/dist/Hyperttp/Request.d.ts +78 -0
  24. package/dist/Hyperttp/Request.d.ts.map +1 -0
  25. package/dist/Hyperttp/Request.js +234 -0
  26. package/dist/Hyperttp/Request.js.map +1 -0
  27. package/dist/Hyperttp/UrlExtractor.d.ts +87 -0
  28. package/dist/Hyperttp/UrlExtractor.d.ts.map +1 -0
  29. package/dist/Hyperttp/UrlExtractor.js +127 -0
  30. package/dist/Hyperttp/UrlExtractor.js.map +1 -0
  31. package/dist/Hyperttp/index.d.ts +5 -0
  32. package/dist/Hyperttp/index.d.ts.map +1 -0
  33. package/dist/Hyperttp/index.js +18 -0
  34. package/dist/Hyperttp/index.js.map +1 -0
  35. package/dist/Types/index.d.ts +32 -0
  36. package/dist/Types/index.d.ts.map +1 -0
  37. package/dist/Types/index.js +18 -0
  38. package/dist/Types/index.js.map +1 -0
  39. package/dist/Types/request.d.ts +136 -0
  40. package/dist/Types/request.d.ts.map +1 -0
  41. package/dist/Types/request.js +3 -0
  42. package/dist/Types/request.js.map +1 -0
  43. package/dist/index.d.ts +3 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +12 -0
  46. package/dist/index.js.map +1 -0
  47. package/package.json +32 -0
@@ -0,0 +1,87 @@
1
+ import { UrlExtractorInterface, UrlPattern } from "../Types";
2
+ /**
3
+ * Universal URL Extractor
4
+ *
5
+ * Allows extraction of entity IDs (track, album, artist, playlist, etc.)
6
+ * from URLs of multiple platforms using configurable regex patterns.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const extractor = new UrlExtractor();
11
+ *
12
+ * // Register Yandex Music patterns
13
+ * extractor.registerPlatform("yandex", [
14
+ * { entity: "track", regex: /music\.yandex\.ru\/track\/(?<id>\d+)/, groupNames: ["id"] },
15
+ * { entity: "album", regex: /music\.yandex\.ru\/album\/(?<id>\d+)/, groupNames: ["id"] },
16
+ * { entity: "artist", regex: /music\.yandex\.ru\/artist\/(?<id>\d+)/, groupNames: ["id"] },
17
+ * { entity: "playlist", regex: /music\.yandex\.ru\/users\/(?<user>[\w\d\-_\.]+)\/playlists\/(?<id>\d+)/, groupNames: ["id", "user"] },
18
+ * { entity: "playlist", regex: /music\.yandex\.ru\/playlists?\/(?<uid>(?:ar\.)?[A-Za-z0-9\-]+)/, groupNames: ["uid"] },
19
+ * ]);
20
+ *
21
+ * // Extract track ID
22
+ * const trackId = extractor.extractId<number>(
23
+ * "https://music.yandex.ru/track/25063569",
24
+ * "track",
25
+ * "yandex"
26
+ * ).id;
27
+ *
28
+ * // Extract playlist info
29
+ * const playlist = extractor.extractId<string | number>(
30
+ * "https://music.yandex.ru/playlists/ar123456",
31
+ * "playlist",
32
+ * "yandex"
33
+ * );
34
+ * ```
35
+ */
36
+ export default class UrlExtractor implements UrlExtractorInterface {
37
+ private patterns;
38
+ /**
39
+ * Register a platform with its URL patterns.
40
+ *
41
+ * Each pattern should specify:
42
+ * - `entity`: the type of entity this pattern extracts (e.g., "track", "album")
43
+ * - `regex`: a regular expression with named capture groups
44
+ * - `groupNames`: array of the named groups to extract from the regex
45
+ *
46
+ * @param platform - Platform name (e.g., "yandex", "spotify")
47
+ * @param patterns - Array of URL patterns for this platform
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * extractor.registerPlatform("yandex", [
52
+ * { entity: "track", regex: /music\.yandex\.ru\/track\/(?<id>\d+)/, groupNames: ["id"] }
53
+ * ]);
54
+ * ```
55
+ */
56
+ registerPlatform(platform: string, patterns: UrlPattern[]): void;
57
+ /**
58
+ * Extract named groups from a URL using a specific pattern
59
+ * @param url URL to extract from
60
+ * @param pattern UrlPattern containing regex and group names
61
+ * @throws Will throw if the URL does not match the pattern or required groups are missing
62
+ * @returns Object with extracted group values
63
+ */
64
+ private extractGroups;
65
+ /**
66
+ * Extract an entity ID from a URL.
67
+ *
68
+ * This method tries all registered patterns for the given entity and platform.
69
+ * The returned values are always strings. If you expect numeric IDs, you should
70
+ * convert them using `Number()`.
71
+ *
72
+ * @param url - URL to extract from
73
+ * @param entity - Entity type ("track", "album", "artist", "playlist", etc.)
74
+ * @param platform - Platform name registered with `registerPlatform`
75
+ * @throws Will throw if no matching pattern is found or extraction fails
76
+ * @returns Record<string, string> containing extracted values (keys depend on the pattern)
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const result = extractor.extractId('https://music.yandex.ru/track/25063569', 'track', 'yandex');
81
+ * console.log(result.id); // "25063569" (string)
82
+ * const numericId = Number(result.id); // 25063569
83
+ * ```
84
+ */
85
+ extractId<T extends string | number>(url: string, entity: string, platform: string, castNumbers?: boolean): Record<string, T>;
86
+ }
87
+ //# sourceMappingURL=UrlExtractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UrlExtractor.d.ts","sourceRoot":"","sources":["../../src/Hyperttp/UrlExtractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,YAAW,qBAAqB;IAChE,OAAO,CAAC,QAAQ,CAAoC;IAEpD;;;;;;;;;;;;;;;;;OAiBG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE;IAIzD;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAmBrB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EACjC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,WAAW,UAAO,GACjB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;CAgCrB"}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Universal URL Extractor
5
+ *
6
+ * Allows extraction of entity IDs (track, album, artist, playlist, etc.)
7
+ * from URLs of multiple platforms using configurable regex patterns.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const extractor = new UrlExtractor();
12
+ *
13
+ * // Register Yandex Music patterns
14
+ * extractor.registerPlatform("yandex", [
15
+ * { entity: "track", regex: /music\.yandex\.ru\/track\/(?<id>\d+)/, groupNames: ["id"] },
16
+ * { entity: "album", regex: /music\.yandex\.ru\/album\/(?<id>\d+)/, groupNames: ["id"] },
17
+ * { entity: "artist", regex: /music\.yandex\.ru\/artist\/(?<id>\d+)/, groupNames: ["id"] },
18
+ * { entity: "playlist", regex: /music\.yandex\.ru\/users\/(?<user>[\w\d\-_\.]+)\/playlists\/(?<id>\d+)/, groupNames: ["id", "user"] },
19
+ * { entity: "playlist", regex: /music\.yandex\.ru\/playlists?\/(?<uid>(?:ar\.)?[A-Za-z0-9\-]+)/, groupNames: ["uid"] },
20
+ * ]);
21
+ *
22
+ * // Extract track ID
23
+ * const trackId = extractor.extractId<number>(
24
+ * "https://music.yandex.ru/track/25063569",
25
+ * "track",
26
+ * "yandex"
27
+ * ).id;
28
+ *
29
+ * // Extract playlist info
30
+ * const playlist = extractor.extractId<string | number>(
31
+ * "https://music.yandex.ru/playlists/ar123456",
32
+ * "playlist",
33
+ * "yandex"
34
+ * );
35
+ * ```
36
+ */
37
+ class UrlExtractor {
38
+ patterns = {};
39
+ /**
40
+ * Register a platform with its URL patterns.
41
+ *
42
+ * Each pattern should specify:
43
+ * - `entity`: the type of entity this pattern extracts (e.g., "track", "album")
44
+ * - `regex`: a regular expression with named capture groups
45
+ * - `groupNames`: array of the named groups to extract from the regex
46
+ *
47
+ * @param platform - Platform name (e.g., "yandex", "spotify")
48
+ * @param patterns - Array of URL patterns for this platform
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * extractor.registerPlatform("yandex", [
53
+ * { entity: "track", regex: /music\.yandex\.ru\/track\/(?<id>\d+)/, groupNames: ["id"] }
54
+ * ]);
55
+ * ```
56
+ */
57
+ registerPlatform(platform, patterns) {
58
+ this.patterns[platform] = patterns;
59
+ }
60
+ /**
61
+ * Extract named groups from a URL using a specific pattern
62
+ * @param url URL to extract from
63
+ * @param pattern UrlPattern containing regex and group names
64
+ * @throws Will throw if the URL does not match the pattern or required groups are missing
65
+ * @returns Object with extracted group values
66
+ */
67
+ extractGroups(url, pattern) {
68
+ const match = url.match(pattern.regex)?.groups;
69
+ if (!match)
70
+ throw new Error(`Invalid ${pattern.entity} URL: ${url}`);
71
+ return pattern.groupNames.reduce((acc, name) => {
72
+ const value = match[name];
73
+ if (!value)
74
+ throw new Error(`Missing "${name}" in ${pattern.entity} URL: ${url}`);
75
+ acc[name] = value;
76
+ return acc;
77
+ }, {});
78
+ }
79
+ /**
80
+ * Extract an entity ID from a URL.
81
+ *
82
+ * This method tries all registered patterns for the given entity and platform.
83
+ * The returned values are always strings. If you expect numeric IDs, you should
84
+ * convert them using `Number()`.
85
+ *
86
+ * @param url - URL to extract from
87
+ * @param entity - Entity type ("track", "album", "artist", "playlist", etc.)
88
+ * @param platform - Platform name registered with `registerPlatform`
89
+ * @throws Will throw if no matching pattern is found or extraction fails
90
+ * @returns Record<string, string> containing extracted values (keys depend on the pattern)
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * const result = extractor.extractId('https://music.yandex.ru/track/25063569', 'track', 'yandex');
95
+ * console.log(result.id); // "25063569" (string)
96
+ * const numericId = Number(result.id); // 25063569
97
+ * ```
98
+ */
99
+ extractId(url, entity, platform, castNumbers = true) {
100
+ const patterns = this.patterns[platform]?.filter((p) => p.entity === entity);
101
+ if (!patterns?.length)
102
+ throw new Error(`No patterns registered for "${entity}" on platform "${platform}"`);
103
+ for (const pattern of patterns) {
104
+ try {
105
+ const extracted = this.extractGroups(url, pattern);
106
+ const result = {};
107
+ for (const key in extracted) {
108
+ const value = extracted[key];
109
+ // Если ожидаем число и включен castNumbers, конвертируем
110
+ if (castNumbers && !isNaN(Number(value))) {
111
+ result[key] = Number(value);
112
+ }
113
+ else {
114
+ result[key] = value;
115
+ }
116
+ }
117
+ return result;
118
+ }
119
+ catch {
120
+ // continue searching for a matching pattern
121
+ }
122
+ }
123
+ throw new Error(`Invalid ${entity} URL for platform "${platform}": ${url}`);
124
+ }
125
+ }
126
+ exports.default = UrlExtractor;
127
+ //# sourceMappingURL=UrlExtractor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UrlExtractor.js","sourceRoot":"","sources":["../../src/Hyperttp/UrlExtractor.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;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nE,CAAC;QAEJ,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC;gBACH,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;gBAEnD,MAAM,MAAM,GAAwB,EAAE,CAAC;gBACvC,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;oBAC5B,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;oBAC7B,yDAAyD;oBACzD,IAAI,WAAW,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;wBACzC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC9B,CAAC;yBAAM,CAAC;wBACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;oBACtB,CAAC;gBACH,CAAC;gBAED,OAAO,MAA2B,CAAC;YACrC,CAAC;YAAC,MAAM,CAAC;gBACP,4CAA4C;YAC9C,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,sBAAsB,QAAQ,MAAM,GAAG,EAAE,CAAC,CAAC;IAC9E,CAAC;CACF;AA5GD,+BA4GC"}
@@ -0,0 +1,5 @@
1
+ export { HttpClientImproved, QueueManager, CacheManager, RateLimiter, } from "./Core";
2
+ export { default as Request } from "./Request";
3
+ export { PreparedRequest } from "./Request";
4
+ export { default as UrlExtractor } from "./UrlExtractor";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Hyperttp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,18 @@
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.UrlExtractor = exports.PreparedRequest = exports.Request = exports.RateLimiter = exports.CacheManager = exports.QueueManager = exports.HttpClientImproved = void 0;
7
+ var Core_1 = require("./Core");
8
+ Object.defineProperty(exports, "HttpClientImproved", { enumerable: true, get: function () { return Core_1.HttpClientImproved; } });
9
+ Object.defineProperty(exports, "QueueManager", { enumerable: true, get: function () { return Core_1.QueueManager; } });
10
+ Object.defineProperty(exports, "CacheManager", { enumerable: true, get: function () { return Core_1.CacheManager; } });
11
+ Object.defineProperty(exports, "RateLimiter", { enumerable: true, get: function () { return Core_1.RateLimiter; } });
12
+ var Request_1 = require("./Request");
13
+ Object.defineProperty(exports, "Request", { enumerable: true, get: function () { return __importDefault(Request_1).default; } });
14
+ var Request_2 = require("./Request");
15
+ Object.defineProperty(exports, "PreparedRequest", { enumerable: true, get: function () { return Request_2.PreparedRequest; } });
16
+ var UrlExtractor_1 = require("./UrlExtractor");
17
+ Object.defineProperty(exports, "UrlExtractor", { enumerable: true, get: function () { return __importDefault(UrlExtractor_1).default; } });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Hyperttp/index.ts"],"names":[],"mappings":";;;;;;AAAA,+BAKgB;AAJd,0GAAA,kBAAkB,OAAA;AAClB,oGAAA,YAAY,OAAA;AACZ,oGAAA,YAAY,OAAA;AACZ,mGAAA,WAAW,OAAA;AAEb,qCAA+C;AAAtC,mHAAA,OAAO,OAAW;AAC3B,qCAA4C;AAAnC,0GAAA,eAAe,OAAA;AACxB,+CAAyD;AAAhD,6HAAA,OAAO,OAAgB"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Interface for a universal URL extractor
3
+ */
4
+ export interface UrlExtractorInterface {
5
+ /**
6
+ * Register a platform with its URL patterns
7
+ * @param platform Platform name (e.g., "yandex", "spotify")
8
+ * @param patterns Array of URL patterns for the platform
9
+ */
10
+ registerPlatform(platform: string, patterns: UrlPattern[]): void;
11
+ /**
12
+ * Extract an entity ID or related info from a URL
13
+ * @param url URL to extract from
14
+ * @param entity Entity type ("track", "album", "artist", "playlist", etc.)
15
+ * @param platform Platform name that has been registered
16
+ * @returns Record of extracted values (keys depend on the pattern)
17
+ */
18
+ extractId<T extends string | number>(url: string, entity: string, platform: string): Record<string, T>;
19
+ }
20
+ /**
21
+ * Defines a URL extraction pattern for a platform
22
+ */
23
+ export interface UrlPattern<T extends string = string> {
24
+ /** Entity type this pattern applies to (track, album, artist, playlist, etc.) */
25
+ entity: string;
26
+ /** Regex with named capturing groups to extract IDs or info */
27
+ regex: RegExp;
28
+ /** Names of the capturing groups to extract */
29
+ groupNames: T[];
30
+ }
31
+ export * from "./request";
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAEjE;;;;;;OAMG;IACH,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EACjC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACnD,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;IAEf,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;IAEd,+CAA+C;IAC/C,UAAU,EAAE,CAAC,EAAE,CAAC;CACjB;AAED,cAAc,WAAW,CAAC"}
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./request"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAuCA,4CAA0B"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Represents HTTP request headers
3
+ */
4
+ export type RequestHeaders = {
5
+ [key: string]: string;
6
+ };
7
+ /**
8
+ * Represents URL query parameters
9
+ */
10
+ export type RequestQuery = {
11
+ [key: string]: string;
12
+ };
13
+ /**
14
+ * Represents body data for requests
15
+ */
16
+ export type RequestBodyData = {
17
+ [key: string]: string;
18
+ };
19
+ /**
20
+ * Configuration for a request
21
+ */
22
+ export type RequestConfig = {
23
+ /** Protocol scheme (http or https) */
24
+ scheme: string;
25
+ /** Hostname or IP address */
26
+ host: string;
27
+ /** Port number */
28
+ port: number;
29
+ /** Optional path after host */
30
+ path?: string;
31
+ /** Optional headers */
32
+ headers?: RequestHeaders;
33
+ /** Optional query parameters */
34
+ query?: RequestQuery;
35
+ /** Optional body data */
36
+ bodyData?: RequestBodyData;
37
+ };
38
+ /**
39
+ * HTTP method type
40
+ */
41
+ export type Method = "get" | "post";
42
+ /**
43
+ * Represents a generic object response
44
+ */
45
+ export type ObjectResponse = {
46
+ [key: string]: any;
47
+ };
48
+ /**
49
+ * Represents a plain string response
50
+ */
51
+ export type StringResponse = string;
52
+ /**
53
+ * Represents either an object or string response
54
+ */
55
+ export type Response = ObjectResponse | StringResponse;
56
+ /**
57
+ * Interface for a request object
58
+ */
59
+ export interface RequestInterface {
60
+ /** Set the request path */
61
+ setPath(path: string): RequestInterface;
62
+ /** Set the host for the request */
63
+ setHost(host: string): RequestInterface;
64
+ /** Get current request headers */
65
+ getHeaders(): RequestHeaders;
66
+ /** Replace all headers */
67
+ setHeaders(headers: RequestHeaders): RequestInterface;
68
+ /** Add headers to the existing ones */
69
+ addHeaders(headers: RequestHeaders): RequestInterface;
70
+ /** Get current query parameters */
71
+ getQuery(): RequestQuery;
72
+ /** Replace all query parameters */
73
+ setQuery(query: RequestQuery): RequestInterface;
74
+ /** Add query parameters */
75
+ addQuery(query: RequestQuery): RequestInterface;
76
+ /** Get query string representation */
77
+ getQueryAsString(): string;
78
+ /** Get request body data */
79
+ getBodyData(): RequestBodyData;
80
+ /** Get body data as string (e.g., for JSON or URL-encoded) */
81
+ getBodyDataString(): string;
82
+ /** Replace body data */
83
+ setBodyData(bodyData: RequestBodyData): RequestInterface;
84
+ /** Add data to the existing body */
85
+ addBodyData(bodyData: RequestBodyData): RequestInterface;
86
+ /** Get URI (path + query) */
87
+ getURI(): string;
88
+ /** Get full URL including scheme, host, port, path and query */
89
+ getURL(): string;
90
+ }
91
+ /**
92
+ * Interface for a HTTP client
93
+ */
94
+ export interface HttpClientInterface {
95
+ /**
96
+ * Send a GET request
97
+ * @param request Request object
98
+ * @returns Response object or string
99
+ */
100
+ get(request: RequestInterface): Promise<Response>;
101
+ /**
102
+ * Send a POST request
103
+ * @param request Request object
104
+ * @returns Response object or string
105
+ */
106
+ post(request: RequestInterface): Promise<Response>;
107
+ }
108
+ /**
109
+ * Options to configure HttpClient
110
+ */
111
+ export interface HttpClientOptions {
112
+ /** Maximum number of concurrent requests */
113
+ maxConcurrent?: number;
114
+ /** Rate limiting options */
115
+ rateLimit?: {
116
+ maxRequests?: number;
117
+ windowMs?: number;
118
+ };
119
+ /** Maximum number of retry attempts */
120
+ maxRetries?: number;
121
+ /** Cache time-to-live in milliseconds */
122
+ cacheTTL?: number;
123
+ /** Maximum number of cached items */
124
+ cacheMaxSize?: number;
125
+ /** Logger function to capture debug/info/warn/error messages */
126
+ logger?: (level: "debug" | "info" | "warn" | "error", msg: string, meta?: any) => void;
127
+ /** User-Agent string to send with requests */
128
+ userAgent?: string;
129
+ /** Follow HTTP redirects (default true) */
130
+ followRedirects?: boolean;
131
+ /** Request timeout in milliseconds */
132
+ timeout?: number;
133
+ responseType?: ResponseType;
134
+ }
135
+ export type ResponseType = "json" | "text" | "buffer" | "xml";
136
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/Types/request.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IAEf,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IAEb,kBAAkB;IACl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ED,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/Types/request.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export { HttpClientImproved, QueueManager, CacheManager, RateLimiter, Request, PreparedRequest, UrlExtractor, } from "./Hyperttp";
2
+ export type * from "./Types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,OAAO,EACP,eAAe,EACf,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,mBAAmB,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UrlExtractor = exports.PreparedRequest = exports.Request = exports.RateLimiter = exports.CacheManager = exports.QueueManager = exports.HttpClientImproved = void 0;
4
+ var Hyperttp_1 = require("./Hyperttp");
5
+ Object.defineProperty(exports, "HttpClientImproved", { enumerable: true, get: function () { return Hyperttp_1.HttpClientImproved; } });
6
+ Object.defineProperty(exports, "QueueManager", { enumerable: true, get: function () { return Hyperttp_1.QueueManager; } });
7
+ Object.defineProperty(exports, "CacheManager", { enumerable: true, get: function () { return Hyperttp_1.CacheManager; } });
8
+ Object.defineProperty(exports, "RateLimiter", { enumerable: true, get: function () { return Hyperttp_1.RateLimiter; } });
9
+ Object.defineProperty(exports, "Request", { enumerable: true, get: function () { return Hyperttp_1.Request; } });
10
+ Object.defineProperty(exports, "PreparedRequest", { enumerable: true, get: function () { return Hyperttp_1.PreparedRequest; } });
11
+ Object.defineProperty(exports, "UrlExtractor", { enumerable: true, get: function () { return Hyperttp_1.UrlExtractor; } });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAQoB;AAPlB,8GAAA,kBAAkB,OAAA;AAClB,wGAAA,YAAY,OAAA;AACZ,wGAAA,YAAY,OAAA;AACZ,uGAAA,WAAW,OAAA;AACX,mGAAA,OAAO,OAAA;AACP,2GAAA,eAAe,OAAA;AACf,wGAAA,YAAY,OAAA"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "hyperttp",
3
+ "version": "0.1.5",
4
+ "description": "A high-performance, universal HTTP client for Node.js with caching, retries, queueing, rate limiting, cookies and logging.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "author": "dirold2",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/dirold2/hyperttp.git"
12
+ },
13
+ "keywords": [
14
+ "http",
15
+ "client",
16
+ "fetch",
17
+ "undici",
18
+ "cache",
19
+ "rate-limit",
20
+ "queue",
21
+ "retry",
22
+ "cookies",
23
+ "logger"
24
+ ],
25
+ "dependencies": {
26
+ "undici": "^7.16.0",
27
+ "tough-cookie": "^6.0.0",
28
+ "http-cookie-agent": "^7.0.3",
29
+ "fast-xml-parser": "^5.3.3",
30
+ "lru-cache": "^11.2.4"
31
+ }
32
+ }