@module-federation/bridge-react 2.7.0 → 2.8.0
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/base.cjs.js +4 -4
- package/dist/base.d.ts +8 -311
- package/dist/base.es.js +5 -5
- package/dist/{bridge-base-CIOXqUYV.mjs → bridge-base-BaKy6CY_.mjs} +25 -92
- package/dist/{bridge-base-HLp3d7aF.js → bridge-base-Ch33UJuN.js} +25 -91
- package/dist/{createHelpers-DNBacpxb.js → createHelpers-19BP0xtB.js} +2 -3
- package/dist/{createHelpers-BY5Uj9_Z.mjs → createHelpers-BSHeKyd-.mjs} +2 -3
- package/dist/data-fetch-server-middleware.cjs.js +1 -1
- package/dist/data-fetch-server-middleware.d.ts +1 -15
- package/dist/data-fetch-server-middleware.es.js +1 -1
- package/dist/data-fetch-utils.cjs.js +2 -2
- package/dist/data-fetch-utils.d.ts +1 -81
- package/dist/data-fetch-utils.es.js +4 -4
- package/dist/data-fetch.cjs.js +3 -3
- package/dist/data-fetch.d.ts +4 -140
- package/dist/data-fetch.es.js +3 -3
- package/dist/error-boundary.d.ts +17 -0
- package/dist/error-boundary.spec.d.ts +1 -0
- package/dist/index.cjs.js +4 -4
- package/dist/index.d.ts +12 -299
- package/dist/index.es.js +5 -5
- package/dist/lazy/AwaitDataFetch.d.ts +24 -0
- package/dist/lazy/constant.d.ts +26 -0
- package/dist/lazy/createLazyComponent.d.ts +28 -0
- package/dist/lazy/data-fetch/cache.d.ts +34 -0
- package/dist/lazy/data-fetch/cache.spec.d.ts +1 -0
- package/dist/lazy/data-fetch/call-data-fetch.d.ts +1 -0
- package/dist/lazy/data-fetch/data-fetch-server-middleware.d.ts +3 -0
- package/dist/lazy/data-fetch/index.d.ts +6 -0
- package/dist/lazy/data-fetch/inject-data-fetch.d.ts +4 -0
- package/dist/lazy/data-fetch/prefetch.d.ts +9 -0
- package/dist/lazy/data-fetch/runtime-plugin.d.ts +3 -0
- package/dist/lazy/index.d.ts +9 -0
- package/dist/lazy/logger.d.ts +2 -0
- package/dist/lazy/types.d.ts +60 -0
- package/dist/lazy/utils.d.ts +48 -0
- package/dist/lazy/wrapNoSSR.d.ts +9 -0
- package/dist/{lazy-load-component-plugin-aj97Vt-4.mjs → lazy-load-component-plugin-DEu-DfZt.mjs} +2 -2
- package/dist/{lazy-load-component-plugin-BjMVNoep.js → lazy-load-component-plugin-FKp6nQa-.js} +2 -2
- package/dist/lazy-load-component-plugin.cjs.js +2 -2
- package/dist/lazy-load-component-plugin.d.ts +2 -16
- package/dist/lazy-load-component-plugin.es.js +2 -2
- package/dist/lazy-utils.cjs.js +1 -1
- package/dist/lazy-utils.d.ts +1 -149
- package/dist/lazy-utils.es.js +2 -2
- package/dist/plugin.d.ts +2 -22
- package/dist/plugins/lazy-load-component-plugin.d.ts +12 -0
- package/dist/plugins/lazy-load-component-plugin.spec.d.ts +1 -0
- package/dist/{prefetch-BwRDb4SJ.mjs → prefetch-CTZuFBqh.mjs} +314 -1
- package/dist/{prefetch-DLhPTofn.js → prefetch-D66kL1aM.js} +314 -1
- package/dist/provider/context.d.ts +3 -0
- package/dist/provider/plugin.d.ts +7 -0
- package/dist/provider/versions/bridge-base.d.ts +5 -0
- package/dist/provider/versions/legacy.d.ts +26 -0
- package/dist/provider/versions/v18.d.ts +19 -0
- package/dist/provider/versions/v19.d.ts +21 -0
- package/dist/remote/RemoteAppWrapper.d.ts +7 -0
- package/dist/remote/base-component/component.d.ts +2 -0
- package/dist/remote/base-component/create.d.ts +9 -0
- package/dist/remote/base-component/index.d.ts +5 -0
- package/dist/remote/createHelpers.d.ts +17 -0
- package/dist/remote/router-component/component.d.ts +8 -0
- package/dist/remote/router-component/create.d.ts +9 -0
- package/dist/remote/router-component/index.d.ts +5 -0
- package/dist/router/default.d.ts +7 -0
- package/dist/router/v5.d.ts +4 -0
- package/dist/router/v6.d.ts +7 -0
- package/dist/router/v7.d.ts +6 -0
- package/dist/router-v5.d.ts +1 -17
- package/dist/router-v6.d.ts +1 -20
- package/dist/router-v7.d.ts +1 -19
- package/dist/router.d.ts +1 -20
- package/dist/shared/size-limited-cache.d.ts +29 -0
- package/dist/shared/size-limited-cache.spec.d.ts +1 -0
- package/dist/size-limited-cache.cjs.js +82 -0
- package/dist/size-limited-cache.d.ts +1 -0
- package/dist/size-limited-cache.es.js +82 -0
- package/dist/types.d.ts +137 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils-5dGErM3C.js +588 -0
- package/dist/utils-BBP3hEeV.mjs +589 -0
- package/dist/v18.cjs.js +1 -1
- package/dist/v18.d.ts +3 -114
- package/dist/v18.es.js +1 -1
- package/dist/v19.cjs.js +1 -1
- package/dist/v19.d.ts +3 -115
- package/dist/v19.es.js +1 -1
- package/package.json +16 -11
- package/dist/utils-CFTy4LVE.js +0 -2029
- package/dist/utils-DGS4pYp8.mjs +0 -2030
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const logger$1 = require("./logger-Dxblx6P-.js");
|
|
3
|
+
const sizeLimitedCache = require("./size-limited-cache.cjs.js");
|
|
4
|
+
const LOG_CATEGORY = "[ Federation Runtime ]";
|
|
5
|
+
const composeKeyWithSeparator = function(...args) {
|
|
6
|
+
if (!args.length) return "";
|
|
7
|
+
return args.reduce((sum, cur) => {
|
|
8
|
+
if (!cur) return sum;
|
|
9
|
+
if (!sum) return cur;
|
|
10
|
+
return `${sum}${logger$1.SEPARATOR}${cur}`;
|
|
11
|
+
}, "");
|
|
12
|
+
};
|
|
13
|
+
const warn = (msg) => {
|
|
14
|
+
console.warn(`${LOG_CATEGORY}: ${msg}`);
|
|
15
|
+
};
|
|
16
|
+
function safeToString(info) {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.stringify(info, null, 2);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const PLUGIN_IDENTIFIER = "[ Module Federation React ]";
|
|
24
|
+
const DOWNGRADE_KEY = "_mfSSRDowngrade";
|
|
25
|
+
const DATA_FETCH_FUNCTION = "_mfDataFetch";
|
|
26
|
+
const FS_HREF = "_mfFSHref";
|
|
27
|
+
const ERROR_TYPE = {
|
|
28
|
+
DATA_FETCH: 1,
|
|
29
|
+
LOAD_REMOTE: 2,
|
|
30
|
+
UNKNOWN: 3
|
|
31
|
+
};
|
|
32
|
+
const WRAP_DATA_FETCH_ID_IDENTIFIER = "wrap_dfip_identifier";
|
|
33
|
+
var MF_DATA_FETCH_TYPE = /* @__PURE__ */ ((MF_DATA_FETCH_TYPE2) => {
|
|
34
|
+
MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_SERVER"] = 1] = "FETCH_SERVER";
|
|
35
|
+
MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_CLIENT"] = 2] = "FETCH_CLIENT";
|
|
36
|
+
return MF_DATA_FETCH_TYPE2;
|
|
37
|
+
})(MF_DATA_FETCH_TYPE || {});
|
|
38
|
+
var MF_DATA_FETCH_STATUS = /* @__PURE__ */ ((MF_DATA_FETCH_STATUS2) => {
|
|
39
|
+
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADED"] = 1] = "LOADED";
|
|
40
|
+
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADING"] = 2] = "LOADING";
|
|
41
|
+
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["AWAIT"] = 0] = "AWAIT";
|
|
42
|
+
MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["ERROR"] = 3] = "ERROR";
|
|
43
|
+
return MF_DATA_FETCH_STATUS2;
|
|
44
|
+
})(MF_DATA_FETCH_STATUS || {});
|
|
45
|
+
const DATA_FETCH_IDENTIFIER = "data";
|
|
46
|
+
const DATA_FETCH_CLIENT_SUFFIX = ".client";
|
|
47
|
+
const DATA_FETCH_QUERY = "x-mf-data-fetch";
|
|
48
|
+
const DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
|
|
49
|
+
const LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
|
|
50
|
+
const logger = logger$1.createLogger(PLUGIN_IDENTIFIER);
|
|
51
|
+
const CacheSize = {
|
|
52
|
+
KB: 1024,
|
|
53
|
+
MB: 1024 * 1024,
|
|
54
|
+
GB: 1024 * 1024 * 1024
|
|
55
|
+
};
|
|
56
|
+
const CacheTime = {
|
|
57
|
+
SECOND: 1e3,
|
|
58
|
+
MINUTE: 60 * 1e3,
|
|
59
|
+
HOUR: 60 * 60 * 1e3,
|
|
60
|
+
DAY: 24 * 60 * 60 * 1e3,
|
|
61
|
+
WEEK: 7 * 24 * 60 * 60 * 1e3,
|
|
62
|
+
MONTH: 30 * 24 * 60 * 60 * 1e3
|
|
63
|
+
};
|
|
64
|
+
function getTagKeyMap() {
|
|
65
|
+
const dataFetchCache = getDataFetchCache();
|
|
66
|
+
if (!dataFetchCache || !dataFetchCache.tagKeyMap) {
|
|
67
|
+
const tagKeyMap = /* @__PURE__ */ new Map();
|
|
68
|
+
globalThis.__MF_DATA_FETCH_CACHE__ || (globalThis.__MF_DATA_FETCH_CACHE__ = {});
|
|
69
|
+
globalThis.__MF_DATA_FETCH_CACHE__.tagKeyMap = tagKeyMap;
|
|
70
|
+
return tagKeyMap;
|
|
71
|
+
}
|
|
72
|
+
return dataFetchCache.tagKeyMap;
|
|
73
|
+
}
|
|
74
|
+
function addTagKeyRelation(tag, key) {
|
|
75
|
+
const tagKeyMap = getTagKeyMap();
|
|
76
|
+
let keys = tagKeyMap.get(tag);
|
|
77
|
+
if (!keys) {
|
|
78
|
+
keys = /* @__PURE__ */ new Set();
|
|
79
|
+
tagKeyMap.set(tag, keys);
|
|
80
|
+
}
|
|
81
|
+
keys.add(key);
|
|
82
|
+
}
|
|
83
|
+
function getCacheConfig() {
|
|
84
|
+
const dataFetchCache = getDataFetchCache();
|
|
85
|
+
if (!dataFetchCache || !dataFetchCache.cacheConfig) {
|
|
86
|
+
const cacheConfig = {
|
|
87
|
+
maxSize: CacheSize.GB
|
|
88
|
+
};
|
|
89
|
+
globalThis.__MF_DATA_FETCH_CACHE__ || (globalThis.__MF_DATA_FETCH_CACHE__ = {});
|
|
90
|
+
globalThis.__MF_DATA_FETCH_CACHE__.cacheConfig = cacheConfig;
|
|
91
|
+
return cacheConfig;
|
|
92
|
+
}
|
|
93
|
+
return dataFetchCache.cacheConfig;
|
|
94
|
+
}
|
|
95
|
+
function configureCache(config) {
|
|
96
|
+
const cacheConfig = getCacheConfig();
|
|
97
|
+
Object.assign(cacheConfig, config);
|
|
98
|
+
}
|
|
99
|
+
function getSizeLimitedCache() {
|
|
100
|
+
const dataFetchCache = getDataFetchCache();
|
|
101
|
+
const cacheConfig = getCacheConfig();
|
|
102
|
+
if (!dataFetchCache || !dataFetchCache.cacheStore) {
|
|
103
|
+
const cacheStore = new sizeLimitedCache.SizeLimitedCache({
|
|
104
|
+
maxSize: cacheConfig.maxSize ?? CacheSize.GB,
|
|
105
|
+
sizeCalculation: (value) => {
|
|
106
|
+
if (!value.size) {
|
|
107
|
+
return 1;
|
|
108
|
+
}
|
|
109
|
+
let size = 0;
|
|
110
|
+
for (const [k, item] of value.entries()) {
|
|
111
|
+
size += k.length * 2;
|
|
112
|
+
size += estimateObjectSize(item.data);
|
|
113
|
+
size += 8;
|
|
114
|
+
}
|
|
115
|
+
return size;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
globalThis.__MF_DATA_FETCH_CACHE__ || (globalThis.__MF_DATA_FETCH_CACHE__ = {});
|
|
119
|
+
globalThis.__MF_DATA_FETCH_CACHE__.cacheStore = cacheStore;
|
|
120
|
+
return cacheStore;
|
|
121
|
+
}
|
|
122
|
+
return dataFetchCache.cacheStore;
|
|
123
|
+
}
|
|
124
|
+
function estimateObjectSize(data) {
|
|
125
|
+
const type = typeof data;
|
|
126
|
+
if (type === "number") return 8;
|
|
127
|
+
if (type === "boolean") return 4;
|
|
128
|
+
if (type === "string") return Math.max(data.length * 2, 1);
|
|
129
|
+
if (data === null || data === void 0) return 1;
|
|
130
|
+
if (ArrayBuffer.isView(data)) {
|
|
131
|
+
return Math.max(data.byteLength, 1);
|
|
132
|
+
}
|
|
133
|
+
if (Array.isArray(data)) {
|
|
134
|
+
return Math.max(
|
|
135
|
+
data.reduce((acc, item) => acc + estimateObjectSize(item), 0),
|
|
136
|
+
1
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (data instanceof Map || data instanceof Set) {
|
|
140
|
+
return 1024;
|
|
141
|
+
}
|
|
142
|
+
if (data instanceof Date) {
|
|
143
|
+
return 8;
|
|
144
|
+
}
|
|
145
|
+
if (type === "object") {
|
|
146
|
+
return Math.max(
|
|
147
|
+
Object.entries(data).reduce(
|
|
148
|
+
(acc, [key, value]) => acc + key.length * 2 + estimateObjectSize(value),
|
|
149
|
+
0
|
|
150
|
+
),
|
|
151
|
+
1
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
return 1;
|
|
155
|
+
}
|
|
156
|
+
function generateKey(dataFetchOptions) {
|
|
157
|
+
return JSON.stringify(dataFetchOptions, (_, value) => {
|
|
158
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
159
|
+
return Object.keys(value).sort().reduce((result, key) => {
|
|
160
|
+
result[key] = value[key];
|
|
161
|
+
return result;
|
|
162
|
+
}, {});
|
|
163
|
+
}
|
|
164
|
+
return value;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function cache(fn, options) {
|
|
168
|
+
const {
|
|
169
|
+
tag = "default",
|
|
170
|
+
maxAge = CacheTime.MINUTE * 5,
|
|
171
|
+
revalidate = 0,
|
|
172
|
+
onCache,
|
|
173
|
+
getKey
|
|
174
|
+
} = options || {};
|
|
175
|
+
const tags = Array.isArray(tag) ? tag : [tag];
|
|
176
|
+
return async (dataFetchOptions) => {
|
|
177
|
+
if (dataFetchOptions.isDowngrade || !dataFetchOptions._id) {
|
|
178
|
+
return fn(dataFetchOptions);
|
|
179
|
+
}
|
|
180
|
+
const store = getSizeLimitedCache();
|
|
181
|
+
const now = Date.now();
|
|
182
|
+
const storeKey = dataFetchOptions._id;
|
|
183
|
+
const cacheKey = getKey ? getKey(dataFetchOptions) : generateKey(dataFetchOptions);
|
|
184
|
+
tags.forEach((t) => addTagKeyRelation(t, cacheKey));
|
|
185
|
+
let cacheStore = store.get(cacheKey);
|
|
186
|
+
if (!cacheStore) {
|
|
187
|
+
cacheStore = /* @__PURE__ */ new Map();
|
|
188
|
+
}
|
|
189
|
+
const cached = cacheStore.get(storeKey);
|
|
190
|
+
if (cached) {
|
|
191
|
+
const age = now - cached.timestamp;
|
|
192
|
+
if (age < maxAge) {
|
|
193
|
+
if (onCache) {
|
|
194
|
+
const useCache = onCache({
|
|
195
|
+
status: "hit",
|
|
196
|
+
key: cacheKey,
|
|
197
|
+
params: dataFetchOptions,
|
|
198
|
+
result: cached.data
|
|
199
|
+
});
|
|
200
|
+
if (!useCache) {
|
|
201
|
+
return fn(dataFetchOptions);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return cached.data;
|
|
205
|
+
}
|
|
206
|
+
if (revalidate > 0 && age < maxAge + revalidate) {
|
|
207
|
+
if (onCache) {
|
|
208
|
+
onCache({
|
|
209
|
+
status: "stale",
|
|
210
|
+
key: cacheKey,
|
|
211
|
+
params: dataFetchOptions,
|
|
212
|
+
result: cached.data
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (!cached.isRevalidating) {
|
|
216
|
+
cached.isRevalidating = true;
|
|
217
|
+
Promise.resolve().then(async () => {
|
|
218
|
+
try {
|
|
219
|
+
const newData = await fn(dataFetchOptions);
|
|
220
|
+
cacheStore.set(storeKey, {
|
|
221
|
+
data: newData,
|
|
222
|
+
timestamp: Date.now(),
|
|
223
|
+
isRevalidating: false
|
|
224
|
+
});
|
|
225
|
+
store.set(cacheKey, cacheStore);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
cached.isRevalidating = false;
|
|
228
|
+
console.error("Background revalidation failed:", error);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return cached.data;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const data = await fn(dataFetchOptions);
|
|
236
|
+
cacheStore.set(storeKey, {
|
|
237
|
+
data,
|
|
238
|
+
timestamp: now,
|
|
239
|
+
isRevalidating: false
|
|
240
|
+
});
|
|
241
|
+
store.set(cacheKey, cacheStore);
|
|
242
|
+
if (onCache) {
|
|
243
|
+
onCache({
|
|
244
|
+
status: "miss",
|
|
245
|
+
key: cacheKey,
|
|
246
|
+
params: dataFetchOptions,
|
|
247
|
+
result: data
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return data;
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function revalidateTag(tag) {
|
|
254
|
+
const tagKeyMap = getTagKeyMap();
|
|
255
|
+
const keys = tagKeyMap.get(tag);
|
|
256
|
+
const cacheStore = getSizeLimitedCache();
|
|
257
|
+
if (keys) {
|
|
258
|
+
keys.forEach((key) => {
|
|
259
|
+
cacheStore == null ? void 0 : cacheStore.delete(key);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function clearStore() {
|
|
264
|
+
var _a;
|
|
265
|
+
const cacheStore = getSizeLimitedCache();
|
|
266
|
+
const tagKeyMap = getTagKeyMap();
|
|
267
|
+
cacheStore == null ? void 0 : cacheStore.clear();
|
|
268
|
+
(_a = globalThis.__MF_DATA_FETCH_CACHE__) == null ? true : delete _a.cacheStore;
|
|
269
|
+
tagKeyMap.clear();
|
|
270
|
+
}
|
|
271
|
+
const getDataFetchInfo = ({
|
|
272
|
+
name,
|
|
273
|
+
alias,
|
|
274
|
+
id,
|
|
275
|
+
remoteSnapshot
|
|
276
|
+
}) => {
|
|
277
|
+
if (!remoteSnapshot) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (!("modules" in remoteSnapshot)) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const regex = new RegExp(`^${name}(/[^/].*|)$`);
|
|
284
|
+
const nameOrAlias = regex.test(id) ? name : alias || name;
|
|
285
|
+
const expose = id.replace(nameOrAlias, "");
|
|
286
|
+
let dataFetchName = "";
|
|
287
|
+
let dataFetchId = "";
|
|
288
|
+
let dataFetchKey = "";
|
|
289
|
+
if (expose.startsWith("/")) {
|
|
290
|
+
dataFetchName = `${expose.slice(1)}.${DATA_FETCH_IDENTIFIER}`;
|
|
291
|
+
dataFetchId = `${id}.${DATA_FETCH_IDENTIFIER}`;
|
|
292
|
+
dataFetchKey = `${name}${expose}.${DATA_FETCH_IDENTIFIER}`;
|
|
293
|
+
} else if (expose === "") {
|
|
294
|
+
dataFetchName = DATA_FETCH_IDENTIFIER;
|
|
295
|
+
dataFetchId = `${id}/${DATA_FETCH_IDENTIFIER}`;
|
|
296
|
+
dataFetchKey = `${name}/${DATA_FETCH_IDENTIFIER}`;
|
|
297
|
+
} else {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (!dataFetchName || !dataFetchId || !dataFetchKey) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (!remoteSnapshot.modules.find(
|
|
304
|
+
(module2) => module2.moduleName === dataFetchName
|
|
305
|
+
)) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
dataFetchName,
|
|
310
|
+
dataFetchId,
|
|
311
|
+
dataFetchKey
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
function initDataFetchMap() {
|
|
315
|
+
globalThis.__MF_DATA_FETCH_MAP__ || (globalThis.__MF_DATA_FETCH_MAP__ = {});
|
|
316
|
+
}
|
|
317
|
+
function getDataFetchItem(id) {
|
|
318
|
+
var _a;
|
|
319
|
+
return (_a = globalThis.__MF_DATA_FETCH_MAP__) == null ? void 0 : _a[id];
|
|
320
|
+
}
|
|
321
|
+
function getDataFetchMap() {
|
|
322
|
+
return globalThis.__MF_DATA_FETCH_MAP__;
|
|
323
|
+
}
|
|
324
|
+
function getDataFetchCache() {
|
|
325
|
+
return globalThis.__MF_DATA_FETCH_CACHE__;
|
|
326
|
+
}
|
|
327
|
+
const flushDataFetch = () => {
|
|
328
|
+
globalThis.__MF_DATA_FETCH_MAP__ = {};
|
|
329
|
+
globalThis[DOWNGRADE_KEY] = void 0;
|
|
330
|
+
clearStore();
|
|
331
|
+
};
|
|
332
|
+
function setDataFetchItemLoadedStatus(id) {
|
|
333
|
+
const dataFetchItem = getDataFetchItem(id);
|
|
334
|
+
if (!dataFetchItem) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
dataFetchItem[2] = MF_DATA_FETCH_STATUS.LOADED;
|
|
338
|
+
}
|
|
339
|
+
const wrapDataFetchId = (id) => {
|
|
340
|
+
return `${WRAP_DATA_FETCH_ID_IDENTIFIER}${id}${WRAP_DATA_FETCH_ID_IDENTIFIER}`;
|
|
341
|
+
};
|
|
342
|
+
const getDataFetchIdWithErrorMsgs = (errMsgs) => {
|
|
343
|
+
const firstIdentifierIndex = errMsgs.indexOf(WRAP_DATA_FETCH_ID_IDENTIFIER);
|
|
344
|
+
if (firstIdentifierIndex === -1) {
|
|
345
|
+
return void 0;
|
|
346
|
+
}
|
|
347
|
+
const secondIdentifierIndex = errMsgs.indexOf(
|
|
348
|
+
WRAP_DATA_FETCH_ID_IDENTIFIER,
|
|
349
|
+
firstIdentifierIndex + WRAP_DATA_FETCH_ID_IDENTIFIER.length
|
|
350
|
+
);
|
|
351
|
+
if (secondIdentifierIndex === -1) {
|
|
352
|
+
return void 0;
|
|
353
|
+
}
|
|
354
|
+
return errMsgs.substring(
|
|
355
|
+
firstIdentifierIndex + WRAP_DATA_FETCH_ID_IDENTIFIER.length,
|
|
356
|
+
secondIdentifierIndex
|
|
357
|
+
);
|
|
358
|
+
};
|
|
359
|
+
async function fetchData(id, params, remoteInfo) {
|
|
360
|
+
var _a;
|
|
361
|
+
const callFetchData = async () => {
|
|
362
|
+
const item = getDataFetchItem(id);
|
|
363
|
+
if (!item) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const [fetchDataFnArr, ..._rest] = item;
|
|
367
|
+
const fetchDataFn = await fetchDataFnArr[2];
|
|
368
|
+
if (!fetchDataFn) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
return fetchDataFn({
|
|
372
|
+
...params,
|
|
373
|
+
_id: id
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
if (logger$1.isBrowserEnvValue) {
|
|
377
|
+
const dataFetchItem = getDataFetchItem(id);
|
|
378
|
+
if (!dataFetchItem) {
|
|
379
|
+
throw new Error(`dataFetchItem not found, id: ${id}`);
|
|
380
|
+
}
|
|
381
|
+
if ((_a = dataFetchItem[1]) == null ? void 0 : _a[0]) {
|
|
382
|
+
return dataFetchItem[1][0];
|
|
383
|
+
}
|
|
384
|
+
if (isCSROnly()) {
|
|
385
|
+
logger.debug("==========csr only!");
|
|
386
|
+
return callFetchData();
|
|
387
|
+
}
|
|
388
|
+
if (remoteInfo) {
|
|
389
|
+
return callDowngrade(id, params, remoteInfo);
|
|
390
|
+
}
|
|
391
|
+
const mfDowngrade = getDowngradeTag();
|
|
392
|
+
if (mfDowngrade && (typeof mfDowngrade === "boolean" || mfDowngrade.includes(id))) {
|
|
393
|
+
return callDowngrade(id, { ...params, isDowngrade: true });
|
|
394
|
+
}
|
|
395
|
+
let res;
|
|
396
|
+
let rej;
|
|
397
|
+
const p = new Promise((resolve, reject) => {
|
|
398
|
+
res = resolve;
|
|
399
|
+
rej = reject;
|
|
400
|
+
});
|
|
401
|
+
dataFetchItem[1] = [p, res, rej];
|
|
402
|
+
dataFetchItem[2] = MF_DATA_FETCH_STATUS.AWAIT;
|
|
403
|
+
return dataFetchItem[1][0];
|
|
404
|
+
}
|
|
405
|
+
return callFetchData();
|
|
406
|
+
}
|
|
407
|
+
function getDataFetchMapKey(dataFetchInfo, hostInfo) {
|
|
408
|
+
if (!dataFetchInfo || !hostInfo) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const { dataFetchKey } = dataFetchInfo;
|
|
412
|
+
return composeKeyWithSeparator(dataFetchKey, hostInfo.name, hostInfo.version);
|
|
413
|
+
}
|
|
414
|
+
async function loadDataFetchModule(instance, id) {
|
|
415
|
+
return instance.loadRemote(id).then((m) => {
|
|
416
|
+
if (m && typeof m === "object" && "fetchData" in m && typeof m.fetchData === "function") {
|
|
417
|
+
return m.fetchData;
|
|
418
|
+
}
|
|
419
|
+
throw new Error(
|
|
420
|
+
`fetchData not found in remote ${id}, ${JSON.stringify(m)}`
|
|
421
|
+
);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function isDataLoaderExpose(exposeKey) {
|
|
425
|
+
return exposeKey.endsWith(DATA_FETCH_IDENTIFIER) || exposeKey.endsWith(DATA_FETCH_CLIENT_SUFFIX);
|
|
426
|
+
}
|
|
427
|
+
function getDowngradeTag() {
|
|
428
|
+
return globalThis[DOWNGRADE_KEY];
|
|
429
|
+
}
|
|
430
|
+
function callAllDowngrade() {
|
|
431
|
+
const dataFetchMap = getDataFetchMap();
|
|
432
|
+
if (!dataFetchMap) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
Object.keys(dataFetchMap).forEach((key) => {
|
|
436
|
+
callDowngrade(key);
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
async function callDowngrade(id, params, remoteInfo) {
|
|
440
|
+
const dataFetchMap = getDataFetchMap();
|
|
441
|
+
if (!dataFetchMap) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const mfDataFetch = dataFetchMap[id];
|
|
445
|
+
if ((mfDataFetch == null ? void 0 : mfDataFetch[2]) === MF_DATA_FETCH_STATUS.AWAIT) {
|
|
446
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADING;
|
|
447
|
+
let promise;
|
|
448
|
+
let res;
|
|
449
|
+
let rej;
|
|
450
|
+
if (mfDataFetch[1]) {
|
|
451
|
+
promise = mfDataFetch[1][0];
|
|
452
|
+
res = mfDataFetch[1][1];
|
|
453
|
+
rej = mfDataFetch[1][2];
|
|
454
|
+
} else {
|
|
455
|
+
promise = new Promise((resolve, reject) => {
|
|
456
|
+
res = resolve;
|
|
457
|
+
rej = reject;
|
|
458
|
+
});
|
|
459
|
+
mfDataFetch[1] = [promise, res, rej];
|
|
460
|
+
}
|
|
461
|
+
const dataFetchType = mfDataFetch[0][1];
|
|
462
|
+
if (dataFetchType === MF_DATA_FETCH_TYPE.FETCH_CLIENT) {
|
|
463
|
+
try {
|
|
464
|
+
mfDataFetch[0][0]().then(async (getDataFetchFn) => {
|
|
465
|
+
return getDataFetchFn({
|
|
466
|
+
...params,
|
|
467
|
+
isDowngrade: true,
|
|
468
|
+
_id: id
|
|
469
|
+
}).then((data) => {
|
|
470
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADED;
|
|
471
|
+
res && res(data);
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
} catch (e) {
|
|
475
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.ERROR;
|
|
476
|
+
rej && rej(e);
|
|
477
|
+
}
|
|
478
|
+
} else if (dataFetchType === MF_DATA_FETCH_TYPE.FETCH_SERVER) {
|
|
479
|
+
try {
|
|
480
|
+
const currentUrl = new URL(window.location.href);
|
|
481
|
+
currentUrl.searchParams.set(DATA_FETCH_QUERY, encodeURIComponent(id));
|
|
482
|
+
if (params) {
|
|
483
|
+
currentUrl.searchParams.set(
|
|
484
|
+
"params",
|
|
485
|
+
encodeURIComponent(JSON.stringify(params))
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
if (remoteInfo) {
|
|
489
|
+
currentUrl.searchParams.set(
|
|
490
|
+
"remoteInfo",
|
|
491
|
+
encodeURIComponent(JSON.stringify(remoteInfo))
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
const fetchServerQuery = globalThis.FEDERATION_SERVER_QUERY;
|
|
495
|
+
if (fetchServerQuery && typeof fetchServerQuery === "object") {
|
|
496
|
+
Object.keys(fetchServerQuery).forEach((key) => {
|
|
497
|
+
currentUrl.searchParams.set(
|
|
498
|
+
key,
|
|
499
|
+
JSON.stringify(fetchServerQuery[key])
|
|
500
|
+
);
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
const fetchUrl = currentUrl.toString();
|
|
504
|
+
const data = await fetch(fetchUrl).then((res2) => res2.json());
|
|
505
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADED;
|
|
506
|
+
res && res(data);
|
|
507
|
+
} catch (e) {
|
|
508
|
+
mfDataFetch[2] = MF_DATA_FETCH_STATUS.ERROR;
|
|
509
|
+
rej && rej(e);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return promise;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function isCSROnly() {
|
|
516
|
+
return window._SSR_DATA === void 0;
|
|
517
|
+
}
|
|
518
|
+
function isServerEnv() {
|
|
519
|
+
return typeof window === "undefined";
|
|
520
|
+
}
|
|
521
|
+
function setSSREnv({
|
|
522
|
+
fetchServerQuery
|
|
523
|
+
}) {
|
|
524
|
+
globalThis.FEDERATION_SSR = true;
|
|
525
|
+
globalThis.FEDERATION_SERVER_QUERY = fetchServerQuery;
|
|
526
|
+
}
|
|
527
|
+
function getLoadedRemoteInfos(id, instance) {
|
|
528
|
+
if (!instance) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
|
|
532
|
+
if (!name) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const module2 = instance.moduleCache.get(name);
|
|
536
|
+
if (!module2) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(
|
|
540
|
+
module2.remoteInfo
|
|
541
|
+
);
|
|
542
|
+
return {
|
|
543
|
+
...module2.remoteInfo,
|
|
544
|
+
snapshot: remoteSnapshot,
|
|
545
|
+
expose
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
exports.CacheSize = CacheSize;
|
|
549
|
+
exports.CacheTime = CacheTime;
|
|
550
|
+
exports.DATA_FETCH_CLIENT_SUFFIX = DATA_FETCH_CLIENT_SUFFIX;
|
|
551
|
+
exports.DATA_FETCH_ERROR_PREFIX = DATA_FETCH_ERROR_PREFIX;
|
|
552
|
+
exports.DATA_FETCH_FUNCTION = DATA_FETCH_FUNCTION;
|
|
553
|
+
exports.DATA_FETCH_QUERY = DATA_FETCH_QUERY;
|
|
554
|
+
exports.DOWNGRADE_KEY = DOWNGRADE_KEY;
|
|
555
|
+
exports.ERROR_TYPE = ERROR_TYPE;
|
|
556
|
+
exports.FS_HREF = FS_HREF;
|
|
557
|
+
exports.LOAD_REMOTE_ERROR_PREFIX = LOAD_REMOTE_ERROR_PREFIX;
|
|
558
|
+
exports.MF_DATA_FETCH_STATUS = MF_DATA_FETCH_STATUS;
|
|
559
|
+
exports.MF_DATA_FETCH_TYPE = MF_DATA_FETCH_TYPE;
|
|
560
|
+
exports.cache = cache;
|
|
561
|
+
exports.callAllDowngrade = callAllDowngrade;
|
|
562
|
+
exports.callDowngrade = callDowngrade;
|
|
563
|
+
exports.clearStore = clearStore;
|
|
564
|
+
exports.composeKeyWithSeparator = composeKeyWithSeparator;
|
|
565
|
+
exports.configureCache = configureCache;
|
|
566
|
+
exports.fetchData = fetchData;
|
|
567
|
+
exports.flushDataFetch = flushDataFetch;
|
|
568
|
+
exports.generateKey = generateKey;
|
|
569
|
+
exports.getDataFetchCache = getDataFetchCache;
|
|
570
|
+
exports.getDataFetchIdWithErrorMsgs = getDataFetchIdWithErrorMsgs;
|
|
571
|
+
exports.getDataFetchInfo = getDataFetchInfo;
|
|
572
|
+
exports.getDataFetchItem = getDataFetchItem;
|
|
573
|
+
exports.getDataFetchMap = getDataFetchMap;
|
|
574
|
+
exports.getDataFetchMapKey = getDataFetchMapKey;
|
|
575
|
+
exports.getDowngradeTag = getDowngradeTag;
|
|
576
|
+
exports.getLoadedRemoteInfos = getLoadedRemoteInfos;
|
|
577
|
+
exports.initDataFetchMap = initDataFetchMap;
|
|
578
|
+
exports.isCSROnly = isCSROnly;
|
|
579
|
+
exports.isDataLoaderExpose = isDataLoaderExpose;
|
|
580
|
+
exports.isServerEnv = isServerEnv;
|
|
581
|
+
exports.loadDataFetchModule = loadDataFetchModule;
|
|
582
|
+
exports.logger = logger;
|
|
583
|
+
exports.revalidateTag = revalidateTag;
|
|
584
|
+
exports.safeToString = safeToString;
|
|
585
|
+
exports.setDataFetchItemLoadedStatus = setDataFetchItemLoadedStatus;
|
|
586
|
+
exports.setSSREnv = setSSREnv;
|
|
587
|
+
exports.warn = warn;
|
|
588
|
+
exports.wrapDataFetchId = wrapDataFetchId;
|