@squide/firefly 9.3.0 → 9.3.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/CHANGELOG.md +19 -0
- package/dist/AppRouter.d.ts +8 -12
- package/dist/AppRouter.js +66 -8
- package/dist/AppRouterContext.d.ts +5 -9
- package/dist/AppRouterContext.js +28 -1
- package/dist/AppRouterReducer.d.ts +23 -26
- package/dist/AppRouterReducer.js +337 -4
- package/dist/FireflyRuntime.d.ts +5 -8
- package/dist/FireflyRuntime.js +64 -5
- package/dist/GlobalDataQueriesError.d.ts +2 -4
- package/dist/GlobalDataQueriesError.js +17 -1
- package/dist/RootRoute.d.ts +1 -5
- package/dist/RootRoute.js +46 -3
- package/dist/boostrap.d.ts +8 -13
- package/dist/boostrap.js +52 -1
- package/dist/index.d.ts +23 -28
- package/dist/index.js +49 -25
- package/dist/useCanFetchProtectedData.d.ts +1 -3
- package/dist/useCanFetchProtectedData.js +15 -2
- package/dist/useCanFetchPublicData.d.ts +1 -3
- package/dist/useCanFetchPublicData.js +15 -2
- package/dist/useCanRegisterDeferredRegistrations.d.ts +1 -3
- package/dist/useCanRegisterDeferredRegistrations.js +12 -2
- package/dist/useCanUpdateDeferredRegistrations.d.ts +1 -3
- package/dist/useCanUpdateDeferredRegistrations.js +14 -2
- package/dist/useDeferredRegistrations.d.ts +5 -8
- package/dist/useDeferredRegistrations.js +72 -6
- package/dist/useExecuteOnce.d.ts +1 -3
- package/dist/useExecuteOnce.js +27 -1
- package/dist/useIsActiveRouteProtected.d.ts +1 -3
- package/dist/useIsActiveRouteProtected.js +21 -1
- package/dist/useIsBootstrapping.d.ts +3 -7
- package/dist/useIsBootstrapping.js +20 -2
- package/dist/useNavigationItems.d.ts +3 -7
- package/dist/useNavigationItems.js +24 -2
- package/dist/useProtectedDataQueries.d.ts +6 -8
- package/dist/useProtectedDataQueries.js +124 -5
- package/dist/usePublicDataQueries.d.ts +5 -7
- package/dist/usePublicDataQueries.js +109 -5
- package/dist/useRegisterDeferredRegistrations.d.ts +4 -9
- package/dist/useRegisterDeferredRegistrations.js +17 -1
- package/dist/useStrictRegistrationMode.d.ts +1 -3
- package/dist/useStrictRegistrationMode.js +38 -1
- package/dist/useUpdateDeferredRegistrations.d.ts +4 -9
- package/dist/useUpdateDeferredRegistrations.js +28 -2
- package/package.json +29 -26
- package/dist/chunk-4RUCDAUT.js +0 -18
- package/dist/chunk-BFHHJOJT.js +0 -41
- package/dist/chunk-CFNKNPS3.js +0 -54
- package/dist/chunk-CTLPFYLM.js +0 -65
- package/dist/chunk-G32YX2KR.js +0 -22
- package/dist/chunk-GXSW4CZS.js +0 -9
- package/dist/chunk-H2ILEMPE.js +0 -28
- package/dist/chunk-HE5HKFL3.js +0 -16
- package/dist/chunk-IGJHKH2A.js +0 -48
- package/dist/chunk-IOMSOUAL.js +0 -20
- package/dist/chunk-JFMSLZ74.js +0 -253
- package/dist/chunk-L44KFU57.js +0 -34
- package/dist/chunk-MKTGJHQR.js +0 -71
- package/dist/chunk-N2GOIQ5E.js +0 -14
- package/dist/chunk-PMVN3U47.js +0 -21
- package/dist/chunk-PP3MRMJJ.js +0 -11
- package/dist/chunk-TURKCH7J.js +0 -20
- package/dist/chunk-WOPD33CM.js +0 -25
- package/dist/chunk-WVRMJZV6.js +0 -18
- package/dist/chunk-XDWYPVAJ.js +0 -21
- package/dist/chunk-YRWFYWK4.js +0 -11
package/dist/chunk-BFHHJOJT.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { useRegisterDeferredRegistrations } from './chunk-YRWFYWK4.js';
|
|
2
|
-
import { useUpdateDeferredRegistrations } from './chunk-N2GOIQ5E.js';
|
|
3
|
-
import { useCanRegisterDeferredRegistrations } from './chunk-4RUCDAUT.js';
|
|
4
|
-
import { useCanUpdateDeferredRegistrations } from './chunk-WVRMJZV6.js';
|
|
5
|
-
import { useRuntime } from '@squide/core';
|
|
6
|
-
import { useEffect } from 'react';
|
|
7
|
-
|
|
8
|
-
function hasError({ localModuleErrors, remoteModuleErrors }) {
|
|
9
|
-
return localModuleErrors.length > 0 || remoteModuleErrors.length > 0;
|
|
10
|
-
}
|
|
11
|
-
function useDeferredRegistrations(data, { onError } = {}) {
|
|
12
|
-
const runtime = useRuntime();
|
|
13
|
-
const canRegisterDeferredRegistrations = useCanRegisterDeferredRegistrations();
|
|
14
|
-
const canUpdateDeferredRegistrations = useCanUpdateDeferredRegistrations();
|
|
15
|
-
const registerDeferredRegistrations = useRegisterDeferredRegistrations();
|
|
16
|
-
const updateDeferredRegistrations = useUpdateDeferredRegistrations();
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
if (canRegisterDeferredRegistrations) {
|
|
19
|
-
const register = async () => {
|
|
20
|
-
const errors = await registerDeferredRegistrations(data, runtime);
|
|
21
|
-
if (hasError(errors) && onError) {
|
|
22
|
-
onError(errors);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
register();
|
|
26
|
-
}
|
|
27
|
-
}, [canRegisterDeferredRegistrations, registerDeferredRegistrations, data, onError, runtime]);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (canUpdateDeferredRegistrations) {
|
|
30
|
-
const update = async () => {
|
|
31
|
-
const errors = await updateDeferredRegistrations(data, runtime);
|
|
32
|
-
if (hasError(errors) && onError) {
|
|
33
|
-
onError(errors);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
update();
|
|
37
|
-
}
|
|
38
|
-
}, [canUpdateDeferredRegistrations, updateDeferredRegistrations, data, onError, runtime]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { useDeferredRegistrations };
|
package/dist/chunk-CFNKNPS3.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { getAreModulesRegistered } from './chunk-JFMSLZ74.js';
|
|
2
|
-
import { MswPlugin } from '@squide/msw';
|
|
3
|
-
import { ReactRouterRuntime } from '@squide/react-router';
|
|
4
|
-
|
|
5
|
-
var FireflyRuntime = class extends ReactRouterRuntime {
|
|
6
|
-
#useMsw;
|
|
7
|
-
constructor({ plugins, useMsw, ...options } = {}) {
|
|
8
|
-
if (useMsw) {
|
|
9
|
-
super({
|
|
10
|
-
plugins: [
|
|
11
|
-
...plugins ?? [],
|
|
12
|
-
(runtime) => new MswPlugin(runtime)
|
|
13
|
-
],
|
|
14
|
-
...options
|
|
15
|
-
});
|
|
16
|
-
this.#useMsw = true;
|
|
17
|
-
} else {
|
|
18
|
-
super({
|
|
19
|
-
plugins,
|
|
20
|
-
...options
|
|
21
|
-
});
|
|
22
|
-
this.#useMsw = false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
registerRequestHandlers(handlers) {
|
|
26
|
-
const mswPlugin = this.getPlugin(MswPlugin.name);
|
|
27
|
-
if (!mswPlugin) {
|
|
28
|
-
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?`);
|
|
29
|
-
}
|
|
30
|
-
if (getAreModulesRegistered()) {
|
|
31
|
-
throw new Error("[squide] Cannot register an MSW request handlers once the modules are registered. Are you trying to register an MSW request handler in a deferred registration function? Only navigation items can be registered in a deferred registration function.");
|
|
32
|
-
}
|
|
33
|
-
mswPlugin.registerRequestHandlers(handlers);
|
|
34
|
-
}
|
|
35
|
-
// Must define a return type otherwise we get an "error TS2742: The inferred type of 'requestHandlers' cannot be named" error.
|
|
36
|
-
get requestHandlers() {
|
|
37
|
-
const mswPlugin = this.getPlugin(MswPlugin.name);
|
|
38
|
-
if (!mswPlugin) {
|
|
39
|
-
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?`);
|
|
40
|
-
}
|
|
41
|
-
return mswPlugin.requestHandlers;
|
|
42
|
-
}
|
|
43
|
-
registerRoute(route, options = {}) {
|
|
44
|
-
if (getAreModulesRegistered()) {
|
|
45
|
-
throw new Error("[squide] Cannot register a route once the modules are registered. Are you trying to register a route in a deferred registration function? Only navigation items can be registered in a deferred registration function.");
|
|
46
|
-
}
|
|
47
|
-
super.registerRoute(route, options);
|
|
48
|
-
}
|
|
49
|
-
get isMswEnabled() {
|
|
50
|
-
return this.#useMsw;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export { FireflyRuntime };
|
package/dist/chunk-CTLPFYLM.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { useCanFetchPublicData } from './chunk-IOMSOUAL.js';
|
|
2
|
-
import { useExecuteOnce } from './chunk-TURKCH7J.js';
|
|
3
|
-
import { GlobalDataQueriesError } from './chunk-HE5HKFL3.js';
|
|
4
|
-
import { useAppRouterDispatcher } from './chunk-G32YX2KR.js';
|
|
5
|
-
import { useEventBus } from '@squide/core';
|
|
6
|
-
import { useQueries } from '@tanstack/react-query';
|
|
7
|
-
import { useCallback, useRef, useEffect } from 'react';
|
|
8
|
-
|
|
9
|
-
var PublicDataFetchStartedEvent = "squide-public-data-fetch-started";
|
|
10
|
-
var PublicDataFetchFailedEvent = "squide-public-data-fetch-failed";
|
|
11
|
-
function usePublicDataQueries(queries) {
|
|
12
|
-
const canFetchPublicData = useCanFetchPublicData();
|
|
13
|
-
const eventBus = useEventBus();
|
|
14
|
-
const dispatch = useAppRouterDispatcher();
|
|
15
|
-
const combineResults = useCallback((results) => {
|
|
16
|
-
const errors = results.filter((x) => x.error).map((x) => x.error);
|
|
17
|
-
const hasErrors2 = errors.length > 0;
|
|
18
|
-
return {
|
|
19
|
-
data: results.map((x) => x.data),
|
|
20
|
-
errors,
|
|
21
|
-
hasErrors: hasErrors2,
|
|
22
|
-
isReady: !hasErrors2 && !results.some((x) => x.isPending)
|
|
23
|
-
};
|
|
24
|
-
}, []);
|
|
25
|
-
const { data, errors: queriesErrors, hasErrors, isReady } = useQueries({
|
|
26
|
-
queries: queries.map((x) => ({
|
|
27
|
-
enabled: canFetchPublicData,
|
|
28
|
-
...x
|
|
29
|
-
})),
|
|
30
|
-
combine: combineResults
|
|
31
|
-
});
|
|
32
|
-
useExecuteOnce(useCallback(() => {
|
|
33
|
-
if (canFetchPublicData) {
|
|
34
|
-
eventBus.dispatch(PublicDataFetchStartedEvent);
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
}, [canFetchPublicData, eventBus]), true);
|
|
39
|
-
const isReadyRef = useRef(false);
|
|
40
|
-
const dispatchReady = useExecuteOnce(useCallback(() => {
|
|
41
|
-
if (isReady) {
|
|
42
|
-
isReadyRef.current = true;
|
|
43
|
-
dispatch({ type: "public-data-ready" });
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
}, [isReady, dispatch]));
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
dispatchReady();
|
|
50
|
-
}, [dispatchReady]);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
if (isReadyRef.current && data) {
|
|
53
|
-
dispatch({ type: "public-data-updated" });
|
|
54
|
-
}
|
|
55
|
-
}, [data, dispatch]);
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
if (hasErrors) {
|
|
58
|
-
eventBus.dispatch(PublicDataFetchFailedEvent, queriesErrors);
|
|
59
|
-
throw new GlobalDataQueriesError("[squide] Global public data queries failed.", queriesErrors);
|
|
60
|
-
}
|
|
61
|
-
}, [hasErrors, queriesErrors, eventBus]);
|
|
62
|
-
return data;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { PublicDataFetchFailedEvent, PublicDataFetchStartedEvent, usePublicDataQueries };
|
package/dist/chunk-G32YX2KR.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { isNil } from '@squide/core';
|
|
2
|
-
import { createContext, useContext } from 'react';
|
|
3
|
-
|
|
4
|
-
// src/AppRouterContext.ts
|
|
5
|
-
var AppRouterStateContext = createContext(void 0);
|
|
6
|
-
function useAppRouterState() {
|
|
7
|
-
const state = useContext(AppRouterStateContext);
|
|
8
|
-
if (isNil(state)) {
|
|
9
|
-
throw new Error("[squide] The useAppRouterState hook must be called by a children of the AppRouter component.");
|
|
10
|
-
}
|
|
11
|
-
return state;
|
|
12
|
-
}
|
|
13
|
-
var AppRouterDispatcherContext = createContext(void 0);
|
|
14
|
-
function useAppRouterDispatcher() {
|
|
15
|
-
const dispatch = useContext(AppRouterDispatcherContext);
|
|
16
|
-
if (isNil(dispatch)) {
|
|
17
|
-
throw new Error("[squide] The useAppRouterDispatcher hook must be called by a children of the AppRouter component.");
|
|
18
|
-
}
|
|
19
|
-
return dispatch;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { AppRouterDispatcherContext, AppRouterStateContext, useAppRouterDispatcher, useAppRouterState };
|
package/dist/chunk-GXSW4CZS.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { useAppRouterState } from './chunk-G32YX2KR.js';
|
|
2
|
-
import { useRuntimeNavigationItems } from '@squide/react-router';
|
|
3
|
-
|
|
4
|
-
function useNavigationItems(options) {
|
|
5
|
-
useAppRouterState();
|
|
6
|
-
return useRuntimeNavigationItems(options);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export { useNavigationItems };
|
package/dist/chunk-H2ILEMPE.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { useAppRouterState } from './chunk-G32YX2KR.js';
|
|
2
|
-
|
|
3
|
-
// src/useIsBootstrapping.ts
|
|
4
|
-
function useIsBootstrapping() {
|
|
5
|
-
const state = useAppRouterState();
|
|
6
|
-
return isApplicationBootstrapping(state);
|
|
7
|
-
}
|
|
8
|
-
function isApplicationBootstrapping(state) {
|
|
9
|
-
const {
|
|
10
|
-
waitForMsw,
|
|
11
|
-
waitForPublicData,
|
|
12
|
-
waitForProtectedData,
|
|
13
|
-
areModulesReady,
|
|
14
|
-
isMswReady,
|
|
15
|
-
isPublicDataReady,
|
|
16
|
-
isProtectedDataReady,
|
|
17
|
-
activeRouteVisibility,
|
|
18
|
-
isUnauthorized
|
|
19
|
-
} = state;
|
|
20
|
-
const isAppReady = !isUnauthorized && areModulesReady && (!waitForMsw || isMswReady) && (!waitForPublicData || isPublicDataReady) && (!waitForProtectedData || activeRouteVisibility === "public" || isProtectedDataReady);
|
|
21
|
-
const flush = (
|
|
22
|
-
// Only applicable when there's a unauthorized request while fetching the initial data.
|
|
23
|
-
isUnauthorized && (!waitForMsw || isMswReady) && (!waitForPublicData || isPublicDataReady)
|
|
24
|
-
);
|
|
25
|
-
return !isAppReady && !flush;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { isApplicationBootstrapping, useIsBootstrapping };
|
package/dist/chunk-HE5HKFL3.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// src/GlobalDataQueriesError.ts
|
|
2
|
-
var GlobalDataQueriesError = class extends Error {
|
|
3
|
-
#errors;
|
|
4
|
-
constructor(message, errors) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.#errors = errors;
|
|
7
|
-
}
|
|
8
|
-
get errors() {
|
|
9
|
-
return this.#errors;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
function isGlobalDataQueriesError(error) {
|
|
13
|
-
return error !== void 0 && error !== null && error instanceof GlobalDataQueriesError;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { GlobalDataQueriesError, isGlobalDataQueriesError };
|
package/dist/chunk-IGJHKH2A.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { registerLocalModules, isFunction } from '@squide/core';
|
|
2
|
-
import { registerRemoteModules } from '@squide/module-federation';
|
|
3
|
-
import { setMswAsReady } from '@squide/msw';
|
|
4
|
-
|
|
5
|
-
// src/boostrap.ts
|
|
6
|
-
var ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
|
|
7
|
-
var isBootstrapped = false;
|
|
8
|
-
async function bootstrap(runtime, options = {}) {
|
|
9
|
-
const {
|
|
10
|
-
localModules,
|
|
11
|
-
remotes,
|
|
12
|
-
context,
|
|
13
|
-
startMsw
|
|
14
|
-
} = options;
|
|
15
|
-
if (isBootstrapped) {
|
|
16
|
-
throw new Error('[squide] A squide application can only be bootstrapped once. Did you call the "bootstrap" function twice?');
|
|
17
|
-
}
|
|
18
|
-
runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);
|
|
19
|
-
let localModuleErrors = [];
|
|
20
|
-
let remoteModuleErrors = [];
|
|
21
|
-
if (localModules) {
|
|
22
|
-
localModuleErrors = await registerLocalModules(localModules, runtime, { context });
|
|
23
|
-
}
|
|
24
|
-
if (remotes) {
|
|
25
|
-
remoteModuleErrors = await registerRemoteModules(remotes, runtime, { context });
|
|
26
|
-
}
|
|
27
|
-
if (runtime.isMswEnabled) {
|
|
28
|
-
if (!isFunction(startMsw)) {
|
|
29
|
-
throw new Error('[squide] When MSW is enabled, the "startMsw" function must be provided.');
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
await startMsw(runtime);
|
|
33
|
-
setMswAsReady();
|
|
34
|
-
} catch (error) {
|
|
35
|
-
runtime.logger.debug("[squide] An error occured while starting MSW.", error);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
isBootstrapped = true;
|
|
39
|
-
return {
|
|
40
|
-
localModuleErrors,
|
|
41
|
-
remoteModuleErrors
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function __resetBootstrapGuard() {
|
|
45
|
-
isBootstrapped = false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export { ApplicationBootstrappingStartedEvent, __resetBootstrapGuard, bootstrap };
|
package/dist/chunk-IOMSOUAL.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useAppRouterState } from './chunk-G32YX2KR.js';
|
|
2
|
-
|
|
3
|
-
// src/useCanFetchPublicData.ts
|
|
4
|
-
function useCanFetchPublicData() {
|
|
5
|
-
const {
|
|
6
|
-
waitForMsw,
|
|
7
|
-
areModulesRegistered,
|
|
8
|
-
areModulesReady,
|
|
9
|
-
isMswReady,
|
|
10
|
-
isPublicDataReady
|
|
11
|
-
} = useAppRouterState();
|
|
12
|
-
return (
|
|
13
|
-
// Always return true when the public data has already been fetched sucessfully so TanStack Query can update the data in the background.
|
|
14
|
-
isPublicDataReady || // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered has they will probably
|
|
15
|
-
// depends on the protected data.
|
|
16
|
-
(areModulesRegistered || areModulesReady) && (!waitForMsw || isMswReady)
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { useCanFetchPublicData };
|
package/dist/chunk-JFMSLZ74.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { useExecuteOnce } from './chunk-TURKCH7J.js';
|
|
2
|
-
import { isApplicationBootstrapping } from './chunk-H2ILEMPE.js';
|
|
3
|
-
import { getLocalModuleRegistrationStatus, useLogger, addLocalModuleRegistrationStatusChangedListener, removeLocalModuleRegistrationStatusChangedListener, useEventBus } from '@squide/core';
|
|
4
|
-
import { getRemoteModuleRegistrationStatus, areModulesRegistered, areModulesReady, addRemoteModuleRegistrationStatusChangedListener, removeRemoteModuleRegistrationStatusChangedListener } from '@squide/module-federation';
|
|
5
|
-
import { isMswReady, addMswStateChangedListener, removeMswStateChangedListener } from '@squide/msw';
|
|
6
|
-
import { useCallback, useEffect, useReducer, useMemo } from 'react';
|
|
7
|
-
|
|
8
|
-
var ModulesRegisteredEvent = "squide-modules-registered";
|
|
9
|
-
var ModulesReadyEvent = "squide-modules-ready";
|
|
10
|
-
var MswReadyEvent = "squide-msw-ready";
|
|
11
|
-
var PublicDataReadyEvent = "squide-public-data-ready";
|
|
12
|
-
var ProtectedDataReadyEvent = "squide-protected-data-ready";
|
|
13
|
-
var PublicDataUpdatedEvent = "squide-public-data-updated";
|
|
14
|
-
var ProtectedDataUpdatedEvent = "squide-protected-data-updated";
|
|
15
|
-
var DeferredRegistrationsUpdatedEvent = "squide-deferred-registrations-updated";
|
|
16
|
-
var ApplicationBoostrappedEvent = "squide-app-boostrapped";
|
|
17
|
-
function reducer(state, action) {
|
|
18
|
-
let newState = state;
|
|
19
|
-
switch (action.type) {
|
|
20
|
-
case "modules-registered": {
|
|
21
|
-
newState = {
|
|
22
|
-
...newState,
|
|
23
|
-
areModulesRegistered: true
|
|
24
|
-
};
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
case "modules-ready": {
|
|
28
|
-
newState = {
|
|
29
|
-
...newState,
|
|
30
|
-
areModulesReady: true,
|
|
31
|
-
// Will be set even if the app is not using deferred registrations.
|
|
32
|
-
deferredRegistrationsUpdatedAt: Date.now()
|
|
33
|
-
};
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
case "msw-ready": {
|
|
37
|
-
newState = {
|
|
38
|
-
...newState,
|
|
39
|
-
isMswReady: true
|
|
40
|
-
};
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
case "public-data-ready": {
|
|
44
|
-
newState = {
|
|
45
|
-
...newState,
|
|
46
|
-
isPublicDataReady: true,
|
|
47
|
-
publicDataUpdatedAt: Date.now()
|
|
48
|
-
};
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case "protected-data-ready": {
|
|
52
|
-
newState = {
|
|
53
|
-
...newState,
|
|
54
|
-
isProtectedDataReady: true,
|
|
55
|
-
protectedDataUpdatedAt: Date.now()
|
|
56
|
-
};
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
case "public-data-updated": {
|
|
60
|
-
newState = {
|
|
61
|
-
...newState,
|
|
62
|
-
publicDataUpdatedAt: Date.now()
|
|
63
|
-
};
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case "protected-data-updated": {
|
|
67
|
-
newState = {
|
|
68
|
-
...newState,
|
|
69
|
-
protectedDataUpdatedAt: Date.now()
|
|
70
|
-
};
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
case "deferred-registrations-updated": {
|
|
74
|
-
newState = {
|
|
75
|
-
...newState,
|
|
76
|
-
deferredRegistrationsUpdatedAt: Date.now()
|
|
77
|
-
};
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
case "active-route-is-public": {
|
|
81
|
-
newState = {
|
|
82
|
-
...newState,
|
|
83
|
-
activeRouteVisibility: "public"
|
|
84
|
-
};
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case "active-route-is-protected": {
|
|
88
|
-
newState = {
|
|
89
|
-
...newState,
|
|
90
|
-
activeRouteVisibility: "protected"
|
|
91
|
-
};
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case "is-unauthorized": {
|
|
95
|
-
newState = {
|
|
96
|
-
...newState,
|
|
97
|
-
isUnauthorized: true
|
|
98
|
-
};
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
default: {
|
|
102
|
-
throw new Error(`[squide] The AppRouter component state reducer doesn't support action type "${action.type}".`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return newState;
|
|
106
|
-
}
|
|
107
|
-
function getAreModulesRegistered() {
|
|
108
|
-
const localModuleStatus = getLocalModuleRegistrationStatus();
|
|
109
|
-
const remoteModuleStatus = getRemoteModuleRegistrationStatus();
|
|
110
|
-
return areModulesRegistered(localModuleStatus, remoteModuleStatus);
|
|
111
|
-
}
|
|
112
|
-
function getAreModulesReady() {
|
|
113
|
-
const localModuleStatus = getLocalModuleRegistrationStatus();
|
|
114
|
-
const remoteModuleStatus = getRemoteModuleRegistrationStatus();
|
|
115
|
-
return areModulesReady(localModuleStatus, remoteModuleStatus);
|
|
116
|
-
}
|
|
117
|
-
function useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch) {
|
|
118
|
-
const logger = useLogger();
|
|
119
|
-
const dispatchModulesRegistered = useExecuteOnce(useCallback(() => {
|
|
120
|
-
if (getAreModulesRegistered()) {
|
|
121
|
-
dispatch({ type: "modules-registered" });
|
|
122
|
-
logger.debug("[squide] %cModules are registered%c.", "color: white; background-color: green;", "");
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
126
|
-
}, [dispatch, logger]));
|
|
127
|
-
const dispatchModulesReady = useExecuteOnce(useCallback(() => {
|
|
128
|
-
if (getAreModulesReady()) {
|
|
129
|
-
dispatch({ type: "modules-ready" });
|
|
130
|
-
logger.debug("[squide] %cModules are ready%c.", "color: white; background-color: green;", "");
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
return false;
|
|
134
|
-
}, [dispatch, logger]));
|
|
135
|
-
return useEffect(() => {
|
|
136
|
-
if (!areModulesRegisteredValue) {
|
|
137
|
-
addLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);
|
|
138
|
-
addRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);
|
|
139
|
-
}
|
|
140
|
-
if (!areModulesReadyValue) {
|
|
141
|
-
addLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
142
|
-
addRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
143
|
-
}
|
|
144
|
-
return () => {
|
|
145
|
-
removeLocalModuleRegistrationStatusChangedListener(dispatchModulesRegistered);
|
|
146
|
-
removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesRegistered);
|
|
147
|
-
removeLocalModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
148
|
-
removeRemoteModuleRegistrationStatusChangedListener(dispatchModulesReady);
|
|
149
|
-
};
|
|
150
|
-
}, [areModulesRegisteredValue, areModulesReadyValue, dispatchModulesRegistered, dispatchModulesReady]);
|
|
151
|
-
}
|
|
152
|
-
function useMswStatusDispatcher(isMswReadyValue, dispatch) {
|
|
153
|
-
const logger = useLogger();
|
|
154
|
-
const dispatchMswReady = useExecuteOnce(useCallback(() => {
|
|
155
|
-
if (isMswReady()) {
|
|
156
|
-
dispatch({ type: "msw-ready" });
|
|
157
|
-
logger.debug("[squide] %cMSW is ready%c.", "color: white; background-color: green;", "");
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
return false;
|
|
161
|
-
}, [dispatch, logger]));
|
|
162
|
-
useEffect(() => {
|
|
163
|
-
if (!isMswReadyValue) {
|
|
164
|
-
addMswStateChangedListener(dispatchMswReady);
|
|
165
|
-
}
|
|
166
|
-
return () => {
|
|
167
|
-
removeMswStateChangedListener(dispatchMswReady);
|
|
168
|
-
};
|
|
169
|
-
}, [isMswReadyValue, dispatchMswReady]);
|
|
170
|
-
}
|
|
171
|
-
function useBootstrappingCompletedDispatcher(state) {
|
|
172
|
-
const eventBus = useEventBus();
|
|
173
|
-
const areModulesRegisteredValue = state.areModulesRegistered;
|
|
174
|
-
const isBoostrapping = isApplicationBootstrapping(state);
|
|
175
|
-
useExecuteOnce(useCallback(() => {
|
|
176
|
-
if (areModulesRegisteredValue && !isBoostrapping) {
|
|
177
|
-
eventBus.dispatch(ApplicationBoostrappedEvent);
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
return false;
|
|
181
|
-
}, [areModulesRegisteredValue, isBoostrapping, eventBus]), true);
|
|
182
|
-
}
|
|
183
|
-
var dispatchProxyFactory;
|
|
184
|
-
function __setAppReducerDispatchProxyFactory(factory) {
|
|
185
|
-
dispatchProxyFactory = factory;
|
|
186
|
-
}
|
|
187
|
-
function __clearAppReducerDispatchProxy() {
|
|
188
|
-
dispatchProxyFactory = void 0;
|
|
189
|
-
}
|
|
190
|
-
function useReducerDispatchProxy(reactDispatch) {
|
|
191
|
-
return useMemo(() => {
|
|
192
|
-
return dispatchProxyFactory ? dispatchProxyFactory(reactDispatch) : reactDispatch;
|
|
193
|
-
}, [reactDispatch]);
|
|
194
|
-
}
|
|
195
|
-
function useEnhancedReducerDispatch(reducerDispatch) {
|
|
196
|
-
const logger = useLogger();
|
|
197
|
-
const eventBus = useEventBus();
|
|
198
|
-
return useCallback((action) => {
|
|
199
|
-
logger.debug("[squide] The following action has been dispatched to the AppRouter reducer:", action);
|
|
200
|
-
eventBus.dispatch(`squide-${action.type}`);
|
|
201
|
-
reducerDispatch(action);
|
|
202
|
-
}, [reducerDispatch, logger, eventBus]);
|
|
203
|
-
}
|
|
204
|
-
function useAppRouterReducer(waitForMsw, waitForPublicData, waitForProtectedData) {
|
|
205
|
-
const areModulesInitiallyRegistered = getAreModulesRegistered();
|
|
206
|
-
const areModulesInitiallyReady = getAreModulesReady();
|
|
207
|
-
const isMswInitiallyReady = isMswReady();
|
|
208
|
-
const eventBus = useEventBus();
|
|
209
|
-
useExecuteOnce(useCallback(() => {
|
|
210
|
-
if (areModulesInitiallyRegistered) {
|
|
211
|
-
eventBus.dispatch(ModulesRegisteredEvent);
|
|
212
|
-
}
|
|
213
|
-
return true;
|
|
214
|
-
}, [areModulesInitiallyRegistered, eventBus]), true);
|
|
215
|
-
useExecuteOnce(useCallback(() => {
|
|
216
|
-
if (areModulesInitiallyReady) {
|
|
217
|
-
eventBus.dispatch(ModulesReadyEvent);
|
|
218
|
-
}
|
|
219
|
-
return true;
|
|
220
|
-
}, [areModulesInitiallyReady, eventBus]), true);
|
|
221
|
-
useExecuteOnce(useCallback(() => {
|
|
222
|
-
if (isMswInitiallyReady) {
|
|
223
|
-
eventBus.dispatch(MswReadyEvent);
|
|
224
|
-
}
|
|
225
|
-
return true;
|
|
226
|
-
}, [isMswInitiallyReady, eventBus]), true);
|
|
227
|
-
const [state, reactDispatch] = useReducer(reducer, {
|
|
228
|
-
waitForMsw,
|
|
229
|
-
waitForPublicData,
|
|
230
|
-
waitForProtectedData,
|
|
231
|
-
// When the modules registration functions are awaited, the event listeners are registered after the modules are registered.
|
|
232
|
-
areModulesRegistered: areModulesInitiallyRegistered,
|
|
233
|
-
areModulesReady: areModulesInitiallyReady,
|
|
234
|
-
isMswReady: isMswInitiallyReady,
|
|
235
|
-
isPublicDataReady: false,
|
|
236
|
-
isProtectedDataReady: false,
|
|
237
|
-
activeRouteVisibility: "unknown",
|
|
238
|
-
isUnauthorized: false
|
|
239
|
-
});
|
|
240
|
-
const {
|
|
241
|
-
areModulesRegistered: areModulesRegisteredValue,
|
|
242
|
-
areModulesReady: areModulesReadyValue,
|
|
243
|
-
isMswReady: isMswReadyValue
|
|
244
|
-
} = state;
|
|
245
|
-
const dispatchProxy = useReducerDispatchProxy(reactDispatch);
|
|
246
|
-
const dispatch = useEnhancedReducerDispatch(dispatchProxy);
|
|
247
|
-
useModuleRegistrationStatusDispatcher(areModulesRegisteredValue, areModulesReadyValue, dispatch);
|
|
248
|
-
useMswStatusDispatcher(isMswReadyValue, dispatch);
|
|
249
|
-
useBootstrappingCompletedDispatcher(state);
|
|
250
|
-
return [state, dispatch];
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export { ApplicationBoostrappedEvent, DeferredRegistrationsUpdatedEvent, ModulesReadyEvent, ModulesRegisteredEvent, MswReadyEvent, ProtectedDataReadyEvent, ProtectedDataUpdatedEvent, PublicDataReadyEvent, PublicDataUpdatedEvent, __clearAppReducerDispatchProxy, __setAppReducerDispatchProxyFactory, getAreModulesReady, getAreModulesRegistered, useAppRouterReducer, useBootstrappingCompletedDispatcher, useModuleRegistrationStatusDispatcher, useMswStatusDispatcher };
|
package/dist/chunk-L44KFU57.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useStrictRegistrationMode } from './chunk-WOPD33CM.js';
|
|
2
|
-
import { useAppRouterReducer } from './chunk-JFMSLZ74.js';
|
|
3
|
-
import { RootRoute } from './chunk-PMVN3U47.js';
|
|
4
|
-
import { AppRouterDispatcherContext, AppRouterStateContext } from './chunk-G32YX2KR.js';
|
|
5
|
-
import { useLogger } from '@squide/core';
|
|
6
|
-
import { useRoutes } from '@squide/react-router';
|
|
7
|
-
import { useEffect, useMemo } from 'react';
|
|
8
|
-
import { jsx } from 'react/jsx-runtime';
|
|
9
|
-
|
|
10
|
-
function AppRouter(props) {
|
|
11
|
-
const {
|
|
12
|
-
waitForMsw,
|
|
13
|
-
waitForPublicData = false,
|
|
14
|
-
waitForProtectedData = false,
|
|
15
|
-
children: renderRouterProvider
|
|
16
|
-
} = props;
|
|
17
|
-
const [state, dispatch] = useAppRouterReducer(waitForMsw, waitForPublicData, waitForProtectedData);
|
|
18
|
-
const logger = useLogger();
|
|
19
|
-
const routes = useRoutes();
|
|
20
|
-
useStrictRegistrationMode();
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
logger.debug("[squide] AppRouter state updated:", state);
|
|
23
|
-
}, [state, logger]);
|
|
24
|
-
const routerProvider = useMemo(() => {
|
|
25
|
-
return renderRouterProvider({
|
|
26
|
-
rootRoute: /* @__PURE__ */ jsx(RootRoute, {}),
|
|
27
|
-
registeredRoutes: routes,
|
|
28
|
-
routerProviderProps: {}
|
|
29
|
-
});
|
|
30
|
-
}, [routes, renderRouterProvider]);
|
|
31
|
-
return /* @__PURE__ */ jsx(AppRouterDispatcherContext.Provider, { value: dispatch, children: /* @__PURE__ */ jsx(AppRouterStateContext.Provider, { value: state, children: routerProvider }) });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { AppRouter };
|
package/dist/chunk-MKTGJHQR.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { useCanFetchProtectedData } from './chunk-XDWYPVAJ.js';
|
|
2
|
-
import { useExecuteOnce } from './chunk-TURKCH7J.js';
|
|
3
|
-
import { GlobalDataQueriesError } from './chunk-HE5HKFL3.js';
|
|
4
|
-
import { useAppRouterDispatcher, useAppRouterState } from './chunk-G32YX2KR.js';
|
|
5
|
-
import { useEventBus } from '@squide/core';
|
|
6
|
-
import { useQueries } from '@tanstack/react-query';
|
|
7
|
-
import { useCallback, useRef, useEffect } from 'react';
|
|
8
|
-
|
|
9
|
-
var ProtectedDataFetchStartedEvent = "squide-protected-data-fetch-started";
|
|
10
|
-
var ProtectedDataFetchFailedEvent = "squide-protected-data-fetch-failed";
|
|
11
|
-
function useProtectedDataQueries(queries, isUnauthorizedError) {
|
|
12
|
-
const canFetchProtectedData = useCanFetchProtectedData();
|
|
13
|
-
const eventBus = useEventBus();
|
|
14
|
-
const dispatch = useAppRouterDispatcher();
|
|
15
|
-
const combineResults = useCallback((results) => {
|
|
16
|
-
const errors = results.filter((x) => x.error).map((x) => x.error);
|
|
17
|
-
const hasErrors2 = errors.length > 0;
|
|
18
|
-
return {
|
|
19
|
-
data: results.map((x) => x.data),
|
|
20
|
-
errors,
|
|
21
|
-
hasErrors: hasErrors2,
|
|
22
|
-
isReady: !hasErrors2 && !results.some((x) => x.isPending)
|
|
23
|
-
};
|
|
24
|
-
}, []);
|
|
25
|
-
const { data, errors: queriesErrors, hasErrors, isReady } = useQueries({
|
|
26
|
-
queries: queries.map((x) => ({
|
|
27
|
-
enabled: canFetchProtectedData,
|
|
28
|
-
...x
|
|
29
|
-
})),
|
|
30
|
-
combine: combineResults
|
|
31
|
-
});
|
|
32
|
-
const { isProtectedDataReady, isUnauthorized } = useAppRouterState();
|
|
33
|
-
useExecuteOnce(useCallback(() => {
|
|
34
|
-
if (canFetchProtectedData) {
|
|
35
|
-
eventBus.dispatch(ProtectedDataFetchStartedEvent);
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
}, [canFetchProtectedData, eventBus]), true);
|
|
40
|
-
const isReadyRef = useRef(false);
|
|
41
|
-
const dispatchReady = useExecuteOnce(useCallback(() => {
|
|
42
|
-
if (isReady) {
|
|
43
|
-
isReadyRef.current = true;
|
|
44
|
-
dispatch({ type: "protected-data-ready" });
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return false;
|
|
48
|
-
}, [isReady, dispatch]));
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
dispatchReady();
|
|
51
|
-
}, [dispatchReady]);
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (isReadyRef.current && data) {
|
|
54
|
-
dispatch({ type: "protected-data-updated" });
|
|
55
|
-
}
|
|
56
|
-
}, [data, dispatch]);
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (hasErrors) {
|
|
59
|
-
if (!isProtectedDataReady && !isUnauthorized && queriesErrors.some((x) => isUnauthorizedError(x))) {
|
|
60
|
-
dispatch({ type: "is-unauthorized" });
|
|
61
|
-
}
|
|
62
|
-
if (!queriesErrors.every((x) => isUnauthorizedError(x))) {
|
|
63
|
-
eventBus.dispatch(ProtectedDataFetchFailedEvent, queriesErrors);
|
|
64
|
-
throw new GlobalDataQueriesError("[squide] Global protected data queries failed.", queriesErrors);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}, [hasErrors, queriesErrors, isProtectedDataReady, isUnauthorized, isUnauthorizedError, dispatch, eventBus]);
|
|
68
|
-
return data;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export { ProtectedDataFetchFailedEvent, ProtectedDataFetchStartedEvent, useProtectedDataQueries };
|