@squide/firefly 8.0.0 → 9.0.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/CHANGELOG.md +66 -2
- package/dist/AppRouter.d.ts +13 -26
- package/dist/AppRouter.js +6 -1
- package/dist/AppRouterContext.d.ts +9 -0
- package/dist/AppRouterContext.js +1 -0
- package/dist/AppRouterReducer.d.ts +31 -0
- package/dist/AppRouterReducer.js +1 -0
- package/dist/{fireflyRuntime.d.ts → FireflyRuntime.d.ts} +3 -2
- package/dist/FireflyRuntime.js +2 -0
- package/dist/GlobalDataQueriesError.d.ts +8 -0
- package/dist/GlobalDataQueriesError.js +1 -0
- package/dist/RootRoute.d.ts +5 -0
- package/dist/RootRoute.js +3 -0
- package/dist/chunk-2E76JVV7.js +41 -0
- package/dist/chunk-36U4TTNR.js +34 -0
- package/dist/chunk-ENUCXEMN.js +180 -0
- package/dist/chunk-FKQ7XQEU.js +54 -0
- package/dist/chunk-G32YX2KR.js +22 -0
- package/dist/chunk-H6F7HDB3.js +9 -0
- package/dist/chunk-HE5HKFL3.js +16 -0
- package/dist/chunk-I6L3AYOB.js +24 -0
- package/dist/chunk-IOMSOUAL.js +20 -0
- package/dist/chunk-L5BP3WP3.js +21 -0
- package/dist/chunk-MZG2PJJG.js +19 -0
- package/dist/chunk-N2GOIQ5E.js +14 -0
- package/dist/chunk-PP3MRMJJ.js +11 -0
- package/dist/chunk-PU7MASPN.js +18 -0
- package/dist/chunk-RG5N56BQ.js +55 -0
- package/dist/chunk-VUMBZ5BP.js +46 -0
- package/dist/chunk-WOPD33CM.js +25 -0
- package/dist/chunk-WVRMJZV6.js +18 -0
- package/dist/chunk-YRWFYWK4.js +11 -0
- package/dist/index.d.ts +21 -4
- package/dist/index.js +19 -2
- package/dist/useCanFetchProtectedData.d.ts +3 -0
- package/dist/useCanFetchProtectedData.js +2 -0
- package/dist/useCanFetchPublicData.d.ts +3 -0
- package/dist/useCanFetchPublicData.js +2 -0
- package/dist/useCanRegisterDeferredRegistrations.d.ts +3 -0
- package/dist/useCanRegisterDeferredRegistrations.js +2 -0
- package/dist/useCanUpdateDeferredRegistrations.d.ts +3 -0
- package/dist/useCanUpdateDeferredRegistrations.js +2 -0
- package/dist/useDeferredRegistrations.d.ts +13 -0
- package/dist/useDeferredRegistrations.js +6 -0
- package/dist/useIsActiveRouteProtected.d.ts +3 -0
- package/dist/useIsActiveRouteProtected.js +1 -0
- package/dist/useIsBootstrapping.d.ts +3 -0
- package/dist/useIsBootstrapping.js +2 -0
- package/dist/useNavigationItems.d.ts +5 -0
- package/dist/useNavigationItems.js +2 -0
- package/dist/useProtectedDataQueries.d.ts +9 -0
- package/dist/useProtectedDataQueries.js +4 -0
- package/dist/usePublicDataQueries.d.ts +8 -0
- package/dist/usePublicDataQueries.js +4 -0
- package/dist/useRegisterDeferredRegistrations.d.ts +9 -0
- package/dist/useRegisterDeferredRegistrations.js +1 -0
- package/dist/useStrictRegistrationMode.d.ts +3 -0
- package/dist/useStrictRegistrationMode.js +1 -0
- package/dist/useUpdateDeferredRegistrations.d.ts +9 -0
- package/dist/useUpdateDeferredRegistrations.js +2 -0
- package/package.json +16 -17
- package/dist/chunk-URNAUMUG.js +0 -160
- package/dist/chunk-YXMNS6U3.js +0 -45
- package/dist/fireflyRuntime.js +0 -1
package/dist/chunk-URNAUMUG.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { useLogOnceLogger, isNil } from '@squide/core';
|
|
2
|
-
import { useAreModulesRegistered, useAreModulesReady } from '@squide/module-federation';
|
|
3
|
-
import { useIsMswStarted } from '@squide/msw';
|
|
4
|
-
import { useRouteMatch, useIsRouteProtected, useRoutes, findRouteByPath } from '@squide/react-router';
|
|
5
|
-
import { useEffect, useCallback, cloneElement, useMemo } from 'react';
|
|
6
|
-
import { ErrorBoundary, useErrorBoundary } from 'react-error-boundary';
|
|
7
|
-
import { useLocation, Outlet } from 'react-router-dom';
|
|
8
|
-
import { jsx } from 'react/jsx-runtime';
|
|
9
|
-
|
|
10
|
-
// src/AppRouter.tsx
|
|
11
|
-
function useLoadPublicData(areModulesRegistered, areModulesReady, isMswStarted, isLoaded, onLoadData) {
|
|
12
|
-
const logger = useLogOnceLogger();
|
|
13
|
-
const { showBoundary } = useErrorBoundary();
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (onLoadData && !isLoaded) {
|
|
16
|
-
if ((areModulesRegistered || areModulesReady) && isMswStarted) {
|
|
17
|
-
logger.debugOnce("loading-public-data", "[shell] Loading public data.");
|
|
18
|
-
const abortController = new AbortController();
|
|
19
|
-
const signal = abortController.signal;
|
|
20
|
-
const result = onLoadData(signal);
|
|
21
|
-
if (!isPromise(result)) {
|
|
22
|
-
throw Error("[squide] An AppRouter onLoadPublicData handler must return a promise object.");
|
|
23
|
-
}
|
|
24
|
-
result.then(() => {
|
|
25
|
-
logger.debugOnce("public-data-loaded", "[shell] Public data has been loaded.");
|
|
26
|
-
}).catch((error) => {
|
|
27
|
-
if (!signal.aborted) {
|
|
28
|
-
showBoundary(error);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
return () => {
|
|
32
|
-
abortController.abort();
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}, [areModulesRegistered, areModulesReady, isMswStarted, isLoaded, showBoundary, onLoadData, logger]);
|
|
37
|
-
}
|
|
38
|
-
function useLoadProtectedData(areModulesRegistered, areModulesReady, isMswStarted, isActiveRouteProtected, isLoaded, onLoadData) {
|
|
39
|
-
const logger = useLogOnceLogger();
|
|
40
|
-
const { showBoundary } = useErrorBoundary();
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (onLoadData && !isLoaded) {
|
|
43
|
-
if ((areModulesRegistered || areModulesReady) && isMswStarted) {
|
|
44
|
-
if (isActiveRouteProtected) {
|
|
45
|
-
logger.debugOnce("loading-protected-data", `[shell] Loading protected data as "${location.pathname}" is a protected route.`);
|
|
46
|
-
const abortController = new AbortController();
|
|
47
|
-
const signal = abortController.signal;
|
|
48
|
-
const result = onLoadData(signal);
|
|
49
|
-
if (!isPromise(result)) {
|
|
50
|
-
throw Error("[squide] An AppRouter onLoadProtectedData handler must return a promise object.");
|
|
51
|
-
}
|
|
52
|
-
result.then(() => {
|
|
53
|
-
logger.debugOnce("protected-data-loaded", "[shell] Protected data has been loaded.");
|
|
54
|
-
}).catch((error) => {
|
|
55
|
-
if (!signal.aborted) {
|
|
56
|
-
showBoundary(error);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return () => {
|
|
60
|
-
abortController.abort();
|
|
61
|
-
};
|
|
62
|
-
} else {
|
|
63
|
-
logger.debugOnce("is-a-public-route", `[shell] Not loading protected data as "${location.pathname}" is a public route.`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}, [areModulesRegistered, areModulesReady, isMswStarted, isActiveRouteProtected, isLoaded, showBoundary, onLoadData, logger]);
|
|
68
|
-
}
|
|
69
|
-
function isPromise(value) {
|
|
70
|
-
return !isNil(value) && !isNil(value.then) && !isNil(value.catch);
|
|
71
|
-
}
|
|
72
|
-
function BootstrappingRoute(props) {
|
|
73
|
-
const {
|
|
74
|
-
fallbackElement,
|
|
75
|
-
onLoadPublicData,
|
|
76
|
-
onLoadProtectedData,
|
|
77
|
-
isPublicDataLoaded,
|
|
78
|
-
isProtectedDataLoaded,
|
|
79
|
-
onCompleteRegistrations,
|
|
80
|
-
waitForMsw,
|
|
81
|
-
areModulesRegistered,
|
|
82
|
-
areModulesReady
|
|
83
|
-
} = props;
|
|
84
|
-
const logger = useLogOnceLogger();
|
|
85
|
-
const location2 = useLocation();
|
|
86
|
-
const isMswStarted = useIsMswStarted(waitForMsw);
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
if (waitForMsw) {
|
|
89
|
-
if ((areModulesRegistered || areModulesReady) && !isMswStarted) {
|
|
90
|
-
logger.debugOnce("waiting-for-msw", `[shell] Modules are ${areModulesReady ? "ready" : "registered"}, waiting for MSW to start...`);
|
|
91
|
-
} else if (!areModulesRegistered && !areModulesReady && isMswStarted) {
|
|
92
|
-
logger.debugOnce("waiting-for-modules", "[shell] MSW is started, waiting for the modules...");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}, [logger, areModulesRegistered, areModulesReady, isMswStarted, waitForMsw]);
|
|
96
|
-
useLoadPublicData(areModulesRegistered, areModulesReady, isMswStarted, isPublicDataLoaded, onLoadPublicData);
|
|
97
|
-
const activeRoute = useRouteMatch(location2, { throwWhenThereIsNoMatch: areModulesReady });
|
|
98
|
-
const isActiveRouteProtected = useIsRouteProtected(activeRoute);
|
|
99
|
-
useLoadProtectedData(areModulesRegistered, areModulesReady, isMswStarted, isActiveRouteProtected, isProtectedDataLoaded, onLoadProtectedData);
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if (onCompleteRegistrations) {
|
|
102
|
-
if (areModulesRegistered && isMswStarted && isPublicDataLoaded && (!isActiveRouteProtected || isProtectedDataLoaded)) {
|
|
103
|
-
if (!areModulesReady) {
|
|
104
|
-
onCompleteRegistrations();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}, [areModulesRegistered, areModulesReady, isMswStarted, isPublicDataLoaded, isProtectedDataLoaded, isActiveRouteProtected, onCompleteRegistrations]);
|
|
109
|
-
if (!areModulesReady || !isMswStarted || !activeRoute || !isPublicDataLoaded || isActiveRouteProtected && !isProtectedDataLoaded) {
|
|
110
|
-
return fallbackElement;
|
|
111
|
-
}
|
|
112
|
-
return /* @__PURE__ */ jsx(Outlet, {});
|
|
113
|
-
}
|
|
114
|
-
function AppRouter(props) {
|
|
115
|
-
const {
|
|
116
|
-
fallbackElement,
|
|
117
|
-
errorElement,
|
|
118
|
-
onLoadPublicData,
|
|
119
|
-
onLoadProtectedData,
|
|
120
|
-
isPublicDataLoaded = true,
|
|
121
|
-
isProtectedDataLoaded = true,
|
|
122
|
-
onCompleteRegistrations,
|
|
123
|
-
waitForMsw,
|
|
124
|
-
children: renderRouterProvider
|
|
125
|
-
} = props;
|
|
126
|
-
const areModulesRegistered = useAreModulesRegistered();
|
|
127
|
-
const areModulesReady = useAreModulesReady();
|
|
128
|
-
const routes = useRoutes();
|
|
129
|
-
const errorRenderer = useCallback(({ error }) => {
|
|
130
|
-
return cloneElement(errorElement, {
|
|
131
|
-
error
|
|
132
|
-
});
|
|
133
|
-
}, [errorElement]);
|
|
134
|
-
return useMemo(() => {
|
|
135
|
-
if (areModulesRegistered && !findRouteByPath(routes, "*")) {
|
|
136
|
-
throw new Error("[squide] For the AppRouter component to work properly, the application must be a define a custom no match router. For additional information, refer to: https://reactrouter.com/en/main/start/tutorial#handling-not-found-errors.");
|
|
137
|
-
}
|
|
138
|
-
return renderRouterProvider([
|
|
139
|
-
{
|
|
140
|
-
element: /* @__PURE__ */ jsx(ErrorBoundary, { fallbackRender: errorRenderer, children: /* @__PURE__ */ jsx(
|
|
141
|
-
BootstrappingRoute,
|
|
142
|
-
{
|
|
143
|
-
fallbackElement,
|
|
144
|
-
onLoadPublicData,
|
|
145
|
-
onLoadProtectedData,
|
|
146
|
-
isPublicDataLoaded,
|
|
147
|
-
isProtectedDataLoaded,
|
|
148
|
-
onCompleteRegistrations,
|
|
149
|
-
waitForMsw,
|
|
150
|
-
areModulesRegistered,
|
|
151
|
-
areModulesReady
|
|
152
|
-
}
|
|
153
|
-
) }),
|
|
154
|
-
children: routes
|
|
155
|
-
}
|
|
156
|
-
], {});
|
|
157
|
-
}, [areModulesRegistered, areModulesReady, routes, onLoadPublicData, onLoadProtectedData, isPublicDataLoaded, isProtectedDataLoaded, onCompleteRegistrations, waitForMsw, errorRenderer, fallbackElement, renderRouterProvider]);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export { AppRouter, BootstrappingRoute };
|
package/dist/chunk-YXMNS6U3.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { MswPlugin } from '@squide/msw';
|
|
2
|
-
import { ReactRouterRuntime } from '@squide/react-router';
|
|
3
|
-
|
|
4
|
-
// src/fireflyRuntime.tsx
|
|
5
|
-
var FireflyRuntime = class extends ReactRouterRuntime {
|
|
6
|
-
#mswPlugin;
|
|
7
|
-
#useMsw;
|
|
8
|
-
constructor({ plugins, useMsw, ...options } = {}) {
|
|
9
|
-
if (useMsw) {
|
|
10
|
-
const mswPlugin = new MswPlugin();
|
|
11
|
-
super({
|
|
12
|
-
plugins: [
|
|
13
|
-
...plugins ?? [],
|
|
14
|
-
mswPlugin
|
|
15
|
-
],
|
|
16
|
-
...options
|
|
17
|
-
});
|
|
18
|
-
this.#mswPlugin = mswPlugin;
|
|
19
|
-
this.#useMsw = true;
|
|
20
|
-
} else {
|
|
21
|
-
super({
|
|
22
|
-
plugins,
|
|
23
|
-
...options
|
|
24
|
-
});
|
|
25
|
-
this.#useMsw = false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
registerRequestHandlers(handlers) {
|
|
29
|
-
if (!this.#mswPlugin) {
|
|
30
|
-
throw new Error(`[squide] Cannot register the provided MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the "useMsw" option?`);
|
|
31
|
-
}
|
|
32
|
-
this.#mswPlugin.registerRequestHandlers(handlers);
|
|
33
|
-
}
|
|
34
|
-
get requestHandlers() {
|
|
35
|
-
if (!this.#mswPlugin) {
|
|
36
|
-
throw new Error(`[squide] Cannot retrieve MSW request handlers because the runtime hasn't been initialized with MSW. Did you instanciate the FireflyRuntime with the "useMsw" option?`);
|
|
37
|
-
}
|
|
38
|
-
return this.#mswPlugin.requestHandlers;
|
|
39
|
-
}
|
|
40
|
-
get isMswEnabled() {
|
|
41
|
-
return this.#useMsw;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export { FireflyRuntime };
|
package/dist/fireflyRuntime.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { FireflyRuntime } from './chunk-YXMNS6U3.js';
|