@acrool/react-fetcher 0.0.8-alpha.1 → 0.0.9
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/dist/acrool-react-fetcher.es.js +18 -19
- package/dist/acrool-react-fetcher.es.js.map +1 -1
- package/dist/fetchers/createGraphQLFetcher/types.d.ts +1 -1
- package/dist/fetchers/createRestFulFetcher/types.d.ts +3 -3
- package/dist/fetchers/createRestFulFetcher/utils.d.ts +1 -6
- package/package.json +1 -1
|
@@ -94,6 +94,20 @@ const createGraphQLFetcher = (axiosInstance, query, options) => {
|
|
|
94
94
|
return res.data.data;
|
|
95
95
|
};
|
|
96
96
|
};
|
|
97
|
+
var ERequestContentType = /* @__PURE__ */ ((ERequestContentType2) => {
|
|
98
|
+
ERequestContentType2["formData"] = "multipart/form-data";
|
|
99
|
+
ERequestContentType2["formUrlDecode"] = "application/x-www-form-urlencoded";
|
|
100
|
+
ERequestContentType2["json"] = "application/json";
|
|
101
|
+
return ERequestContentType2;
|
|
102
|
+
})(ERequestContentType || {});
|
|
103
|
+
var ERequestMethod = /* @__PURE__ */ ((ERequestMethod2) => {
|
|
104
|
+
ERequestMethod2["GET"] = "GET";
|
|
105
|
+
ERequestMethod2["POST"] = "POST";
|
|
106
|
+
ERequestMethod2["PUT"] = "PUT";
|
|
107
|
+
ERequestMethod2["DELETE"] = "DELETE";
|
|
108
|
+
ERequestMethod2["PATCH"] = "PATCH";
|
|
109
|
+
return ERequestMethod2;
|
|
110
|
+
})(ERequestMethod || {});
|
|
97
111
|
function $(t2) {
|
|
98
112
|
const n = new FormData(), e2 = (s2, r2 = "") => {
|
|
99
113
|
for (const [a2, o] of Object.entries(s2)) {
|
|
@@ -110,27 +124,10 @@ function $(t2) {
|
|
|
110
124
|
};
|
|
111
125
|
return e2(t2), n;
|
|
112
126
|
}
|
|
113
|
-
var ERequestContentType = /* @__PURE__ */ ((ERequestContentType2) => {
|
|
114
|
-
ERequestContentType2["formData"] = "multipart/form-data";
|
|
115
|
-
ERequestContentType2["formUrlDecode"] = "application/x-www-form-urlencoded";
|
|
116
|
-
ERequestContentType2["json"] = "application/json";
|
|
117
|
-
return ERequestContentType2;
|
|
118
|
-
})(ERequestContentType || {});
|
|
119
|
-
var ERequestMethod = /* @__PURE__ */ ((ERequestMethod2) => {
|
|
120
|
-
ERequestMethod2["GET"] = "GET";
|
|
121
|
-
ERequestMethod2["POST"] = "POST";
|
|
122
|
-
ERequestMethod2["PUT"] = "PUT";
|
|
123
|
-
ERequestMethod2["DELETE"] = "DELETE";
|
|
124
|
-
ERequestMethod2["PATCH"] = "PATCH";
|
|
125
|
-
return ERequestMethod2;
|
|
126
|
-
})(ERequestMethod || {});
|
|
127
127
|
const getDataWithContentType = (contentType, data = {}) => {
|
|
128
128
|
if ([ERequestContentType.formData, ERequestContentType.formUrlDecode].includes(contentType)) return $(data);
|
|
129
129
|
return JSON.stringify(data);
|
|
130
130
|
};
|
|
131
|
-
const getContentTypeWithMethod = (method) => {
|
|
132
|
-
return ERequestContentType.json;
|
|
133
|
-
};
|
|
134
131
|
const createRestFulFetcher = (axiosInstance, document2, options) => {
|
|
135
132
|
return async (args) => {
|
|
136
133
|
const method = (document2 == null ? void 0 : document2.method) || "";
|
|
@@ -143,8 +140,10 @@ const createRestFulFetcher = (axiosInstance, document2, options) => {
|
|
|
143
140
|
}
|
|
144
141
|
const body = typeof args === "object" && args !== null && "body" in args ? args.body : void 0;
|
|
145
142
|
const params = typeof args === "object" && args !== null && "params" in args ? args.params : void 0;
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
let contentType = ERequestContentType.json;
|
|
144
|
+
if (headers == null ? void 0 : headers.contentType) contentType = headers.contentType;
|
|
145
|
+
else if (options == null ? void 0 : options.contentTypeResolver) contentType = options.contentTypeResolver(method.toUpperCase());
|
|
146
|
+
else if (document2.contentType) contentType = document2.contentType;
|
|
148
147
|
const config = {
|
|
149
148
|
url: document2.url,
|
|
150
149
|
method,
|