@nestia/fetcher
Advanced tools
Comparing version 3.2.2-dev.20240617 to 3.2.2
@@ -17,2 +17,4 @@ /** | ||
* Path template. | ||
* | ||
* Filled since 3.2.2 version. | ||
*/ | ||
@@ -19,0 +21,0 @@ template?: string; |
@@ -121,3 +121,3 @@ "use strict"; | ||
return function (props) { | ||
return function (connection, metadata, input, stringify) { return __awaiter(_this, void 0, void 0, function () { | ||
return function (connection, route, input, stringify) { return __awaiter(_this, void 0, void 0, function () { | ||
var headers, init, path, url, event, response, _a, result, _b, type, text, query, _c, _d, _e, _f, exp_1, _g; | ||
@@ -130,7 +130,7 @@ var _h, _j, _k, _l, _m, _o, _p, _q, _r; | ||
if (input !== undefined) | ||
if (((_j = metadata.request) === null || _j === void 0 ? void 0 : _j.type) === undefined) | ||
if (((_j = route.request) === null || _j === void 0 ? void 0 : _j.type) === undefined) | ||
throw new Error("Error on ".concat(props.className, ".fetch(): no content-type being configured.")); | ||
else if (metadata.request.type !== "multipart/form-data") | ||
headers["Content-Type"] = metadata.request.type; | ||
init = __assign(__assign({}, ((_k = connection.options) !== null && _k !== void 0 ? _k : {})), { method: metadata.method, headers: (function () { | ||
else if (route.request.type !== "multipart/form-data") | ||
headers["Content-Type"] = route.request.type; | ||
init = __assign(__assign({}, ((_k = connection.options) !== null && _k !== void 0 ? _k : {})), { method: route.method, headers: (function () { | ||
var e_1, _a, e_2, _b; | ||
@@ -174,16 +174,16 @@ var output = []; | ||
// BODY TRANSFORM | ||
((_l = metadata.request) === null || _l === void 0 ? void 0 : _l.type) === "application/x-www-form-urlencoded" | ||
((_l = route.request) === null || _l === void 0 ? void 0 : _l.type) === "application/x-www-form-urlencoded" | ||
? request_query_body(input) | ||
: ((_m = metadata.request) === null || _m === void 0 ? void 0 : _m.type) === "multipart/form-data" | ||
: ((_m = route.request) === null || _m === void 0 ? void 0 : _m.type) === "multipart/form-data" | ||
? request_form_data_body(input) | ||
: ((_o = metadata.request) === null || _o === void 0 ? void 0 : _o.type) !== "text/plain" | ||
: ((_o = route.request) === null || _o === void 0 ? void 0 : _o.type) !== "text/plain" | ||
? (stringify !== null && stringify !== void 0 ? stringify : JSON.stringify)(input) | ||
: input, headers); | ||
path = connection.host[connection.host.length - 1] !== "/" && | ||
metadata.path[0] !== "/" | ||
? "/".concat(metadata.path) | ||
: metadata.path; | ||
route.path[0] !== "/" | ||
? "/".concat(route.path) | ||
: route.path; | ||
url = new URL("".concat(connection.host).concat(path)); | ||
event = { | ||
route: metadata, | ||
route: route, | ||
path: path, | ||
@@ -215,3 +215,3 @@ status: null, | ||
response.status === 201 || | ||
response.status == metadata.status, | ||
response.status == route.status, | ||
status: response.status, | ||
@@ -238,7 +238,7 @@ headers: response_headers_to_object(response.headers), | ||
case 7: | ||
if (!(metadata.method === "HEAD")) return [3 /*break*/, 8]; | ||
if (!(route.method === "HEAD")) return [3 /*break*/, 8]; | ||
result.data = undefined; | ||
return [3 /*break*/, 14]; | ||
case 8: | ||
if (!(((_q = metadata.response) === null || _q === void 0 ? void 0 : _q.type) === "application/json")) return [3 /*break*/, 10]; | ||
if (!(((_q = route.response) === null || _q === void 0 ? void 0 : _q.type) === "application/json")) return [3 /*break*/, 10]; | ||
return [4 /*yield*/, response.text()]; | ||
@@ -250,3 +250,3 @@ case 9: | ||
case 10: | ||
if (!(((_r = metadata.response) === null || _r === void 0 ? void 0 : _r.type) === "application/x-www-form-urlencoded")) return [3 /*break*/, 12]; | ||
if (!(((_r = route.response) === null || _r === void 0 ? void 0 : _r.type) === "application/x-www-form-urlencoded")) return [3 /*break*/, 12]; | ||
_c = URLSearchParams.bind; | ||
@@ -256,5 +256,3 @@ return [4 /*yield*/, response.text()]; | ||
query = new (_c.apply(URLSearchParams, [void 0, _s.sent()]))(); | ||
result.data = metadata.parseQuery | ||
? metadata.parseQuery(query) | ||
: query; | ||
result.data = route.parseQuery ? route.parseQuery(query) : query; | ||
return [3 /*break*/, 14]; | ||
@@ -261,0 +259,0 @@ case 12: |
{ | ||
"name": "@nestia/fetcher", | ||
"version": "3.2.2-dev.20240617", | ||
"version": "3.2.2", | ||
"description": "Fetcher library of Nestia SDK", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -21,2 +21,4 @@ /** | ||
* Path template. | ||
* | ||
* Filled since 3.2.2 version. | ||
*/ | ||
@@ -23,0 +25,0 @@ template?: string; |
@@ -66,5 +66,3 @@ import import2 from "import2"; | ||
connection: IConnection, | ||
metadata: IFetchRoute< | ||
"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | ||
>, | ||
route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">, | ||
input?: Input, | ||
@@ -81,8 +79,8 @@ stringify?: (input: Input) => string, | ||
if (input !== undefined) | ||
if (metadata.request?.type === undefined) | ||
if (route.request?.type === undefined) | ||
throw new Error( | ||
`Error on ${props.className}.fetch(): no content-type being configured.`, | ||
); | ||
else if (metadata.request.type !== "multipart/form-data") | ||
headers["Content-Type"] = metadata.request.type; | ||
else if (route.request.type !== "multipart/form-data") | ||
headers["Content-Type"] = route.request.type; | ||
@@ -92,3 +90,3 @@ // INIT REQUEST DATA | ||
...(connection.options ?? {}), | ||
method: metadata.method, | ||
method: route.method, | ||
headers: (() => { | ||
@@ -109,7 +107,7 @@ const output: [string, string][] = []; | ||
// BODY TRANSFORM | ||
metadata.request?.type === "application/x-www-form-urlencoded" | ||
route.request?.type === "application/x-www-form-urlencoded" | ||
? request_query_body(input) | ||
: metadata.request?.type === "multipart/form-data" | ||
: route.request?.type === "multipart/form-data" | ||
? request_form_data_body(input as any) | ||
: metadata.request?.type !== "text/plain" | ||
: route.request?.type !== "text/plain" | ||
? (stringify ?? JSON.stringify)(input) | ||
@@ -126,5 +124,5 @@ : input, | ||
connection.host[connection.host.length - 1] !== "/" && | ||
metadata.path[0] !== "/" | ||
? `/${metadata.path}` | ||
: metadata.path; | ||
route.path[0] !== "/" | ||
? `/${route.path}` | ||
: route.path; | ||
const url: URL = new URL(`${connection.host}${path}`); | ||
@@ -134,3 +132,3 @@ | ||
const event: IFetchEvent = { | ||
route: metadata, | ||
route, | ||
path, | ||
@@ -157,3 +155,3 @@ status: null, | ||
response.status === 201 || | ||
response.status == metadata.status, | ||
response.status == route.status, | ||
status: response.status, | ||
@@ -177,8 +175,8 @@ headers: response_headers_to_object(response.headers), | ||
// WHEN SUCCESS | ||
if (metadata.method === "HEAD") result.data = undefined!; | ||
else if (metadata.response?.type === "application/json") { | ||
if (route.method === "HEAD") result.data = undefined!; | ||
else if (route.response?.type === "application/json") { | ||
const text: string = await response.text(); | ||
result.data = text.length ? JSON.parse(text) : undefined; | ||
} else if ( | ||
metadata.response?.type === "application/x-www-form-urlencoded" | ||
route.response?.type === "application/x-www-form-urlencoded" | ||
) { | ||
@@ -188,5 +186,3 @@ const query: URLSearchParams = new URLSearchParams( | ||
); | ||
result.data = metadata.parseQuery | ||
? metadata.parseQuery(query) | ||
: query; | ||
result.data = route.parseQuery ? route.parseQuery(query) : query; | ||
} else | ||
@@ -193,0 +189,0 @@ result.data = props.decode(await response.text(), result.headers); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
147009
3087