@module-federation/bridge-react 0.0.0-next-20250708121428 → 0.0.0-next-20250709032753

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +4 -8
  2. package/__tests__/bridge.spec.tsx +7 -7
  3. package/dist/{bridge-base-UGCwcMnG.js → bridge-base-BBH982Tz.cjs} +1 -1
  4. package/dist/{bridge-base-BoshEggF.mjs → bridge-base-P6pEjY1q.js} +1 -1
  5. package/dist/index-Cv3p6r66.cjs +235 -0
  6. package/dist/index-D4yt7Udv.js +236 -0
  7. package/dist/index.cjs.js +9 -35
  8. package/dist/index.d.ts +0 -143
  9. package/dist/index.es.js +12 -38
  10. package/dist/plugin.d.ts +0 -9
  11. package/dist/router-v5.cjs.js +1 -1
  12. package/dist/router-v5.d.ts +0 -9
  13. package/dist/router-v5.es.js +1 -1
  14. package/dist/router-v6.cjs.js +1 -1
  15. package/dist/router-v6.d.ts +0 -9
  16. package/dist/router-v6.es.js +1 -1
  17. package/dist/router.cjs.js +1 -1
  18. package/dist/router.d.ts +0 -9
  19. package/dist/router.es.js +1 -1
  20. package/dist/v18.cjs.js +1 -1
  21. package/dist/v18.d.ts +0 -9
  22. package/dist/v18.es.js +1 -1
  23. package/dist/v19.cjs.js +1 -1
  24. package/dist/v19.d.ts +0 -9
  25. package/dist/v19.es.js +1 -1
  26. package/package.json +5 -46
  27. package/src/.eslintrc.js +9 -0
  28. package/src/index.ts +1 -32
  29. package/src/remote/component.tsx +3 -3
  30. package/src/remote/create.tsx +4 -17
  31. package/tsconfig.json +1 -1
  32. package/vite.config.ts +0 -13
  33. package/dist/data-fetch-server-middleware.cjs.js +0 -163
  34. package/dist/data-fetch-server-middleware.d.ts +0 -15
  35. package/dist/data-fetch-server-middleware.es.js +0 -164
  36. package/dist/data-fetch-utils.cjs.js +0 -24
  37. package/dist/data-fetch-utils.d.ts +0 -86
  38. package/dist/data-fetch-utils.es.js +0 -26
  39. package/dist/index-C0fDZB5b.js +0 -45
  40. package/dist/index-CqxytsLY.mjs +0 -46
  41. package/dist/index.esm-BCeUd-x9.mjs +0 -418
  42. package/dist/index.esm-j_1sIRzg.js +0 -417
  43. package/dist/lazy-load-component-plugin-BbqmMGKu.mjs +0 -492
  44. package/dist/lazy-load-component-plugin-DgYHamxE.js +0 -491
  45. package/dist/lazy-load-component-plugin.cjs.js +0 -6
  46. package/dist/lazy-load-component-plugin.d.ts +0 -16
  47. package/dist/lazy-load-component-plugin.es.js +0 -6
  48. package/dist/lazy-utils.cjs.js +0 -24
  49. package/dist/lazy-utils.d.ts +0 -149
  50. package/dist/lazy-utils.es.js +0 -24
  51. package/dist/prefetch-BWabXlKU.js +0 -1332
  52. package/dist/prefetch-CXJhiNUD.mjs +0 -1333
  53. package/dist/utils-BTYYwZcb.mjs +0 -2016
  54. package/dist/utils-iEVlDmyk.js +0 -2015
  55. package/src/lazy/AwaitDataFetch.tsx +0 -215
  56. package/src/lazy/constant.ts +0 -30
  57. package/src/lazy/createLazyComponent.tsx +0 -418
  58. package/src/lazy/data-fetch/cache.ts +0 -296
  59. package/src/lazy/data-fetch/call-data-fetch.ts +0 -13
  60. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +0 -196
  61. package/src/lazy/data-fetch/index.ts +0 -16
  62. package/src/lazy/data-fetch/inject-data-fetch.ts +0 -109
  63. package/src/lazy/data-fetch/prefetch.ts +0 -106
  64. package/src/lazy/data-fetch/runtime-plugin.ts +0 -115
  65. package/src/lazy/index.ts +0 -35
  66. package/src/lazy/logger.ts +0 -6
  67. package/src/lazy/types.ts +0 -75
  68. package/src/lazy/utils.ts +0 -372
  69. package/src/lazy/wrapNoSSR.tsx +0 -10
  70. package/src/plugins/lazy-load-component-plugin.ts +0 -62
@@ -16,7 +16,7 @@ function createLazyRemoteComponent<
16
16
  >(info: LazyRemoteComponentInfo<T, E>) {
17
17
  const exportName = info?.export || 'default';
18
18
  return React.lazy(async () => {
19
- LoggerInstance.debug(`createRemoteAppComponent LazyComponent create >>>`, {
19
+ LoggerInstance.debug(`createRemoteComponent LazyComponent create >>>`, {
20
20
  lazyComponent: info.loader,
21
21
  exportName,
22
22
  });
@@ -26,7 +26,7 @@ function createLazyRemoteComponent<
26
26
  // @ts-ignore
27
27
  const moduleName = m && m[Symbol.for('mf_module_id')];
28
28
  LoggerInstance.debug(
29
- `createRemoteAppComponent LazyComponent loadRemote info >>>`,
29
+ `createRemoteComponent LazyComponent loadRemote info >>>`,
30
30
  { name: moduleName, module: m, exportName },
31
31
  );
32
32
 
@@ -55,7 +55,7 @@ function createLazyRemoteComponent<
55
55
  };
56
56
  } else {
57
57
  LoggerInstance.debug(
58
- `createRemoteAppComponent LazyComponent module not found >>>`,
58
+ `createRemoteComponent LazyComponent module not found >>>`,
59
59
  { name: moduleName, module: m, exportName },
60
60
  );
61
61
  throw Error(
@@ -70,7 +70,7 @@ function createLazyRemoteComponent<
70
70
  });
71
71
  }
72
72
 
73
- export function createRemoteAppComponent<
73
+ export function createRemoteComponent<
74
74
  T = Record<string, unknown>,
75
75
  E extends keyof T = keyof T,
76
76
  >(info: LazyRemoteComponentInfo<T, E>) {
@@ -87,16 +87,3 @@ export function createRemoteAppComponent<
87
87
  );
88
88
  });
89
89
  }
90
-
91
- /**
92
- * @deprecated createRemoteAppComponent is deprecated, please use createRemoteAppComponent instead!
93
- */
94
- export function createRemoteComponent<
95
- T = Record<string, unknown>,
96
- E extends keyof T = keyof T,
97
- >(info: LazyRemoteComponentInfo<T, E>) {
98
- LoggerInstance.warn(
99
- `createRemoteAppComponent is deprecated, please use createRemoteAppComponent instead!`,
100
- );
101
- return createRemoteAppComponent(info);
102
- }
package/tsconfig.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "declarationDir": "./dist/types",
10
10
  "rootDir": "./src",
11
11
  "module": "commonjs",
12
- "target": "es2015",
12
+ "target": "es5",
13
13
 
14
14
  /* Linting */
15
15
  "noUnusedLocals": true,
package/vite.config.ts CHANGED
@@ -26,19 +26,6 @@ export default defineConfig({
26
26
  'router-v6': path.resolve(__dirname, 'src/router/v6.tsx'),
27
27
  v18: path.resolve(__dirname, 'src/v18.ts'),
28
28
  v19: path.resolve(__dirname, 'src/v19.ts'),
29
- 'lazy-load-component-plugin': path.resolve(
30
- __dirname,
31
- 'src/plugins/lazy-load-component-plugin.ts',
32
- ),
33
- 'data-fetch-server-middleware': path.resolve(
34
- __dirname,
35
- 'src/lazy/data-fetch/data-fetch-server-middleware.ts',
36
- ),
37
- 'lazy-utils': path.resolve(__dirname, 'src/lazy/utils.ts'),
38
- 'data-fetch-utils': path.resolve(
39
- __dirname,
40
- 'src/lazy/data-fetch/index.ts',
41
- ),
42
29
  },
43
30
  formats: ['cjs', 'es'],
44
31
  fileName: (format, entryName) => `${entryName}.${format}.js`,
@@ -1,163 +0,0 @@
1
- "use strict";
2
- const lazyUtils = require("./utils-iEVlDmyk.js");
3
- const index_esm = require("./index.esm-j_1sIRzg.js");
4
- function wrapSetTimeout(targetPromise, delay = 2e4, id) {
5
- if (targetPromise && typeof targetPromise.then === "function") {
6
- return new Promise((resolve, reject) => {
7
- const timeoutId = setTimeout(() => {
8
- lazyUtils.logger.warn(`Data fetch for ID ${id} timed out after 20 seconds.`);
9
- reject(new Error(`Data fetch for ID ${id} timed out after 20 seconds`));
10
- }, delay);
11
- targetPromise.then((value) => {
12
- clearTimeout(timeoutId);
13
- resolve(value);
14
- }).catch((err) => {
15
- clearTimeout(timeoutId);
16
- reject(err);
17
- });
18
- });
19
- }
20
- }
21
- function addProtocol(url) {
22
- if (url.startsWith("//")) {
23
- return "https:" + url;
24
- }
25
- return url;
26
- }
27
- const getDecodeQuery = (url, name) => {
28
- const res = url.searchParams.get(name);
29
- if (!res) {
30
- return null;
31
- }
32
- return decodeURIComponent(res);
33
- };
34
- const dataFetchServerMiddleware = async (ctx, next) => {
35
- var _a, _b, _c;
36
- let url;
37
- let dataFetchKey;
38
- let params;
39
- let remoteInfo;
40
- try {
41
- url = new URL(ctx.req.url);
42
- dataFetchKey = getDecodeQuery(url, lazyUtils.DATA_FETCH_QUERY);
43
- params = JSON.parse(getDecodeQuery(url, "params") || "{}");
44
- const remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
45
- remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
46
- } catch (e) {
47
- lazyUtils.logger.error("fetch data from server, error: ", e);
48
- return next();
49
- }
50
- if (!dataFetchKey) {
51
- return next();
52
- }
53
- lazyUtils.logger.log("fetch data from server, dataFetchKey: ", dataFetchKey);
54
- lazyUtils.logger.debug(
55
- "fetch data from server, moduleInfo: ",
56
- (_a = globalThis.__FEDERATION__) == null ? void 0 : _a.moduleInfo
57
- );
58
- try {
59
- const dataFetchMap = lazyUtils.getDataFetchMap();
60
- if (!dataFetchMap) {
61
- lazyUtils.initDataFetchMap();
62
- }
63
- const fetchDataPromise = (_b = dataFetchMap[dataFetchKey]) == null ? void 0 : _b[1];
64
- lazyUtils.logger.debug(
65
- "fetch data from server, fetchDataPromise: ",
66
- fetchDataPromise
67
- );
68
- if (fetchDataPromise && ((_c = dataFetchMap[dataFetchKey]) == null ? void 0 : _c[2]) !== lazyUtils.MF_DATA_FETCH_STATUS.ERROR) {
69
- const targetPromise = fetchDataPromise[0];
70
- const wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchKey);
71
- if (wrappedPromise) {
72
- const res = await wrappedPromise;
73
- lazyUtils.logger.log("fetch data from server, fetchDataPromise res: ", res);
74
- return ctx.json(res);
75
- }
76
- lazyUtils.logger.error(
77
- `Expected a Promise from fetchDataPromise[0] for dataFetchKey ${dataFetchKey}, but received:`,
78
- targetPromise,
79
- "Will try call new dataFetch again..."
80
- );
81
- }
82
- if (remoteInfo) {
83
- try {
84
- const hostInstance2 = globalThis.__FEDERATION__.__INSTANCES__[0];
85
- const remoteEntry = `${addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry}`;
86
- if (!hostInstance2) {
87
- throw new Error("host instance not found!");
88
- }
89
- const remote = hostInstance2.options.remotes.find(
90
- (remote2) => remote2.name === remoteInfo.name
91
- );
92
- lazyUtils.logger.debug("find remote: ", JSON.stringify(remote));
93
- if (!remote) {
94
- hostInstance2.registerRemotes([
95
- {
96
- name: remoteInfo.name,
97
- entry: remoteEntry,
98
- entryGlobalName: remoteInfo.globalName
99
- }
100
- ]);
101
- } else if (!("entry" in remote) || !remote.entry.includes(index_esm.MANIFEST_EXT)) {
102
- const { hostGlobalSnapshot, remoteSnapshot } = hostInstance2.snapshotHandler.getGlobalRemoteInfo(remoteInfo);
103
- lazyUtils.logger.debug(
104
- "find hostGlobalSnapshot: ",
105
- JSON.stringify(hostGlobalSnapshot)
106
- );
107
- lazyUtils.logger.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
108
- if (!hostGlobalSnapshot || !remoteSnapshot) {
109
- if ("version" in remote) {
110
- delete remote.version;
111
- }
112
- remote.entry = remoteEntry;
113
- remote.entryGlobalName = remoteInfo.globalName;
114
- }
115
- }
116
- } catch (e) {
117
- ctx.status(500);
118
- return ctx.text(
119
- `failed to fetch ${remoteInfo.name} data, error:
120
- ${e}`
121
- );
122
- }
123
- }
124
- const dataFetchItem = dataFetchMap[dataFetchKey];
125
- lazyUtils.logger.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
126
- if (dataFetchItem) {
127
- const callFetchDataPromise = lazyUtils.fetchData(dataFetchKey, {
128
- ...params,
129
- isDowngrade: !remoteInfo,
130
- _id: dataFetchKey
131
- });
132
- const wrappedPromise = wrapSetTimeout(
133
- callFetchDataPromise,
134
- 2e4,
135
- dataFetchKey
136
- );
137
- if (wrappedPromise) {
138
- const res = await wrappedPromise;
139
- lazyUtils.logger.log("fetch data from server, dataFetchItem res: ", res);
140
- return ctx.json(res);
141
- }
142
- }
143
- const remoteId = dataFetchKey.split(index_esm.SEPARATOR)[0];
144
- const hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
145
- if (!hostInstance) {
146
- throw new Error("host instance not found!");
147
- }
148
- const dataFetchFn = await lazyUtils.loadDataFetchModule(hostInstance, remoteId);
149
- const data = await dataFetchFn({
150
- ...params,
151
- isDowngrade: !remoteInfo,
152
- _id: dataFetchKey
153
- });
154
- lazyUtils.logger.log("fetch data from server, loadDataFetchModule res: ", data);
155
- return ctx.json(data);
156
- } catch (e) {
157
- lazyUtils.logger.error("server plugin data fetch error: ", e);
158
- ctx.status(500);
159
- return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
160
- ${e}`);
161
- }
162
- };
163
- module.exports = dataFetchServerMiddleware;
@@ -1,15 +0,0 @@
1
- import { MiddlewareHandler } from 'hono';
2
-
3
- declare const dataFetchServerMiddleware: MiddlewareHandler;
4
- export default dataFetchServerMiddleware;
5
-
6
- export { }
7
-
8
-
9
- declare module '@module-federation/runtime-core' {
10
- interface FederationHost {
11
- createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
12
- prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
13
- collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
14
- }
15
- }
@@ -1,164 +0,0 @@
1
- import { D as DATA_FETCH_QUERY, l as logger, g as getDataFetchMap, i as initDataFetchMap, M as MF_DATA_FETCH_STATUS, f as fetchData, a as loadDataFetchModule } from "./utils-BTYYwZcb.mjs";
2
- import { M as MANIFEST_EXT, S as SEPARATOR } from "./index.esm-BCeUd-x9.mjs";
3
- function wrapSetTimeout(targetPromise, delay = 2e4, id) {
4
- if (targetPromise && typeof targetPromise.then === "function") {
5
- return new Promise((resolve, reject) => {
6
- const timeoutId = setTimeout(() => {
7
- logger.warn(`Data fetch for ID ${id} timed out after 20 seconds.`);
8
- reject(new Error(`Data fetch for ID ${id} timed out after 20 seconds`));
9
- }, delay);
10
- targetPromise.then((value) => {
11
- clearTimeout(timeoutId);
12
- resolve(value);
13
- }).catch((err) => {
14
- clearTimeout(timeoutId);
15
- reject(err);
16
- });
17
- });
18
- }
19
- }
20
- function addProtocol(url) {
21
- if (url.startsWith("//")) {
22
- return "https:" + url;
23
- }
24
- return url;
25
- }
26
- const getDecodeQuery = (url, name) => {
27
- const res = url.searchParams.get(name);
28
- if (!res) {
29
- return null;
30
- }
31
- return decodeURIComponent(res);
32
- };
33
- const dataFetchServerMiddleware = async (ctx, next) => {
34
- var _a, _b, _c;
35
- let url;
36
- let dataFetchKey;
37
- let params;
38
- let remoteInfo;
39
- try {
40
- url = new URL(ctx.req.url);
41
- dataFetchKey = getDecodeQuery(url, DATA_FETCH_QUERY);
42
- params = JSON.parse(getDecodeQuery(url, "params") || "{}");
43
- const remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
44
- remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
45
- } catch (e) {
46
- logger.error("fetch data from server, error: ", e);
47
- return next();
48
- }
49
- if (!dataFetchKey) {
50
- return next();
51
- }
52
- logger.log("fetch data from server, dataFetchKey: ", dataFetchKey);
53
- logger.debug(
54
- "fetch data from server, moduleInfo: ",
55
- (_a = globalThis.__FEDERATION__) == null ? void 0 : _a.moduleInfo
56
- );
57
- try {
58
- const dataFetchMap = getDataFetchMap();
59
- if (!dataFetchMap) {
60
- initDataFetchMap();
61
- }
62
- const fetchDataPromise = (_b = dataFetchMap[dataFetchKey]) == null ? void 0 : _b[1];
63
- logger.debug(
64
- "fetch data from server, fetchDataPromise: ",
65
- fetchDataPromise
66
- );
67
- if (fetchDataPromise && ((_c = dataFetchMap[dataFetchKey]) == null ? void 0 : _c[2]) !== MF_DATA_FETCH_STATUS.ERROR) {
68
- const targetPromise = fetchDataPromise[0];
69
- const wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchKey);
70
- if (wrappedPromise) {
71
- const res = await wrappedPromise;
72
- logger.log("fetch data from server, fetchDataPromise res: ", res);
73
- return ctx.json(res);
74
- }
75
- logger.error(
76
- `Expected a Promise from fetchDataPromise[0] for dataFetchKey ${dataFetchKey}, but received:`,
77
- targetPromise,
78
- "Will try call new dataFetch again..."
79
- );
80
- }
81
- if (remoteInfo) {
82
- try {
83
- const hostInstance2 = globalThis.__FEDERATION__.__INSTANCES__[0];
84
- const remoteEntry = `${addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry}`;
85
- if (!hostInstance2) {
86
- throw new Error("host instance not found!");
87
- }
88
- const remote = hostInstance2.options.remotes.find(
89
- (remote2) => remote2.name === remoteInfo.name
90
- );
91
- logger.debug("find remote: ", JSON.stringify(remote));
92
- if (!remote) {
93
- hostInstance2.registerRemotes([
94
- {
95
- name: remoteInfo.name,
96
- entry: remoteEntry,
97
- entryGlobalName: remoteInfo.globalName
98
- }
99
- ]);
100
- } else if (!("entry" in remote) || !remote.entry.includes(MANIFEST_EXT)) {
101
- const { hostGlobalSnapshot, remoteSnapshot } = hostInstance2.snapshotHandler.getGlobalRemoteInfo(remoteInfo);
102
- logger.debug(
103
- "find hostGlobalSnapshot: ",
104
- JSON.stringify(hostGlobalSnapshot)
105
- );
106
- logger.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
107
- if (!hostGlobalSnapshot || !remoteSnapshot) {
108
- if ("version" in remote) {
109
- delete remote.version;
110
- }
111
- remote.entry = remoteEntry;
112
- remote.entryGlobalName = remoteInfo.globalName;
113
- }
114
- }
115
- } catch (e) {
116
- ctx.status(500);
117
- return ctx.text(
118
- `failed to fetch ${remoteInfo.name} data, error:
119
- ${e}`
120
- );
121
- }
122
- }
123
- const dataFetchItem = dataFetchMap[dataFetchKey];
124
- logger.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
125
- if (dataFetchItem) {
126
- const callFetchDataPromise = fetchData(dataFetchKey, {
127
- ...params,
128
- isDowngrade: !remoteInfo,
129
- _id: dataFetchKey
130
- });
131
- const wrappedPromise = wrapSetTimeout(
132
- callFetchDataPromise,
133
- 2e4,
134
- dataFetchKey
135
- );
136
- if (wrappedPromise) {
137
- const res = await wrappedPromise;
138
- logger.log("fetch data from server, dataFetchItem res: ", res);
139
- return ctx.json(res);
140
- }
141
- }
142
- const remoteId = dataFetchKey.split(SEPARATOR)[0];
143
- const hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
144
- if (!hostInstance) {
145
- throw new Error("host instance not found!");
146
- }
147
- const dataFetchFn = await loadDataFetchModule(hostInstance, remoteId);
148
- const data = await dataFetchFn({
149
- ...params,
150
- isDowngrade: !remoteInfo,
151
- _id: dataFetchKey
152
- });
153
- logger.log("fetch data from server, loadDataFetchModule res: ", data);
154
- return ctx.json(data);
155
- } catch (e) {
156
- logger.error("server plugin data fetch error: ", e);
157
- ctx.status(500);
158
- return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
159
- ${e}`);
160
- }
161
- };
162
- export {
163
- dataFetchServerMiddleware as default
164
- };
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const lazyUtils = require("./utils-iEVlDmyk.js");
4
- const prefetch = require("./prefetch-BWabXlKU.js");
5
- async function callDataFetch() {
6
- const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
7
- if (dataFetch) {
8
- await Promise.all(
9
- dataFetch.map(async (options) => {
10
- await prefetch.dataFetchFunction(options);
11
- })
12
- );
13
- }
14
- }
15
- exports.CacheSize = lazyUtils.CacheSize;
16
- exports.CacheTime = lazyUtils.CacheTime;
17
- exports.cache = lazyUtils.cache;
18
- exports.clearStore = lazyUtils.clearStore;
19
- exports.configureCache = lazyUtils.configureCache;
20
- exports.generateKey = lazyUtils.generateKey;
21
- exports.revalidateTag = lazyUtils.revalidateTag;
22
- exports.injectDataFetch = prefetch.injectDataFetch;
23
- exports.prefetch = prefetch.prefetch;
24
- exports.callDataFetch = callDataFetch;
@@ -1,86 +0,0 @@
1
- import { getInstance } from '@module-federation/runtime';
2
-
3
- export declare function cache<T>(fn: DataFetch<T>, options?: CacheOptions): DataFetch<T>;
4
-
5
- declare interface CacheConfig {
6
- maxSize?: number;
7
- unstable_shouldDisable?: ({ request, }: {
8
- request: Request;
9
- }) => boolean | Promise<boolean>;
10
- }
11
-
12
- declare interface CacheOptions {
13
- tag?: string | string[];
14
- maxAge?: number;
15
- revalidate?: number;
16
- getKey?: <Args extends any[]>(...args: Args) => string;
17
- customKey?: <Args extends any[]>(options: {
18
- params: Args;
19
- fn: (...args: Args) => any;
20
- generatedKey: string;
21
- }) => string | symbol;
22
- onCache?: (info: CacheStatsInfo) => boolean;
23
- }
24
-
25
- export declare const CacheSize: {
26
- readonly KB: 1024;
27
- readonly MB: number;
28
- readonly GB: number;
29
- };
30
-
31
- export declare interface CacheStatsInfo {
32
- status: CacheStatus;
33
- key: string | symbol;
34
- params: DataFetchParams;
35
- result: any;
36
- }
37
-
38
- export declare type CacheStatus = 'hit' | 'stale' | 'miss';
39
-
40
- export declare const CacheTime: {
41
- readonly SECOND: 1000;
42
- readonly MINUTE: number;
43
- readonly HOUR: number;
44
- readonly DAY: number;
45
- readonly WEEK: number;
46
- readonly MONTH: number;
47
- };
48
-
49
- export declare function callDataFetch(): Promise<void>;
50
-
51
- export declare function clearStore(): void;
52
-
53
- export declare function configureCache(config: CacheConfig): void;
54
-
55
- declare type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
56
-
57
- declare type DataFetchParams = {
58
- isDowngrade: boolean;
59
- _id?: string;
60
- } & Record<string, unknown>;
61
-
62
- export declare function generateKey(dataFetchOptions: DataFetchParams): string;
63
-
64
- export declare function injectDataFetch(): void;
65
-
66
- export declare function prefetch(options: PrefetchOptions): Promise<void>;
67
-
68
- export declare type PrefetchOptions = {
69
- id: string;
70
- instance: ReturnType<typeof getInstance>;
71
- dataFetchParams?: DataFetchParams;
72
- preloadComponentResource?: boolean;
73
- };
74
-
75
- export declare function revalidateTag(tag: string): void;
76
-
77
- export { }
78
-
79
-
80
- declare module '@module-federation/runtime-core' {
81
- interface FederationHost {
82
- createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
83
- prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
84
- collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
85
- }
86
- }
@@ -1,26 +0,0 @@
1
- import { u as DATA_FETCH_FUNCTION } from "./utils-BTYYwZcb.mjs";
2
- import { C, b, e, h, c, d, r } from "./utils-BTYYwZcb.mjs";
3
- import { d as dataFetchFunction } from "./prefetch-CXJhiNUD.mjs";
4
- import { i, p } from "./prefetch-CXJhiNUD.mjs";
5
- async function callDataFetch() {
6
- const dataFetch = globalThis[DATA_FETCH_FUNCTION];
7
- if (dataFetch) {
8
- await Promise.all(
9
- dataFetch.map(async (options) => {
10
- await dataFetchFunction(options);
11
- })
12
- );
13
- }
14
- }
15
- export {
16
- C as CacheSize,
17
- b as CacheTime,
18
- e as cache,
19
- callDataFetch,
20
- h as clearStore,
21
- c as configureCache,
22
- d as generateKey,
23
- i as injectDataFetch,
24
- p as prefetch,
25
- r as revalidateTag
26
- };
@@ -1,45 +0,0 @@
1
- "use strict";
2
- const React = require("react");
3
- const index_esm = require("./index.esm-j_1sIRzg.js");
4
- const RouterContext = React.createContext(null);
5
- const LoggerInstance = index_esm.createLogger(
6
- "[ Module Federation Bridge React ]"
7
- );
8
- function pathJoin(...args) {
9
- const res = args.reduce((res2, path) => {
10
- let nPath = path;
11
- if (!nPath || typeof nPath !== "string") {
12
- return res2;
13
- }
14
- if (nPath[0] !== "/") {
15
- nPath = `/${nPath}`;
16
- }
17
- const lastIndex = nPath.length - 1;
18
- if (nPath[lastIndex] === "/") {
19
- nPath = nPath.substring(0, lastIndex);
20
- }
21
- return res2 + nPath;
22
- }, "");
23
- return res || "/";
24
- }
25
- const getModuleName = (id) => {
26
- if (!id) {
27
- return id;
28
- }
29
- const idArray = id.split("/");
30
- if (idArray.length < 2) {
31
- return id;
32
- }
33
- return idArray[0] + "/" + idArray[1];
34
- };
35
- const getRootDomDefaultClassName = (moduleName) => {
36
- if (!moduleName) {
37
- return "";
38
- }
39
- const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
40
- return `bridge-root-component-${name}`;
41
- };
42
- exports.LoggerInstance = LoggerInstance;
43
- exports.RouterContext = RouterContext;
44
- exports.getRootDomDefaultClassName = getRootDomDefaultClassName;
45
- exports.pathJoin = pathJoin;
@@ -1,46 +0,0 @@
1
- import React__default from "react";
2
- import { c as createLogger } from "./index.esm-BCeUd-x9.mjs";
3
- const RouterContext = React__default.createContext(null);
4
- const LoggerInstance = createLogger(
5
- "[ Module Federation Bridge React ]"
6
- );
7
- function pathJoin(...args) {
8
- const res = args.reduce((res2, path) => {
9
- let nPath = path;
10
- if (!nPath || typeof nPath !== "string") {
11
- return res2;
12
- }
13
- if (nPath[0] !== "/") {
14
- nPath = `/${nPath}`;
15
- }
16
- const lastIndex = nPath.length - 1;
17
- if (nPath[lastIndex] === "/") {
18
- nPath = nPath.substring(0, lastIndex);
19
- }
20
- return res2 + nPath;
21
- }, "");
22
- return res || "/";
23
- }
24
- const getModuleName = (id) => {
25
- if (!id) {
26
- return id;
27
- }
28
- const idArray = id.split("/");
29
- if (idArray.length < 2) {
30
- return id;
31
- }
32
- return idArray[0] + "/" + idArray[1];
33
- };
34
- const getRootDomDefaultClassName = (moduleName) => {
35
- if (!moduleName) {
36
- return "";
37
- }
38
- const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
39
- return `bridge-root-component-${name}`;
40
- };
41
- export {
42
- LoggerInstance as L,
43
- RouterContext as R,
44
- getRootDomDefaultClassName as g,
45
- pathJoin as p
46
- };