fexios-browser 2.1.1 → 2.1.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/dist/chunk-4RAYGLHZ.js +34 -0
- package/dist/index.cjs +37 -4
- package/dist/index.js +9 -4
- package/dist/utils.cjs +54 -0
- package/dist/utils.d.cts +6 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +6 -0
- package/package.json +1 -1
@@ -0,0 +1,34 @@
|
|
1
|
+
// src/utils.ts
|
2
|
+
function useUtil() {
|
3
|
+
function normalizeHeaders(headers = {}) {
|
4
|
+
if (headers instanceof Headers) {
|
5
|
+
const normalized = {};
|
6
|
+
headers.forEach((value, key) => {
|
7
|
+
normalized[key] = value;
|
8
|
+
});
|
9
|
+
return normalized;
|
10
|
+
}
|
11
|
+
return headers;
|
12
|
+
}
|
13
|
+
function deepMerge(target, source) {
|
14
|
+
const result = { ...target };
|
15
|
+
for (const key in source) {
|
16
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
17
|
+
if (typeof target[key] === "object" && typeof source[key] === "object" && target[key] !== null && source[key] !== null) {
|
18
|
+
result[key] = deepMerge(target[key], source[key]);
|
19
|
+
} else {
|
20
|
+
result[key] = source[key];
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
return result;
|
25
|
+
}
|
26
|
+
return {
|
27
|
+
normalizeHeaders,
|
28
|
+
deepMerge
|
29
|
+
};
|
30
|
+
}
|
31
|
+
|
32
|
+
export {
|
33
|
+
useUtil
|
34
|
+
};
|
package/dist/index.cjs
CHANGED
@@ -86,6 +86,37 @@ var InterceptorManager = class {
|
|
86
86
|
};
|
87
87
|
var InterceptorManager_default = InterceptorManager;
|
88
88
|
|
89
|
+
// src/utils.ts
|
90
|
+
function useUtil() {
|
91
|
+
function normalizeHeaders(headers = {}) {
|
92
|
+
if (headers instanceof Headers) {
|
93
|
+
const normalized = {};
|
94
|
+
headers.forEach((value, key) => {
|
95
|
+
normalized[key] = value;
|
96
|
+
});
|
97
|
+
return normalized;
|
98
|
+
}
|
99
|
+
return headers;
|
100
|
+
}
|
101
|
+
function deepMerge(target, source) {
|
102
|
+
const result = { ...target };
|
103
|
+
for (const key in source) {
|
104
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
105
|
+
if (typeof target[key] === "object" && typeof source[key] === "object" && target[key] !== null && source[key] !== null) {
|
106
|
+
result[key] = deepMerge(target[key], source[key]);
|
107
|
+
} else {
|
108
|
+
result[key] = source[key];
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
return result;
|
113
|
+
}
|
114
|
+
return {
|
115
|
+
normalizeHeaders,
|
116
|
+
deepMerge
|
117
|
+
};
|
118
|
+
}
|
119
|
+
|
89
120
|
// src/index.ts
|
90
121
|
var Fexios = class {
|
91
122
|
// 没有请求数据
|
@@ -130,15 +161,17 @@ var Fexios = class {
|
|
130
161
|
});
|
131
162
|
}
|
132
163
|
async request(config) {
|
164
|
+
const { deepMerge, normalizeHeaders } = useUtil();
|
133
165
|
config.headers = config.headers || {};
|
134
166
|
const mergedRequest = {
|
135
167
|
...this.defaults,
|
136
168
|
...config,
|
137
|
-
headers:
|
138
|
-
|
139
|
-
|
140
|
-
|
169
|
+
headers: deepMerge(
|
170
|
+
normalizeHeaders(this.defaults.headers),
|
171
|
+
normalizeHeaders(config.headers)
|
172
|
+
)
|
141
173
|
};
|
174
|
+
console.log(mergedRequest);
|
142
175
|
let chain = [dispatchRequest, void 0];
|
143
176
|
this.interceptors.request.forEach((interceptor) => {
|
144
177
|
interceptor.onFulfilled;
|
package/dist/index.js
CHANGED
@@ -4,6 +4,9 @@ import {
|
|
4
4
|
import {
|
5
5
|
InterceptorManager_default
|
6
6
|
} from "./chunk-HIR6OZ3W.js";
|
7
|
+
import {
|
8
|
+
useUtil
|
9
|
+
} from "./chunk-4RAYGLHZ.js";
|
7
10
|
|
8
11
|
// src/index.ts
|
9
12
|
var Fexios = class {
|
@@ -49,15 +52,17 @@ var Fexios = class {
|
|
49
52
|
});
|
50
53
|
}
|
51
54
|
async request(config) {
|
55
|
+
const { deepMerge, normalizeHeaders } = useUtil();
|
52
56
|
config.headers = config.headers || {};
|
53
57
|
const mergedRequest = {
|
54
58
|
...this.defaults,
|
55
59
|
...config,
|
56
|
-
headers:
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
headers: deepMerge(
|
61
|
+
normalizeHeaders(this.defaults.headers),
|
62
|
+
normalizeHeaders(config.headers)
|
63
|
+
)
|
60
64
|
};
|
65
|
+
console.log(mergedRequest);
|
61
66
|
let chain = [dispatchRequest, void 0];
|
62
67
|
this.interceptors.request.forEach((interceptor) => {
|
63
68
|
interceptor.onFulfilled;
|
package/dist/utils.cjs
ADDED
@@ -0,0 +1,54 @@
|
|
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.ts
|
21
|
+
var utils_exports = {};
|
22
|
+
__export(utils_exports, {
|
23
|
+
default: () => useUtil
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(utils_exports);
|
26
|
+
function useUtil() {
|
27
|
+
function normalizeHeaders(headers = {}) {
|
28
|
+
if (headers instanceof Headers) {
|
29
|
+
const normalized = {};
|
30
|
+
headers.forEach((value, key) => {
|
31
|
+
normalized[key] = value;
|
32
|
+
});
|
33
|
+
return normalized;
|
34
|
+
}
|
35
|
+
return headers;
|
36
|
+
}
|
37
|
+
function deepMerge(target, source) {
|
38
|
+
const result = { ...target };
|
39
|
+
for (const key in source) {
|
40
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
41
|
+
if (typeof target[key] === "object" && typeof source[key] === "object" && target[key] !== null && source[key] !== null) {
|
42
|
+
result[key] = deepMerge(target[key], source[key]);
|
43
|
+
} else {
|
44
|
+
result[key] = source[key];
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
return result;
|
49
|
+
}
|
50
|
+
return {
|
51
|
+
normalizeHeaders,
|
52
|
+
deepMerge
|
53
|
+
};
|
54
|
+
}
|
package/dist/utils.d.cts
ADDED
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED