hyperttp 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Hyperttp/Client/HyperClient.d.ts +7 -3
- package/Hyperttp/Client/HyperClient.d.ts.map +1 -1
- package/Hyperttp/Client/HyperClient.js +1 -1
- package/Hyperttp/Client/HyperClient.js.map +3 -3
- package/Hyperttp/Request.d.ts +3 -0
- package/Hyperttp/Request.d.ts.map +1 -1
- package/Hyperttp/Request.js +1 -1
- package/Hyperttp/Request.js.map +3 -3
- package/Hyperttp/UrlExtractor.d.ts +16 -5
- package/Hyperttp/UrlExtractor.d.ts.map +1 -1
- package/Hyperttp/UrlExtractor.js +1 -1
- package/Hyperttp/UrlExtractor.js.map +3 -3
- package/Hyperttp/Utils/RequestBuilder.d.ts +1 -7
- package/Hyperttp/Utils/RequestBuilder.d.ts.map +1 -1
- package/Hyperttp/Utils/RequestBuilder.js +1 -1
- package/Hyperttp/Utils/RequestBuilder.js.map +3 -3
- package/Hyperttp/Utils/index.d.ts +2 -0
- package/Hyperttp/Utils/index.d.ts.map +1 -1
- package/Hyperttp/Utils/index.js.map +2 -2
- package/Hyperttp/Utils/query.d.ts +3 -1
- package/Hyperttp/Utils/query.d.ts.map +1 -1
- package/Hyperttp/Utils/query.js.map +2 -2
- package/Hyperttp/index.d.ts +1 -0
- package/Hyperttp/index.d.ts.map +1 -1
- package/Hyperttp/index.js.map +2 -2
- package/README.md +392 -162
- package/Types/url-extractor.d.ts +5 -2
- package/Types/url-extractor.d.ts.map +1 -1
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -1
- package/index.js.map +2 -2
- package/package.json +7 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Hyperttp/Utils/RequestBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["import type { HttpMethod, RestRequestOptions } from \"@hyperttp/core/rest\";\nimport { HyperClient } from \"../Client/HyperClient.js\";\nimport { appendQueryToUrl, type RequestQuery } from \"./query.js\";\n\nexport type ResponseType = \"json\" | \"text\" | \"xml\" | \"html\" | \"buffer\" | \"stream\";\n\n/**\n * @ru \u0421\u0442\u0440\u043E\u0438\u0442\u0435\u043B\u044C \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432 \u0434\u043B\u044F \u0443\u0434\u043E\u0431\u043D\u043E\u0433\u043E \u0441\u043E\u0437\u0434\u0430\u043D\u0438\u044F \u0438 \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438 HTTP \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432.\n * @en Request builder for convenient creation and configuration of HTTP requests.\n */\nexport class RequestBuilder {\n private _url: string;\n private _method: HttpMethod = \"GET\";\n private _headers: Record<string, string> = {};\n private _body?: unknown;\n private _client: HyperClient;\n private _signal?: AbortSignal;\n private _queryParams: RequestQuery = {};\n private _timeout?: number;\n private _responseType?: ResponseType;\n\n /**\n * @ru \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 \u043F\u043E\u0441\u0442\u0440\u043E\u0438\u0442\u0435\u043B\u044F \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432.\n * @en Creates a request builder instance.\n * @param url - Base URL for the request.\n * @param client - HyperClient instance used to execute the request.\n */\n constructor(url: string, client: HyperClient) {\n this._url = url;\n this._client = client;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 HTTP \u043C\u0435\u0442\u043E\u0434.\n * @en Sets the HTTP method.\n * @param method - HTTP method (GET, POST, etc.).\n * @returns This builder instance for chaining.\n */\n method(method: HttpMethod): this {\n this._method = method;\n return this;\n }\n\n /**\n * @ru \u0414\u043E\u0431\u0430\u0432\u043B\u044F\u0435\u0442 \u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043A\u0438 \u043A \u0437\u0430\u043F\u0440\u043E\u0441\u0443 (\u043C\u0435\u0440\u0436\u0438\u0442 \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0449\u0438\u043C\u0438).\n * @en Adds headers to the request (merges with existing ones).\n * @param headers - Headers object to merge.\n * @returns This builder instance for chaining.\n */\n headers(headers: Record<string, string>): this {\n Object.assign(this._headers, headers);\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043B\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0430 (\u043F\u0440\u043E\u0438\u0437\u0432\u043E\u043B\u044C\u043D\u044B\u0435 \u0434\u0430\u043D\u043D\u044B\u0435).\n * @en Sets the request body (arbitrary data).\n * @param bodyData - Request body data.\n * @returns This builder instance for chaining.\n */\n body(bodyData: unknown): this {\n this._body = bodyData;\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043B\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0430 \u0432 \u0444\u043E\u0440\u043C\u0430\u0442\u0435 JSON \u0438 \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u0438 \u0434\u043E\u0431\u0430\u0432\u043B\u044F\u0435\u0442 \u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A Content-Type: application/json.\n * @en Sets the request body as JSON and automatically adds Content-Type: application/json header.\n * @param body - JSON-serializable body.\n * @returns This builder instance for chaining.\n */\n jsonBody(body: unknown): this {\n this._body = body;\n this._headers[\"Content-Type\"] = \"application/json; charset=utf-8\";\n return this;\n }\n\n /**\n * @ru \u0414\u043E\u0431\u0430\u0432\u043B\u044F\u0435\u0442 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0437\u0430\u043F\u0440\u043E\u0441\u0430 (query string). \u041C\u0435\u0440\u0436\u0438\u0442 \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0449\u0438\u043C\u0438.\n * @en Adds query parameters to the URL (query string). Merges with existing ones.\n * @param params - Object with query parameters (keys and values).\n * @returns This builder instance for chaining.\n */\n query(params: RequestQuery): this {\n Object.assign(this._queryParams, params);\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 GET.\n * @en Sets HTTP method to GET.\n * @returns This builder instance for chaining.\n */\n get(): this {\n this._method = \"GET\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 POST.\n * @en Sets HTTP method to POST.\n * @returns This builder instance for chaining.\n */\n post(): this {\n this._method = \"POST\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 PUT.\n * @en Sets HTTP method to PUT.\n * @returns This builder instance for chaining.\n */\n put(): this {\n this._method = \"PUT\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 PATCH.\n * @en Sets HTTP method to PATCH.\n * @returns This builder instance for chaining.\n */\n patch(): this {\n this._method = \"PATCH\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 DELETE.\n * @en Sets HTTP method to DELETE.\n * @returns This builder instance for chaining.\n */\n delete(): this {\n this._method = \"DELETE\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 HEAD.\n * @en Sets HTTP method to HEAD.\n * @returns This builder instance for chaining.\n */\n head(): this {\n this._method = \"HEAD\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 OPTIONS.\n * @en Sets HTTP method to OPTIONS.\n * @returns This builder instance for chaining.\n */\n options(): this {\n this._method = \"OPTIONS\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u0433\u043D\u0430\u043B \u0434\u043B\u044F \u043E\u0442\u043C\u0435\u043D\u044B \u0437\u0430\u043F\u0440\u043E\u0441\u0430 (AbortSignal).\n * @en Sets an abort signal for the request.\n * @param signal - AbortSignal instance.\n * @returns This builder instance for chaining.\n */\n signal(signal: AbortSignal): this {\n this._signal = signal;\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u0439\u043C\u0430\u0443\u0442 \u0437\u0430\u043F\u0440\u043E\u0441\u0430 \u0432 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u0430\u0445. \u0421\u043E\u0437\u0434\u0430\u0451\u0442 AbortSignal.timeout.\n * @en Sets a request timeout in milliseconds. Creates an AbortSignal.timeout.\n * @param ms - Timeout in milliseconds.\n * @returns This builder instance for chaining.\n */\n timeout(ms: number): this {\n this._timeout = ms;\n return this;\n }\n\n json(): this {\n this._responseType = \"json\";\n return this;\n }\n\n text(): this {\n this._responseType = \"text\";\n return this;\n }\n\n xml(): this {\n this._responseType = \"xml\";\n return this;\n }\n\n html(): this {\n this._responseType = \"html\";\n return this;\n }\n\n buffer(): this {\n this._responseType = \"buffer\";\n return this;\n }\n\n stream(): this {\n this._responseType = \"stream\";\n return this;\n }\n\n /**\n * @ru \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u043A\u043E\u043F\u0438\u044E \u0442\u0435\u043A\u0443\u0449\u0435\u0433\u043E builder'\u0430.\n * @en Creates a clone of the current builder.\n * @returns New RequestBuilder instance with the same configuration.\n */\n clone(): RequestBuilder {\n const cloned = new RequestBuilder(this._url, this._client);\n cloned._method = this._method;\n cloned._headers = { ...this._headers };\n cloned._body = this._body;\n cloned._signal = this._signal;\n cloned._queryParams = { ...this._queryParams };\n cloned._timeout = this._timeout;\n cloned._responseType = this._responseType;\n return cloned;\n }\n\n /**\n * @ru \u0424\u043E\u0440\u043C\u0438\u0440\u0443\u0435\u0442 URL \u0441 \u0443\u0447\u0451\u0442\u043E\u043C \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u043E\u0432 \u0437\u0430\u043F\u0440\u043E\u0441\u0430.\n * @en Builds the URL with query parameters applied.\n * @returns The final URL string.\n */\n private buildUrl(): string {\n if (Object.keys(this._queryParams).length > 0) {\n return appendQueryToUrl(this._url, this._queryParams);\n }\n return this._url;\n }\n\n /**\n * @ru \u0424\u043E\u0440\u043C\u0438\u0440\u0443\u0435\u0442 \u043E\u043F\u0446\u0438\u0438 \u0437\u0430\u043F\u0440\u043E\u0441\u0430 \u0438\u0437 \u0442\u0435\u043A\u0443\u0449\u0438\u0445 \u043D\u0430\u0441\u0442\u0440\u043E\u0435\u043A.\n * @en Builds request options from current settings.\n * @returns RestRequestOptions ready for dispatching.\n */\n private toOptions(): RestRequestOptions {\n const opts: RestRequestOptions = {};\n if (Object.keys(this._headers).length > 0) opts.headers = this._headers;\n if (this._body !== undefined) opts.body = this._body;\n if (this._timeout !== undefined) opts.timeout = this._timeout;\n return opts;\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 \u0437\u0430\u043F\u0440\u043E\u0441 \u0441 \u0442\u0435\u043A\u0443\u0449\u0438\u043C\u0438 \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0430\u043C\u0438 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Promise \u0441 \u0440\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442\u043E\u043C.\n * @en Executes the request with current settings and returns a Promise with the result.\n * @template T - Expected response type.\n * @returns Promise resolving to the response (type depends on responseType).\n */\n send<T = unknown>(): Promise<T> {\n const url = this.buildUrl();\n const opts = this.toOptions();\n\n if (this._method === \"HEAD\") {\n return this._client.head(url, opts, this._signal) as unknown as Promise<T>;\n }\n\n const m = this._method;\n const hasBody = m === \"POST\" || m === \"PUT\" || m === \"PATCH\" || m === \"OPTIONS\";\n\n return this._client._execute<T>(\n this._method,\n url,\n hasBody ? { ...opts, body: this._body } : opts,\n this._signal,\n this._responseType ? { responseType: this._responseType } : undefined,\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "aACA,MAA4B,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import type { HttpMethod, RestRequestOptions } from \"@hyperttp/core/rest\";\nimport { HyperClient } from \"../Client/HyperClient.js\";\nimport type { RequestQuery } from \"./query.js\";\n\nexport type ResponseType = \"json\" | \"text\" | \"xml\" | \"html\" | \"buffer\" | \"stream\";\n\n/**\n * @ru \u0421\u0442\u0440\u043E\u0438\u0442\u0435\u043B\u044C \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432 \u0434\u043B\u044F \u0443\u0434\u043E\u0431\u043D\u043E\u0433\u043E \u0441\u043E\u0437\u0434\u0430\u043D\u0438\u044F \u0438 \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438 HTTP \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432.\n * @en Request builder for convenient creation and configuration of HTTP requests.\n */\nexport class RequestBuilder {\n private _url: string;\n private _method: HttpMethod = \"GET\";\n private _headers: Record<string, string> = {};\n private _body?: unknown;\n private _client: HyperClient;\n private _signal?: AbortSignal;\n private _queryParams: RequestQuery = {};\n private _timeout?: number;\n private _responseType?: ResponseType;\n\n /**\n * @ru \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 \u043F\u043E\u0441\u0442\u0440\u043E\u0438\u0442\u0435\u043B\u044F \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432.\n * @en Creates a request builder instance.\n * @param url - Base URL for the request.\n * @param client - HyperClient instance used to execute the request.\n */\n constructor(url: string, client: HyperClient) {\n this._url = url;\n this._client = client;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 HTTP \u043C\u0435\u0442\u043E\u0434.\n * @en Sets the HTTP method.\n * @param method - HTTP method (GET, POST, etc.).\n * @returns This builder instance for chaining.\n */\n method(method: HttpMethod): this {\n this._method = method;\n return this;\n }\n\n /**\n * @ru \u0414\u043E\u0431\u0430\u0432\u043B\u044F\u0435\u0442 \u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043A\u0438 \u043A \u0437\u0430\u043F\u0440\u043E\u0441\u0443 (\u043C\u0435\u0440\u0436\u0438\u0442 \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0449\u0438\u043C\u0438).\n * @en Adds headers to the request (merges with existing ones).\n * @param headers - Headers object to merge.\n * @returns This builder instance for chaining.\n */\n headers(headers: Record<string, string>): this {\n Object.assign(this._headers, headers);\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043B\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0430 (\u043F\u0440\u043E\u0438\u0437\u0432\u043E\u043B\u044C\u043D\u044B\u0435 \u0434\u0430\u043D\u043D\u044B\u0435).\n * @en Sets the request body (arbitrary data).\n * @param bodyData - Request body data.\n * @returns This builder instance for chaining.\n */\n body(bodyData: unknown): this {\n this._body = bodyData;\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u0442\u0435\u043B\u043E \u0437\u0430\u043F\u0440\u043E\u0441\u0430 \u0432 \u0444\u043E\u0440\u043C\u0430\u0442\u0435 JSON \u0438 \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u0438 \u0434\u043E\u0431\u0430\u0432\u043B\u044F\u0435\u0442 \u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A Content-Type: application/json.\n * @en Sets the request body as JSON and automatically adds Content-Type: application/json header.\n * @param body - JSON-serializable body.\n * @returns This builder instance for chaining.\n */\n jsonBody(body: unknown): this {\n this._body = body;\n this._headers[\"Content-Type\"] = \"application/json; charset=utf-8\";\n return this;\n }\n\n /**\n * @ru \u0414\u043E\u0431\u0430\u0432\u043B\u044F\u0435\u0442 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0437\u0430\u043F\u0440\u043E\u0441\u0430 (query string). \u041C\u0435\u0440\u0436\u0438\u0442 \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0449\u0438\u043C\u0438.\n * @en Adds query parameters to the URL (query string). Merges with existing ones.\n * @param params - Object with query parameters (keys and values).\n * @returns This builder instance for chaining.\n */\n query(params: RequestQuery): this {\n Object.assign(this._queryParams, params);\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 GET.\n * @en Sets HTTP method to GET.\n * @returns This builder instance for chaining.\n */\n get(): this {\n this._method = \"GET\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 POST.\n * @en Sets HTTP method to POST.\n * @returns This builder instance for chaining.\n */\n post(): this {\n this._method = \"POST\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 PUT.\n * @en Sets HTTP method to PUT.\n * @returns This builder instance for chaining.\n */\n put(): this {\n this._method = \"PUT\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 PATCH.\n * @en Sets HTTP method to PATCH.\n * @returns This builder instance for chaining.\n */\n patch(): this {\n this._method = \"PATCH\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 DELETE.\n * @en Sets HTTP method to DELETE.\n * @returns This builder instance for chaining.\n */\n delete(): this {\n this._method = \"DELETE\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 HEAD.\n * @en Sets HTTP method to HEAD.\n * @returns This builder instance for chaining.\n */\n head(): this {\n this._method = \"HEAD\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u043C\u0435\u0442\u043E\u0434 HTTP \u0432 OPTIONS.\n * @en Sets HTTP method to OPTIONS.\n * @returns This builder instance for chaining.\n */\n options(): this {\n this._method = \"OPTIONS\";\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u0433\u043D\u0430\u043B \u0434\u043B\u044F \u043E\u0442\u043C\u0435\u043D\u044B \u0437\u0430\u043F\u0440\u043E\u0441\u0430 (AbortSignal).\n * @en Sets an abort signal for the request.\n * @param signal - AbortSignal instance.\n * @returns This builder instance for chaining.\n */\n signal(signal: AbortSignal): this {\n this._signal = signal;\n return this;\n }\n\n /**\n * @ru \u0423\u0441\u0442\u0430\u043D\u0430\u0432\u043B\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u0439\u043C\u0430\u0443\u0442 \u0437\u0430\u043F\u0440\u043E\u0441\u0430 \u0432 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u0430\u0445. \u0421\u043E\u0437\u0434\u0430\u0451\u0442 AbortSignal.timeout.\n * @en Sets a request timeout in milliseconds. Creates an AbortSignal.timeout.\n * @param ms - Timeout in milliseconds.\n * @returns This builder instance for chaining.\n */\n timeout(ms: number): this {\n this._timeout = ms;\n return this;\n }\n\n json(): this {\n this._responseType = \"json\";\n return this;\n }\n\n text(): this {\n this._responseType = \"text\";\n return this;\n }\n\n xml(): this {\n this._responseType = \"xml\";\n return this;\n }\n\n html(): this {\n this._responseType = \"html\";\n return this;\n }\n\n buffer(): this {\n this._responseType = \"buffer\";\n return this;\n }\n\n stream(): this {\n this._responseType = \"stream\";\n return this;\n }\n\n /**\n * @ru \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u043A\u043E\u043F\u0438\u044E \u0442\u0435\u043A\u0443\u0449\u0435\u0433\u043E builder'\u0430.\n * @en Creates a clone of the current builder.\n * @returns New RequestBuilder instance with the same configuration.\n */\n clone(): RequestBuilder {\n const cloned = new RequestBuilder(this._url, this._client);\n cloned._method = this._method;\n cloned._headers = { ...this._headers };\n cloned._body = this._body;\n cloned._signal = this._signal;\n cloned._queryParams = { ...this._queryParams };\n cloned._timeout = this._timeout;\n cloned._responseType = this._responseType;\n return cloned;\n }\n\n /**\n * @ru \u0424\u043E\u0440\u043C\u0438\u0440\u0443\u0435\u0442 \u043E\u043F\u0446\u0438\u0438 \u0437\u0430\u043F\u0440\u043E\u0441\u0430 \u0438\u0437 \u0442\u0435\u043A\u0443\u0449\u0438\u0445 \u043D\u0430\u0441\u0442\u0440\u043E\u0435\u043A.\n * @en Builds request options from current settings.\n * @returns RestRequestOptions ready for dispatching.\n */\n private toOptions(): RestRequestOptions {\n const opts: RestRequestOptions = {};\n const query: NonNullable<RestRequestOptions[\"query\"]> = {};\n\n for (const [key, value] of Object.entries(this._queryParams)) {\n if (value == null) continue;\n\n if (Array.isArray(value)) {\n const items = value.filter((item): item is string | number | boolean => item != null);\n if (items.length > 0) query[key] = items;\n } else {\n query[key] = value;\n }\n }\n\n if (Object.keys(this._headers).length > 0) opts.headers = this._headers;\n if (Object.keys(query).length > 0) opts.query = query;\n if (this._body !== undefined) opts.body = this._body;\n if (this._timeout !== undefined) opts.timeout = this._timeout;\n return opts;\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 \u0437\u0430\u043F\u0440\u043E\u0441 \u0441 \u0442\u0435\u043A\u0443\u0449\u0438\u043C\u0438 \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0430\u043C\u0438 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Promise \u0441 \u0440\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442\u043E\u043C.\n * @en Executes the request with current settings and returns a Promise with the result.\n * @template T - Expected response type.\n * @returns Promise resolving to the response (type depends on responseType).\n */\n send<T = unknown>(): Promise<T> {\n const url = this._url;\n const opts = this.toOptions();\n\n if (this._method === \"HEAD\") {\n return this._client.head(url, opts, this._signal) as unknown as Promise<T>;\n }\n\n const m = this._method;\n const hasBody = m === \"POST\" || m === \"PUT\" || m === \"PATCH\" || m === \"OPTIONS\";\n\n return this._client._execute<T>(\n this._method,\n url,\n hasBody ? { ...opts, body: this._body } : opts,\n this._signal,\n this._responseType ? { responseType: this._responseType } : undefined,\n );\n }\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ts", "query", "key", "value", "items", "item", "m", "hasBody"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Hyperttp/Utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Hyperttp/Utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Hyperttp/Utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { RequestBuilder } from \"./RequestBuilder.js\";\nexport { appendQueryToUrl } from \"./query.js\";\n"],
|
|
5
|
-
"mappings": "aAAA,OAAS,mBAAsB,
|
|
4
|
+
"sourcesContent": ["export { RequestBuilder } from \"./RequestBuilder.js\";\nexport type { ResponseType } from \"./RequestBuilder.js\";\nexport { appendQueryToUrl } from \"./query.js\";\nexport type { RequestQuery } from \"./query.js\";\n"],
|
|
5
|
+
"mappings": "aAAA,OAAS,mBAAsB,sBAE/B,OAAS,qBAAwB",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
type RequestQueryValue = string | number | boolean | null | undefined;
|
|
2
|
+
export type RequestQuery = Record<string, RequestQueryValue | RequestQueryValue[]>;
|
|
2
3
|
export declare function appendQueryToUrl(url: string, query: RequestQuery): string;
|
|
4
|
+
export {};
|
|
3
5
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/Hyperttp/Utils/query.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/Hyperttp/Utils/query.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,CAAC,CAAC;AAEnF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,CAoBzE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Hyperttp/Utils/query.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["type RequestQueryValue = string | number | boolean | null | undefined;\n\nexport type RequestQuery = Record<string, RequestQueryValue | RequestQueryValue[]>;\n\nexport function appendQueryToUrl(url: string, query: RequestQuery): string {\n try {\n const urlObj = new URL(url);\n for (const k in query) {\n if (Object.prototype.hasOwnProperty.call(query, k)) {\n const v = query[k];\n if (v == null) continue;\n if (Array.isArray(v)) {\n for (const item of v) {\n if (item != null) urlObj.searchParams.append(k, String(item));\n }\n } else {\n urlObj.searchParams.set(k, String(v));\n }\n }\n }\n return urlObj.toString();\n } catch {\n return url;\n }\n}\n"],
|
|
5
|
+
"mappings": "aAIM,gBAAU,iBAAiBA,EAAaC,EAAmB,CAC/D,GAAI,CACF,MAAMC,EAAS,IAAI,IAAIF,CAAG,EAC1B,UAAWG,KAAKF,EACd,GAAI,OAAO,UAAU,eAAe,KAAKA,EAAOE,CAAC,EAAG,CAClD,MAAMC,EAAIH,EAAME,CAAC,EACjB,GAAIC,GAAK,KAAM,SACf,GAAI,MAAM,QAAQA,CAAC,EACjB,UAAWC,KAAQD,EACbC,GAAQ,MAAMH,EAAO,aAAa,OAAOC,EAAG,OAAOE,CAAI,CAAC,OAG9DH,EAAO,aAAa,IAAIC,EAAG,OAAOC,CAAC,CAAC,CAExC,CAEF,OAAOF,EAAO,SAAQ,CACxB,MAAQ,CACN,OAAOF,CACT,CACF",
|
|
6
6
|
"names": ["url", "query", "urlObj", "k", "v", "item"]
|
|
7
7
|
}
|
package/Hyperttp/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { HyperClient } from "./Client/HyperClient.js";
|
|
2
|
+
export type { ShortcutRequestOptions } from "./Client/HyperClient.js";
|
|
2
3
|
export { default as Request } from "./Request.js";
|
|
3
4
|
export { PreparedRequest } from "./Request.js";
|
|
4
5
|
export { default as UrlExtractor } from "./UrlExtractor.js";
|
package/Hyperttp/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Hyperttp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC5D,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Hyperttp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,YAAY,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC5D,cAAc,kBAAkB,CAAC"}
|
package/Hyperttp/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Hyperttp/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { HyperClient } from \"./Client/HyperClient.js\";\nexport { default as Request } from \"./Request.js\";\nexport { PreparedRequest } from \"./Request.js\";\nexport { default as UrlExtractor } from \"./UrlExtractor.js\";\nexport * from \"./Utils/index.js\";\n"],
|
|
5
|
-
"mappings": "aAAA,OAAS,gBAAmB,
|
|
4
|
+
"sourcesContent": ["export { HyperClient } from \"./Client/HyperClient.js\";\nexport type { ShortcutRequestOptions } from \"./Client/HyperClient.js\";\nexport { default as Request } from \"./Request.js\";\nexport { PreparedRequest } from \"./Request.js\";\nexport { default as UrlExtractor } from \"./UrlExtractor.js\";\nexport * from \"./Utils/index.js\";\n"],
|
|
5
|
+
"mappings": "aAAA,OAAS,gBAAmB,0BAE5B,OAAS,WAAW,YAAe,eACnC,OAAS,oBAAuB,eAChC,OAAS,WAAW,iBAAoB,oBACxC,WAAc",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|