@squide/firefly 9.3.1 → 9.3.3
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 +68 -8
- package/dist/AppRouter.js.map +1 -0
- package/dist/AppRouterContext.d.ts +5 -9
- package/dist/AppRouterContext.js +30 -1
- package/dist/AppRouterContext.js.map +1 -0
- package/dist/AppRouterReducer.d.ts +23 -26
- package/dist/AppRouterReducer.js +339 -4
- package/dist/AppRouterReducer.js.map +1 -0
- package/dist/FireflyRuntime.d.ts +5 -8
- package/dist/FireflyRuntime.js +66 -5
- package/dist/FireflyRuntime.js.map +1 -0
- package/dist/GlobalDataQueriesError.d.ts +2 -4
- package/dist/GlobalDataQueriesError.js +19 -1
- package/dist/GlobalDataQueriesError.js.map +1 -0
- package/dist/RootRoute.d.ts +1 -5
- package/dist/RootRoute.js +48 -3
- package/dist/RootRoute.js.map +1 -0
- package/dist/boostrap.d.ts +8 -13
- package/dist/boostrap.js +54 -1
- package/dist/boostrap.js.map +1 -0
- package/dist/index.d.ts +23 -28
- package/dist/index.js +51 -25
- package/dist/index.js.map +1 -0
- package/dist/useCanFetchProtectedData.d.ts +1 -3
- package/dist/useCanFetchProtectedData.js +17 -2
- package/dist/useCanFetchProtectedData.js.map +1 -0
- package/dist/useCanFetchPublicData.d.ts +1 -3
- package/dist/useCanFetchPublicData.js +17 -2
- package/dist/useCanFetchPublicData.js.map +1 -0
- package/dist/useCanRegisterDeferredRegistrations.d.ts +1 -3
- package/dist/useCanRegisterDeferredRegistrations.js +14 -2
- package/dist/useCanRegisterDeferredRegistrations.js.map +1 -0
- package/dist/useCanUpdateDeferredRegistrations.d.ts +1 -3
- package/dist/useCanUpdateDeferredRegistrations.js +16 -2
- package/dist/useCanUpdateDeferredRegistrations.js.map +1 -0
- package/dist/useDeferredRegistrations.d.ts +5 -8
- package/dist/useDeferredRegistrations.js +74 -6
- package/dist/useDeferredRegistrations.js.map +1 -0
- package/dist/useExecuteOnce.d.ts +1 -3
- package/dist/useExecuteOnce.js +29 -1
- package/dist/useExecuteOnce.js.map +1 -0
- package/dist/useIsActiveRouteProtected.d.ts +1 -3
- package/dist/useIsActiveRouteProtected.js +23 -1
- package/dist/useIsActiveRouteProtected.js.map +1 -0
- package/dist/useIsBootstrapping.d.ts +3 -7
- package/dist/useIsBootstrapping.js +22 -2
- package/dist/useIsBootstrapping.js.map +1 -0
- package/dist/useNavigationItems.d.ts +3 -7
- package/dist/useNavigationItems.js +26 -2
- package/dist/useNavigationItems.js.map +1 -0
- package/dist/useProtectedDataQueries.d.ts +6 -8
- package/dist/useProtectedDataQueries.js +126 -5
- package/dist/useProtectedDataQueries.js.map +1 -0
- package/dist/usePublicDataQueries.d.ts +5 -7
- package/dist/usePublicDataQueries.js +111 -5
- package/dist/usePublicDataQueries.js.map +1 -0
- package/dist/useRegisterDeferredRegistrations.d.ts +4 -9
- package/dist/useRegisterDeferredRegistrations.js +19 -1
- package/dist/useRegisterDeferredRegistrations.js.map +1 -0
- package/dist/useStrictRegistrationMode.d.ts +1 -3
- package/dist/useStrictRegistrationMode.js +40 -1
- package/dist/useStrictRegistrationMode.js.map +1 -0
- package/dist/useUpdateDeferredRegistrations.d.ts +4 -9
- package/dist/useUpdateDeferredRegistrations.js +30 -2
- package/dist/useUpdateDeferredRegistrations.js.map +1 -0
- package/package.json +29 -24
- package/src/AppRouter.tsx +63 -0
- package/src/AppRouterContext.ts +27 -0
- package/src/AppRouterReducer.ts +363 -0
- package/src/FireflyRuntime.tsx +71 -0
- package/src/GlobalDataQueriesError.ts +17 -0
- package/src/RootRoute.tsx +25 -0
- package/src/boostrap.ts +62 -0
- package/src/index.ts +28 -0
- package/src/useCanFetchProtectedData.ts +26 -0
- package/src/useCanFetchPublicData.ts +23 -0
- package/src/useCanRegisterDeferredRegistrations.ts +24 -0
- package/src/useCanUpdateDeferredRegistrations.ts +23 -0
- package/src/useDeferredRegistrations.ts +59 -0
- package/src/useExecuteOnce.ts +23 -0
- package/src/useIsActiveRouteProtected.ts +12 -0
- package/src/useIsBootstrapping.ts +45 -0
- package/src/useNavigationItems.ts +18 -0
- package/src/useProtectedDataQueries.ts +101 -0
- package/src/usePublicDataQueries.ts +88 -0
- package/src/useRegisterDeferredRegistrations.ts +9 -0
- package/src/useStrictRegistrationMode.ts +28 -0
- package/src/useUpdateDeferredRegistrations.ts +16 -0
- package/dist/chunk-4RUCDAUT.js +0 -18
- package/dist/chunk-BFHHJOJT.js +0 -41
- 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-IOMSOUAL.js +0 -20
- package/dist/chunk-JFMSLZ74.js +0 -253
- package/dist/chunk-L44KFU57.js +0 -34
- package/dist/chunk-LC233OPR.js +0 -54
- 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-ROE2YHN5.js +0 -44
- 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
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__ from "./AppRouterContext.js";
|
|
2
|
+
|
|
3
|
+
;// CONCATENATED MODULE: external "./AppRouterContext.js"
|
|
4
|
+
|
|
5
|
+
;// CONCATENATED MODULE: ./src/useCanUpdateDeferredRegistrations.ts?__rslib_entry__
|
|
6
|
+
|
|
7
|
+
function useCanUpdateDeferredRegistrations() {
|
|
8
|
+
const { areModulesReady, publicDataUpdatedAt, protectedDataUpdatedAt, deferredRegistrationsUpdatedAt } = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.useAppRouterState)();
|
|
9
|
+
return(// Do not trigger an update if the deferred registrations has not been registered yet (if there are deferred registrations, once they are
|
|
10
|
+
// registered, the modules will be marked as ready).
|
|
11
|
+
areModulesReady && deferredRegistrationsUpdatedAt && (publicDataUpdatedAt && publicDataUpdatedAt > deferredRegistrationsUpdatedAt || protectedDataUpdatedAt && protectedDataUpdatedAt > deferredRegistrationsUpdatedAt));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { useCanUpdateDeferredRegistrations };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=useCanUpdateDeferredRegistrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCanUpdateDeferredRegistrations.js","sources":["webpack://@squide/firefly/./src/useCanUpdateDeferredRegistrations.ts"],"sourcesContent":["import { useAppRouterState } from \"./AppRouterContext.ts\";\n\nexport function useCanUpdateDeferredRegistrations() {\n const {\n areModulesReady,\n publicDataUpdatedAt,\n protectedDataUpdatedAt,\n deferredRegistrationsUpdatedAt\n } = useAppRouterState();\n\n return (\n // Do not trigger an update if the deferred registrations has not been registered yet (if there are deferred registrations, once they are\n // registered, the modules will be marked as ready).\n areModulesReady\n // Make sure the apps is actually having deferred registrations.\n && deferredRegistrationsUpdatedAt\n // If either the public data or the protected data has been updated, update the deferred registrations.\n && (\n (publicDataUpdatedAt && publicDataUpdatedAt > deferredRegistrationsUpdatedAt) ||\n (protectedDataUpdatedAt && protectedDataUpdatedAt > deferredRegistrationsUpdatedAt)\n )\n );\n}\n"],"names":["useAppRouterState","useCanUpdateDeferredRegistrations","areModulesReady","publicDataUpdatedAt","protectedDataUpdatedAt","deferredRegistrationsUpdatedAt"],"mappings":";;;;;AAA0D;AAEnD,SAASC;IACZ,MAAM,EACFC,eAAe,EACfC,mBAAmB,EACnBC,sBAAsB,EACtBC,8BAA8B,EACjC,GAAGL,+EAAiBA;IAErB,OACI,yIAAyI;IACzI,oDAAoD;IACpDE,mBAEGG,kCAGC,CAACF,uBAAuBA,sBAAsBE,kCAC7CD,0BAA0BA,yBAAyBC,8BAA8B;AAG9F"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { ModuleRegistrationError } from
|
|
2
|
-
|
|
3
|
-
interface DeferredRegistrationsErrorsObject {
|
|
1
|
+
import { type ModuleRegistrationError } from "@squide/core";
|
|
2
|
+
export interface DeferredRegistrationsErrorsObject {
|
|
4
3
|
localModuleErrors: ModuleRegistrationError[];
|
|
5
4
|
remoteModuleErrors: ModuleRegistrationError[];
|
|
6
5
|
}
|
|
7
|
-
type DeferredRegistrationsErrorCallback = (errorsObject: DeferredRegistrationsErrorsObject) => void;
|
|
8
|
-
interface UseDeferredRegistrationsOptions {
|
|
6
|
+
export type DeferredRegistrationsErrorCallback = (errorsObject: DeferredRegistrationsErrorsObject) => void;
|
|
7
|
+
export interface UseDeferredRegistrationsOptions {
|
|
9
8
|
onError?: DeferredRegistrationsErrorCallback;
|
|
10
9
|
}
|
|
11
|
-
declare function useDeferredRegistrations(data: unknown, { onError }?: UseDeferredRegistrationsOptions): void;
|
|
12
|
-
|
|
13
|
-
export { type DeferredRegistrationsErrorCallback, type DeferredRegistrationsErrorsObject, type UseDeferredRegistrationsOptions, useDeferredRegistrations };
|
|
10
|
+
export declare function useDeferredRegistrations(data: unknown, { onError }?: UseDeferredRegistrationsOptions): void;
|
|
@@ -1,6 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__core_src_index_js_d19dd8a6__ from "../../core/src/index.js";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useCanRegisterDeferredRegistrations_js_257f17d4__ from "./useCanRegisterDeferredRegistrations.js";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useCanUpdateDeferredRegistrations_js_12932b2c__ from "./useCanUpdateDeferredRegistrations.js";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useRegisterDeferredRegistrations_js_eed558b9__ from "./useRegisterDeferredRegistrations.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useUpdateDeferredRegistrations_js_80de5337__ from "./useUpdateDeferredRegistrations.js";
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: external "../../core/src/index.js"
|
|
9
|
+
|
|
10
|
+
;// CONCATENATED MODULE: external "react"
|
|
11
|
+
|
|
12
|
+
;// CONCATENATED MODULE: external "./useCanRegisterDeferredRegistrations.js"
|
|
13
|
+
|
|
14
|
+
;// CONCATENATED MODULE: external "./useCanUpdateDeferredRegistrations.js"
|
|
15
|
+
|
|
16
|
+
;// CONCATENATED MODULE: external "./useRegisterDeferredRegistrations.js"
|
|
17
|
+
|
|
18
|
+
;// CONCATENATED MODULE: external "./useUpdateDeferredRegistrations.js"
|
|
19
|
+
|
|
20
|
+
;// CONCATENATED MODULE: ./src/useDeferredRegistrations.ts?__rslib_entry__
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function hasError({ localModuleErrors, remoteModuleErrors }) {
|
|
28
|
+
return localModuleErrors.length > 0 || remoteModuleErrors.length > 0;
|
|
29
|
+
}
|
|
30
|
+
function useDeferredRegistrations(data, { onError } = {}) {
|
|
31
|
+
const runtime = (0,__WEBPACK_EXTERNAL_MODULE__core_src_index_js_d19dd8a6__.useRuntime)();
|
|
32
|
+
const canRegisterDeferredRegistrations = (0,__WEBPACK_EXTERNAL_MODULE__useCanRegisterDeferredRegistrations_js_257f17d4__.useCanRegisterDeferredRegistrations)();
|
|
33
|
+
const canUpdateDeferredRegistrations = (0,__WEBPACK_EXTERNAL_MODULE__useCanUpdateDeferredRegistrations_js_12932b2c__.useCanUpdateDeferredRegistrations)();
|
|
34
|
+
const registerDeferredRegistrations = (0,__WEBPACK_EXTERNAL_MODULE__useRegisterDeferredRegistrations_js_eed558b9__.useRegisterDeferredRegistrations)();
|
|
35
|
+
const updateDeferredRegistrations = (0,__WEBPACK_EXTERNAL_MODULE__useUpdateDeferredRegistrations_js_80de5337__.useUpdateDeferredRegistrations)();
|
|
36
|
+
(0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
37
|
+
if (canRegisterDeferredRegistrations) {
|
|
38
|
+
const register = async ()=>{
|
|
39
|
+
const errors = await registerDeferredRegistrations(data, runtime);
|
|
40
|
+
if (hasError(errors) && onError) {
|
|
41
|
+
onError(errors);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
register();
|
|
45
|
+
}
|
|
46
|
+
}, [
|
|
47
|
+
canRegisterDeferredRegistrations,
|
|
48
|
+
registerDeferredRegistrations,
|
|
49
|
+
data,
|
|
50
|
+
onError,
|
|
51
|
+
runtime
|
|
52
|
+
]);
|
|
53
|
+
(0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
54
|
+
if (canUpdateDeferredRegistrations) {
|
|
55
|
+
const update = async ()=>{
|
|
56
|
+
const errors = await updateDeferredRegistrations(data, runtime);
|
|
57
|
+
if (hasError(errors) && onError) {
|
|
58
|
+
onError(errors);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
update();
|
|
62
|
+
}
|
|
63
|
+
}, [
|
|
64
|
+
canUpdateDeferredRegistrations,
|
|
65
|
+
updateDeferredRegistrations,
|
|
66
|
+
data,
|
|
67
|
+
onError,
|
|
68
|
+
runtime
|
|
69
|
+
]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { useDeferredRegistrations };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=useDeferredRegistrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDeferredRegistrations.js","sources":["webpack://@squide/firefly/./src/useDeferredRegistrations.ts"],"sourcesContent":["import { useRuntime, type ModuleRegistrationError } from \"@squide/core\";\nimport { useEffect } from \"react\";\nimport { useCanRegisterDeferredRegistrations } from \"./useCanRegisterDeferredRegistrations.ts\";\nimport { useCanUpdateDeferredRegistrations } from \"./useCanUpdateDeferredRegistrations.ts\";\nimport { useRegisterDeferredRegistrations } from \"./useRegisterDeferredRegistrations.ts\";\nimport { useUpdateDeferredRegistrations } from \"./useUpdateDeferredRegistrations.ts\";\n\nexport interface DeferredRegistrationsErrorsObject {\n localModuleErrors: ModuleRegistrationError[];\n remoteModuleErrors: ModuleRegistrationError[];\n}\n\nexport type DeferredRegistrationsErrorCallback = (errorsObject: DeferredRegistrationsErrorsObject) => void;\n\nexport interface UseDeferredRegistrationsOptions {\n onError?: DeferredRegistrationsErrorCallback;\n}\n\nfunction hasError({ localModuleErrors, remoteModuleErrors }: DeferredRegistrationsErrorsObject) {\n return localModuleErrors.length > 0 || remoteModuleErrors.length > 0;\n}\n\nexport function useDeferredRegistrations(data: unknown, { onError }: UseDeferredRegistrationsOptions = {}) {\n const runtime = useRuntime();\n\n const canRegisterDeferredRegistrations = useCanRegisterDeferredRegistrations();\n const canUpdateDeferredRegistrations = useCanUpdateDeferredRegistrations();\n\n const registerDeferredRegistrations = useRegisterDeferredRegistrations();\n const updateDeferredRegistrations = useUpdateDeferredRegistrations();\n\n useEffect(() => {\n if (canRegisterDeferredRegistrations) {\n const register = async () => {\n const errors = await registerDeferredRegistrations(data, runtime);\n\n if (hasError(errors) && onError) {\n onError(errors);\n }\n };\n\n register();\n }\n }, [canRegisterDeferredRegistrations, registerDeferredRegistrations, data, onError, runtime]);\n\n useEffect(() => {\n if (canUpdateDeferredRegistrations) {\n const update = async () => {\n const errors = await updateDeferredRegistrations(data, runtime);\n\n if (hasError(errors) && onError) {\n onError(errors);\n }\n };\n\n update();\n }\n }, [canUpdateDeferredRegistrations, updateDeferredRegistrations, data, onError, runtime]);\n}\n"],"names":["useRuntime","useEffect","useCanRegisterDeferredRegistrations","useCanUpdateDeferredRegistrations","useRegisterDeferredRegistrations","useUpdateDeferredRegistrations","hasError","localModuleErrors","remoteModuleErrors","useDeferredRegistrations","data","onError","runtime","canRegisterDeferredRegistrations","canUpdateDeferredRegistrations","registerDeferredRegistrations","updateDeferredRegistrations","register","errors","update"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAwE;AACtC;AAC6D;AACJ;AACF;AACJ;AAarF,SAASM,SAAS,EAAEC,iBAAiB,EAAEC,kBAAkB,EAAqC;IAC1F,OAAOD,kBAAkB,MAAM,GAAG,KAAKC,mBAAmB,MAAM,GAAG;AACvE;AAEO,SAASC,yBAAyBC,IAAa,EAAE,EAAEC,OAAO,EAAmC,GAAG,CAAC,CAAC;IACrG,MAAMC,UAAUZ,sEAAUA;IAE1B,MAAMa,mCAAmCX,oHAAmCA;IAC5E,MAAMY,iCAAiCX,gHAAiCA;IAExE,MAAMY,gCAAgCX,8GAAgCA;IACtE,MAAMY,8BAA8BX,0GAA8BA;IAElEJ,+CAASA,CAAC;QACN,IAAIY,kCAAkC;YAClC,MAAMI,WAAW;gBACb,MAAMC,SAAS,MAAMH,8BAA8BL,MAAME;gBAEzD,IAAIN,SAASY,WAAWP,SAAS;oBAC7BA,QAAQO;gBACZ;YACJ;YAEAD;QACJ;IACJ,GAAG;QAACJ;QAAkCE;QAA+BL;QAAMC;QAASC;KAAQ;IAE5FX,+CAASA,CAAC;QACN,IAAIa,gCAAgC;YAChC,MAAMK,SAAS;gBACX,MAAMD,SAAS,MAAMF,4BAA4BN,MAAME;gBAEvD,IAAIN,SAASY,WAAWP,SAAS;oBAC7BA,QAAQO;gBACZ;YACJ;YAEAC;QACJ;IACJ,GAAG;QAACL;QAAgCE;QAA6BN;QAAMC;QAASC;KAAQ;AAC5F"}
|
package/dist/useExecuteOnce.d.ts
CHANGED
package/dist/useExecuteOnce.js
CHANGED
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
2
|
+
|
|
3
|
+
;// CONCATENATED MODULE: external "react"
|
|
4
|
+
|
|
5
|
+
;// CONCATENATED MODULE: ./src/useExecuteOnce.ts?__rslib_entry__
|
|
6
|
+
|
|
7
|
+
// Not using useEffect or useLayoutEffect because this utility hook is often used to dispatch events
|
|
8
|
+
// and it messed with the events dispatch order.
|
|
9
|
+
function useExecuteOnce(fct, inline = false) {
|
|
10
|
+
const triggered = (0,__WEBPACK_EXTERNAL_MODULE_react__.useRef)(false);
|
|
11
|
+
const onceFct = (0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
12
|
+
if (!triggered.current) {
|
|
13
|
+
const result = fct();
|
|
14
|
+
if (result) {
|
|
15
|
+
triggered.current = true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}, [
|
|
19
|
+
fct
|
|
20
|
+
]);
|
|
21
|
+
if (inline) {
|
|
22
|
+
onceFct();
|
|
23
|
+
}
|
|
24
|
+
return onceFct;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { useExecuteOnce };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=useExecuteOnce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useExecuteOnce.js","sources":["webpack://@squide/firefly/./src/useExecuteOnce.ts"],"sourcesContent":["import { useCallback, useRef } from \"react\";\n\n// Not using useEffect or useLayoutEffect because this utility hook is often used to dispatch events\n// and it messed with the events dispatch order.\nexport function useExecuteOnce(fct: () => boolean, inline: boolean = false) {\n const triggered = useRef(false);\n\n const onceFct = useCallback(() => {\n if (!triggered.current) {\n const result = fct();\n\n if (result) {\n triggered.current = true;\n }\n }\n }, [fct]);\n\n if (inline) {\n onceFct();\n }\n\n return onceFct;\n}\n"],"names":["useCallback","useRef","useExecuteOnce","fct","inline","triggered","onceFct","result"],"mappings":";;;;;AAA4C;AAE5C,oGAAoG;AACpG,gDAAgD;AACzC,SAASE,eAAeC,GAAkB,EAAEC,SAAkB,KAAK;IACtE,MAAMC,YAAYJ,4CAAMA,CAAC;IAEzB,MAAMK,UAAUN,iDAAWA,CAAC;QACxB,IAAI,CAACK,UAAU,OAAO,EAAE;YACpB,MAAME,SAASJ;YAEf,IAAII,QAAQ;gBACRF,UAAU,OAAO,GAAG;YACxB;QACJ;IACJ,GAAG;QAACF;KAAI;IAER,IAAIC,QAAQ;QACRE;IACJ;IAEA,OAAOA;AACX"}
|
|
@@ -1 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__react_router_src_index_js_ff6a88b1__ from "../../react-router/src/index.js";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__ from "react-router-dom";
|
|
3
|
+
|
|
4
|
+
;// CONCATENATED MODULE: external "../../react-router/src/index.js"
|
|
5
|
+
|
|
6
|
+
;// CONCATENATED MODULE: external "react-router-dom"
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: ./src/useIsActiveRouteProtected.ts?__rslib_entry__
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function useIsActiveRouteProtected(areModulesReady) {
|
|
12
|
+
// Using this hook instead of window.location to retrieve the current location because it triggers a re-render everytime the browser location change.
|
|
13
|
+
const location = (0,__WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.useLocation)();
|
|
14
|
+
// Only throw when there's no match if the modules are ready, otherwise it's expected that no route will be found since they are not all registered yet.
|
|
15
|
+
const activeRoute = (0,__WEBPACK_EXTERNAL_MODULE__react_router_src_index_js_ff6a88b1__.useRouteMatch)(location, {
|
|
16
|
+
throwWhenThereIsNoMatch: areModulesReady
|
|
17
|
+
});
|
|
18
|
+
return (0,__WEBPACK_EXTERNAL_MODULE__react_router_src_index_js_ff6a88b1__.useIsRouteProtected)(activeRoute);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { useIsActiveRouteProtected };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=useIsActiveRouteProtected.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsActiveRouteProtected.js","sources":["webpack://@squide/firefly/./src/useIsActiveRouteProtected.ts"],"sourcesContent":["import { useIsRouteProtected, useRouteMatch } from \"@squide/react-router\";\nimport { useLocation } from \"react-router-dom\";\n\nexport function useIsActiveRouteProtected(areModulesReady: boolean) {\n // Using this hook instead of window.location to retrieve the current location because it triggers a re-render everytime the browser location change.\n const location = useLocation();\n\n // Only throw when there's no match if the modules are ready, otherwise it's expected that no route will be found since they are not all registered yet.\n const activeRoute = useRouteMatch(location, { throwWhenThereIsNoMatch: areModulesReady });\n\n return useIsRouteProtected(activeRoute);\n}\n"],"names":["useIsRouteProtected","useRouteMatch","useLocation","useIsActiveRouteProtected","areModulesReady","location","activeRoute"],"mappings":";;;;;;;;AAA0E;AAC3B;AAExC,SAASG,0BAA0BC,eAAwB;IAC9D,qJAAqJ;IACrJ,MAAMC,WAAWH,qEAAWA;IAE5B,wJAAwJ;IACxJ,MAAMI,cAAcL,iFAAaA,CAACI,UAAU;QAAE,yBAAyBD;IAAgB;IAEvF,OAAOJ,uFAAmBA,CAACM;AAC/B"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { AppRouterState } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare function useIsBootstrapping(): boolean;
|
|
5
|
-
declare function isApplicationBootstrapping(state: AppRouterState): boolean;
|
|
6
|
-
|
|
7
|
-
export { isApplicationBootstrapping, useIsBootstrapping };
|
|
1
|
+
import type { AppRouterState } from "./AppRouterReducer.ts";
|
|
2
|
+
export declare function useIsBootstrapping(): boolean;
|
|
3
|
+
export declare function isApplicationBootstrapping(state: AppRouterState): boolean;
|
|
@@ -1,2 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__ from "./AppRouterContext.js";
|
|
2
|
+
|
|
3
|
+
;// CONCATENATED MODULE: external "./AppRouterContext.js"
|
|
4
|
+
|
|
5
|
+
;// CONCATENATED MODULE: ./src/useIsBootstrapping.ts?__rslib_entry__
|
|
6
|
+
|
|
7
|
+
function useIsBootstrapping() {
|
|
8
|
+
const state = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.useAppRouterState)();
|
|
9
|
+
return isApplicationBootstrapping(state);
|
|
10
|
+
}
|
|
11
|
+
function isApplicationBootstrapping(state) {
|
|
12
|
+
const { waitForMsw, waitForPublicData, waitForProtectedData, areModulesReady, isMswReady, isPublicDataReady, isProtectedDataReady, activeRouteVisibility, isUnauthorized } = state;
|
|
13
|
+
const isAppReady = !isUnauthorized && areModulesReady && (!waitForMsw || isMswReady) && (!waitForPublicData || isPublicDataReady) && (!waitForProtectedData || activeRouteVisibility === "public" || isProtectedDataReady);
|
|
14
|
+
// When an API request returns a 401, the bootstrapping should be bypassed to render the login page.
|
|
15
|
+
const flush = // Only applicable when there's a unauthorized request while fetching the initial data.
|
|
16
|
+
isUnauthorized && (!waitForMsw || isMswReady) && (!waitForPublicData || isPublicDataReady);
|
|
17
|
+
return !isAppReady && !flush;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { isApplicationBootstrapping, useIsBootstrapping };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=useIsBootstrapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsBootstrapping.js","sources":["webpack://@squide/firefly/./src/useIsBootstrapping.ts"],"sourcesContent":["import { useAppRouterState } from \"./AppRouterContext.ts\";\nimport type { AppRouterState } from \"./AppRouterReducer.ts\";\n\nexport function useIsBootstrapping() {\n const state = useAppRouterState();\n\n return isApplicationBootstrapping(state);\n}\n\nexport function isApplicationBootstrapping(state: AppRouterState) {\n const {\n waitForMsw,\n waitForPublicData,\n waitForProtectedData,\n areModulesReady,\n isMswReady,\n isPublicDataReady,\n isProtectedDataReady,\n activeRouteVisibility,\n isUnauthorized\n } = state;\n\n const isAppReady = (\n !isUnauthorized\n // Wait until the modules has been registered and the deferred registrations has been registered if any.\n && areModulesReady\n // Not required but can sometimes prevent a re-render when the state value is somehow updated after the initial data is ready.\n && (!waitForMsw || isMswReady)\n // Wait for the initial data to be ready.\n && (!waitForPublicData || isPublicDataReady)\n && (!waitForProtectedData || activeRouteVisibility === \"public\" || isProtectedDataReady)\n );\n\n // When an API request returns a 401, the bootstrapping should be bypassed to render the login page.\n const flush = (\n // Only applicable when there's a unauthorized request while fetching the initial data.\n isUnauthorized\n // Not required but can sometimes prevent a re-render when the state value is somehow updated after the public data is ready.\n && (!waitForMsw || isMswReady)\n // If the application is loading public data, we want to wait for this data to be ready to prevent a re-render.\n && (!waitForPublicData || isPublicDataReady)\n );\n\n return !isAppReady && !flush;\n}\n"],"names":["useAppRouterState","useIsBootstrapping","state","isApplicationBootstrapping","waitForMsw","waitForPublicData","waitForProtectedData","areModulesReady","isMswReady","isPublicDataReady","isProtectedDataReady","activeRouteVisibility","isUnauthorized","isAppReady","flush"],"mappings":";;;;;AAA0D;AAGnD,SAASC;IACZ,MAAMC,QAAQF,+EAAiBA;IAE/B,OAAOG,2BAA2BD;AACtC;AAEO,SAASC,2BAA2BD,KAAqB;IAC5D,MAAM,EACFE,UAAU,EACVC,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,UAAU,EACVC,iBAAiB,EACjBC,oBAAoB,EACpBC,qBAAqB,EACrBC,cAAc,EACjB,GAAGV;IAEJ,MAAMW,aACF,CAACD,kBAEEL,mBAEC,EAACH,cAAcI,UAAS,KAExB,EAACH,qBAAqBI,iBAAgB,KACtC,EAACH,wBAAwBK,0BAA0B,YAAYD,oBAAmB;IAG1F,oGAAoG;IACpG,MAAMI,QACF,uFAAuF;IACvFF,kBAEI,EAACR,cAAcI,UAAS,KAExB,EAACH,qBAAqBI,iBAAgB;IAG9C,OAAO,CAACI,cAAc,CAACC;AAC3B"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type UseNavigationItemsOptions = UseRuntimeNavigationItemsOptions;
|
|
5
|
-
declare function useNavigationItems(options?: UseNavigationItemsOptions): _squide_react_router.RootNavigationItem[];
|
|
6
|
-
|
|
7
|
-
export { type UseNavigationItemsOptions, useNavigationItems };
|
|
1
|
+
import { type UseRuntimeNavigationItemsOptions } from "@squide/react-router";
|
|
2
|
+
export type UseNavigationItemsOptions = UseRuntimeNavigationItemsOptions;
|
|
3
|
+
export declare function useNavigationItems(options?: UseNavigationItemsOptions): import("@squide/react-router").RootNavigationItem[];
|
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__react_router_src_index_js_ff6a88b1__ from "../../react-router/src/index.js";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__ from "./AppRouterContext.js";
|
|
3
|
+
|
|
4
|
+
;// CONCATENATED MODULE: external "../../react-router/src/index.js"
|
|
5
|
+
|
|
6
|
+
;// CONCATENATED MODULE: external "./AppRouterContext.js"
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: ./src/useNavigationItems.ts?__rslib_entry__
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function useNavigationItems(options) {
|
|
12
|
+
// This is not the most sophisticated strategy but it seems to be good enough for now.
|
|
13
|
+
// The idea is that when deferred registrations are used by the consumer applications, the deferred registrations could
|
|
14
|
+
// be updated when the global data is updated. If the deferred registrations are updated, it means that the registered
|
|
15
|
+
// navigation items might have been updated and a re-render must happens to display the new navigation items.
|
|
16
|
+
// Since the "deferredRegistrationsUpdatedAt" state value of the AppRouterReducer is updated everytime the deferred registrations
|
|
17
|
+
// are updated, subscribing to the state with useAppRouterState ensure that the navigation items will be re-rendered.
|
|
18
|
+
// A more sophisticated strategy could be implemented later on if needed, something involving a subscription to the "runtime" changes, or
|
|
19
|
+
// even introducing new module states.
|
|
20
|
+
(0,__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.useAppRouterState)();
|
|
21
|
+
return (0,__WEBPACK_EXTERNAL_MODULE__react_router_src_index_js_ff6a88b1__.useRuntimeNavigationItems)(options);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { useNavigationItems };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=useNavigationItems.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNavigationItems.js","sources":["webpack://@squide/firefly/./src/useNavigationItems.ts"],"sourcesContent":["import { useRuntimeNavigationItems, type UseRuntimeNavigationItemsOptions } from \"@squide/react-router\";\nimport { useAppRouterState } from \"./AppRouterContext.ts\";\n\nexport type UseNavigationItemsOptions = UseRuntimeNavigationItemsOptions;\n\nexport function useNavigationItems(options?: UseNavigationItemsOptions) {\n // This is not the most sophisticated strategy but it seems to be good enough for now.\n // The idea is that when deferred registrations are used by the consumer applications, the deferred registrations could\n // be updated when the global data is updated. If the deferred registrations are updated, it means that the registered\n // navigation items might have been updated and a re-render must happens to display the new navigation items.\n // Since the \"deferredRegistrationsUpdatedAt\" state value of the AppRouterReducer is updated everytime the deferred registrations\n // are updated, subscribing to the state with useAppRouterState ensure that the navigation items will be re-rendered.\n // A more sophisticated strategy could be implemented later on if needed, something involving a subscription to the \"runtime\" changes, or\n // even introducing new module states.\n useAppRouterState();\n\n return useRuntimeNavigationItems(options);\n}\n"],"names":["useRuntimeNavigationItems","useAppRouterState","useNavigationItems","options"],"mappings":";;;;;;;;AAAwG;AAC9C;AAInD,SAASE,mBAAmBC,OAAmC;IAClE,sFAAsF;IACtF,uHAAuH;IACvH,sHAAsH;IACtH,6GAA6G;IAC7G,iIAAiI;IACjI,qHAAqH;IACrH,yIAAyI;IACzI,sCAAsC;IACtCF,+EAAiBA;IAEjB,OAAOD,6FAAyBA,CAACG;AACrC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { QueriesOptions, QueriesResults, UseQueryResult } from
|
|
2
|
-
|
|
3
|
-
declare const
|
|
4
|
-
|
|
5
|
-
type IsUnauthorizedErrorCallback = (error: unknown) => boolean;
|
|
1
|
+
import { type QueriesOptions, type QueriesResults, type UseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
export declare const ProtectedDataFetchStartedEvent = "squide-protected-data-fetch-started";
|
|
3
|
+
export declare const ProtectedDataFetchFailedEvent = "squide-protected-data-fetch-failed";
|
|
4
|
+
export type IsUnauthorizedErrorCallback = (error: unknown) => boolean;
|
|
6
5
|
type MapUseQueryResultToData<T> = {
|
|
7
6
|
[K in keyof T]: T[K] extends UseQueryResult<infer U> ? U : never;
|
|
8
7
|
};
|
|
9
|
-
declare function useProtectedDataQueries<T extends Array<any>>(queries: QueriesOptions<T>, isUnauthorizedError: IsUnauthorizedErrorCallback): MapUseQueryResultToData<QueriesResults<T>>;
|
|
10
|
-
|
|
11
|
-
export { type IsUnauthorizedErrorCallback, ProtectedDataFetchFailedEvent, ProtectedDataFetchStartedEvent, useProtectedDataQueries };
|
|
8
|
+
export declare function useProtectedDataQueries<T extends Array<any>>(queries: QueriesOptions<T>, isUnauthorizedError: IsUnauthorizedErrorCallback): MapUseQueryResultToData<QueriesResults<T>>;
|
|
9
|
+
export {};
|
|
@@ -1,5 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__core_src_index_js_d19dd8a6__ from "../../core/src/index.js";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__tanstack_react_query_db705f77__ from "@tanstack/react-query";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__ from "./AppRouterContext.js";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__GlobalDataQueriesError_js_0c24ca62__ from "./GlobalDataQueriesError.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useCanFetchProtectedData_js_52158d16__ from "./useCanFetchProtectedData.js";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__ from "./useExecuteOnce.js";
|
|
8
|
+
|
|
9
|
+
;// CONCATENATED MODULE: external "../../core/src/index.js"
|
|
10
|
+
|
|
11
|
+
;// CONCATENATED MODULE: external "@tanstack/react-query"
|
|
12
|
+
|
|
13
|
+
;// CONCATENATED MODULE: external "react"
|
|
14
|
+
|
|
15
|
+
;// CONCATENATED MODULE: external "./AppRouterContext.js"
|
|
16
|
+
|
|
17
|
+
;// CONCATENATED MODULE: external "./GlobalDataQueriesError.js"
|
|
18
|
+
|
|
19
|
+
;// CONCATENATED MODULE: external "./useCanFetchProtectedData.js"
|
|
20
|
+
|
|
21
|
+
;// CONCATENATED MODULE: external "./useExecuteOnce.js"
|
|
22
|
+
|
|
23
|
+
;// CONCATENATED MODULE: ./src/useProtectedDataQueries.ts?__rslib_entry__
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const ProtectedDataFetchStartedEvent = "squide-protected-data-fetch-started";
|
|
32
|
+
const ProtectedDataFetchFailedEvent = "squide-protected-data-fetch-failed";
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
function useProtectedDataQueries(queries, isUnauthorizedError) {
|
|
35
|
+
const canFetchProtectedData = (0,__WEBPACK_EXTERNAL_MODULE__useCanFetchProtectedData_js_52158d16__.useCanFetchProtectedData)();
|
|
36
|
+
const eventBus = (0,__WEBPACK_EXTERNAL_MODULE__core_src_index_js_d19dd8a6__.useEventBus)();
|
|
37
|
+
const dispatch = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.useAppRouterDispatcher)();
|
|
38
|
+
const combineResults = (0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)((results)=>{
|
|
39
|
+
const errors = results.filter((x)=>x.error).map((x)=>x.error);
|
|
40
|
+
const hasErrors = errors.length > 0;
|
|
41
|
+
return {
|
|
42
|
+
data: results.map((x)=>x.data),
|
|
43
|
+
errors,
|
|
44
|
+
hasErrors,
|
|
45
|
+
isReady: !hasErrors && !results.some((x)=>x.isPending)
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
const { data, errors: queriesErrors, hasErrors, isReady } = (0,__WEBPACK_EXTERNAL_MODULE__tanstack_react_query_db705f77__.useQueries)({
|
|
49
|
+
queries: queries.map((x)=>({
|
|
50
|
+
enabled: canFetchProtectedData,
|
|
51
|
+
...x
|
|
52
|
+
})),
|
|
53
|
+
combine: combineResults
|
|
54
|
+
});
|
|
55
|
+
const { isProtectedDataReady, isUnauthorized } = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.useAppRouterState)();
|
|
56
|
+
(0,__WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__.useExecuteOnce)((0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
57
|
+
if (canFetchProtectedData) {
|
|
58
|
+
eventBus.dispatch(ProtectedDataFetchStartedEvent);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}, [
|
|
63
|
+
canFetchProtectedData,
|
|
64
|
+
eventBus
|
|
65
|
+
]), true);
|
|
66
|
+
// Using a ref seems to be the only way to prevent starting two deferred registrations scope.
|
|
67
|
+
const isReadyRef = (0,__WEBPACK_EXTERNAL_MODULE_react__.useRef)(false);
|
|
68
|
+
const dispatchReady = (0,__WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__.useExecuteOnce)((0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
69
|
+
if (isReady) {
|
|
70
|
+
isReadyRef.current = true;
|
|
71
|
+
dispatch({
|
|
72
|
+
type: "protected-data-ready"
|
|
73
|
+
});
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}, [
|
|
78
|
+
isReady,
|
|
79
|
+
dispatch
|
|
80
|
+
]));
|
|
81
|
+
(0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
82
|
+
// State update must be executed in useEffect.
|
|
83
|
+
dispatchReady();
|
|
84
|
+
}, [
|
|
85
|
+
dispatchReady
|
|
86
|
+
]);
|
|
87
|
+
(0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
88
|
+
if (isReadyRef.current && data) {
|
|
89
|
+
dispatch({
|
|
90
|
+
type: "protected-data-updated"
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}, [
|
|
94
|
+
data,
|
|
95
|
+
dispatch
|
|
96
|
+
]);
|
|
97
|
+
(0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
98
|
+
if (hasErrors) {
|
|
99
|
+
if (!isProtectedDataReady && !isUnauthorized && queriesErrors.some((x)=>isUnauthorizedError(x))) {
|
|
100
|
+
// Will transition the state to allow the routes to render even if the bootstrapping is not complete, because otherwise
|
|
101
|
+
// a login page for example could not be rendered.
|
|
102
|
+
dispatch({
|
|
103
|
+
type: "is-unauthorized"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// Otherwise, when a user is logged off, a refetch might throws a 401.
|
|
107
|
+
if (!queriesErrors.every((x)=>isUnauthorizedError(x))) {
|
|
108
|
+
eventBus.dispatch(ProtectedDataFetchFailedEvent, queriesErrors);
|
|
109
|
+
throw new __WEBPACK_EXTERNAL_MODULE__GlobalDataQueriesError_js_0c24ca62__.GlobalDataQueriesError("[squide] Global protected data queries failed.", queriesErrors);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}, [
|
|
113
|
+
hasErrors,
|
|
114
|
+
queriesErrors,
|
|
115
|
+
isProtectedDataReady,
|
|
116
|
+
isUnauthorized,
|
|
117
|
+
isUnauthorizedError,
|
|
118
|
+
dispatch,
|
|
119
|
+
eventBus
|
|
120
|
+
]);
|
|
121
|
+
return data;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { ProtectedDataFetchFailedEvent, ProtectedDataFetchStartedEvent, useProtectedDataQueries };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=useProtectedDataQueries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useProtectedDataQueries.js","sources":["webpack://@squide/firefly/./src/useProtectedDataQueries.ts"],"sourcesContent":["import { useEventBus } from \"@squide/core\";\nimport { useQueries, type QueriesOptions, type QueriesResults, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport { useAppRouterDispatcher, useAppRouterState } from \"./AppRouterContext.ts\";\nimport { GlobalDataQueriesError } from \"./GlobalDataQueriesError.ts\";\nimport { useCanFetchProtectedData } from \"./useCanFetchProtectedData.ts\";\nimport { useExecuteOnce } from \"./useExecuteOnce.ts\";\n\nexport const ProtectedDataFetchStartedEvent = \"squide-protected-data-fetch-started\";\nexport const ProtectedDataFetchFailedEvent = \"squide-protected-data-fetch-failed\";\n\nexport type IsUnauthorizedErrorCallback = (error: unknown) => boolean;\n\n// This converts an array of UseQueryResult to an array of the data type of each query result.\n// For more information, view: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-1.html#mapped-types-on-tuples-and-arrays.\ntype MapUseQueryResultToData<T> = { [K in keyof T]: T[K] extends UseQueryResult<infer U> ? U : never };\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useProtectedDataQueries<T extends Array<any>>(queries: QueriesOptions<T>, isUnauthorizedError: IsUnauthorizedErrorCallback): MapUseQueryResultToData<QueriesResults<T>> {\n const canFetchProtectedData = useCanFetchProtectedData();\n const eventBus = useEventBus();\n\n const dispatch = useAppRouterDispatcher();\n\n const combineResults = useCallback((results: UseQueryResult<unknown, Error>[]) => {\n const errors = results.filter(x => x.error).map(x => x.error) as Error[];\n const hasErrors = errors.length > 0;\n\n return {\n data: results.map(x => x.data) as MapUseQueryResultToData<QueriesResults<T>>,\n errors,\n hasErrors,\n isReady: !hasErrors && !results.some(x => x.isPending)\n };\n }, []);\n\n const { data, errors: queriesErrors, hasErrors, isReady } = useQueries({\n queries: queries.map(x => ({\n enabled: canFetchProtectedData,\n ...x\n })),\n combine: combineResults\n });\n\n const { isProtectedDataReady, isUnauthorized } = useAppRouterState();\n\n useExecuteOnce(useCallback(() => {\n if (canFetchProtectedData) {\n eventBus.dispatch(ProtectedDataFetchStartedEvent);\n\n return true;\n }\n\n return false;\n }, [canFetchProtectedData, eventBus]), true);\n\n // Using a ref seems to be the only way to prevent starting two deferred registrations scope.\n const isReadyRef = useRef(false);\n\n const dispatchReady = useExecuteOnce(useCallback(() => {\n if (isReady) {\n isReadyRef.current = true;\n\n dispatch({ type: \"protected-data-ready\" });\n\n return true;\n }\n\n return false;\n }, [isReady, dispatch]));\n\n useEffect(() => {\n // State update must be executed in useEffect.\n dispatchReady();\n }, [dispatchReady]);\n\n useEffect(() => {\n if (isReadyRef.current && data) {\n dispatch({ type: \"protected-data-updated\" });\n }\n }, [data, dispatch]);\n\n useEffect(() => {\n if (hasErrors) {\n if (!isProtectedDataReady && !isUnauthorized && queriesErrors.some(x => isUnauthorizedError(x))) {\n // Will transition the state to allow the routes to render even if the bootstrapping is not complete, because otherwise\n // a login page for example could not be rendered.\n dispatch({ type: \"is-unauthorized\" });\n }\n\n // Otherwise, when a user is logged off, a refetch might throws a 401.\n if (!queriesErrors.every(x => isUnauthorizedError(x))) {\n eventBus.dispatch(ProtectedDataFetchFailedEvent, queriesErrors);\n\n throw new GlobalDataQueriesError(\"[squide] Global protected data queries failed.\", queriesErrors);\n }\n }\n }, [hasErrors, queriesErrors, isProtectedDataReady, isUnauthorized, isUnauthorizedError, dispatch, eventBus]);\n\n return data;\n}\n"],"names":["useEventBus","useQueries","useCallback","useEffect","useRef","useAppRouterDispatcher","useAppRouterState","GlobalDataQueriesError","useCanFetchProtectedData","useExecuteOnce","ProtectedDataFetchStartedEvent","ProtectedDataFetchFailedEvent","useProtectedDataQueries","queries","isUnauthorizedError","canFetchProtectedData","eventBus","dispatch","combineResults","results","errors","x","hasErrors","data","queriesErrors","isReady","isProtectedDataReady","isUnauthorized","isReadyRef","dispatchReady"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAA2C;AACuE;AAC3D;AAC2B;AACb;AACI;AACpB;AAE9C,MAAMU,iCAAiC,sCAAsC;AAC7E,MAAMC,gCAAgC,qCAAqC;AAQlF,8DAA8D;AACvD,SAASC,wBAA8CC,OAA0B,EAAEC,mBAAgD;IACtI,MAAMC,wBAAwBP,8FAAwBA;IACtD,MAAMQ,WAAWhB,uEAAWA;IAE5B,MAAMiB,WAAWZ,oFAAsBA;IAEvC,MAAMa,iBAAiBhB,iDAAWA,CAAC,CAACiB;QAChC,MAAMC,SAASD,QAAQ,MAAM,CAACE,CAAAA,IAAKA,EAAE,KAAK,EAAE,GAAG,CAACA,CAAAA,IAAKA,EAAE,KAAK;QAC5D,MAAMC,YAAYF,OAAO,MAAM,GAAG;QAElC,OAAO;YACH,MAAMD,QAAQ,GAAG,CAACE,CAAAA,IAAKA,EAAE,IAAI;YAC7BD;YACAE;YACA,SAAS,CAACA,aAAa,CAACH,QAAQ,IAAI,CAACE,CAAAA,IAAKA,EAAE,SAAS;QACzD;IACJ,GAAG,EAAE;IAEL,MAAM,EAAEE,IAAI,EAAE,QAAQC,aAAa,EAAEF,SAAS,EAAEG,OAAO,EAAE,GAAGxB,yEAAUA,CAAC;QACnE,SAASY,QAAQ,GAAG,CAACQ,CAAAA,IAAM;gBACvB,SAASN;gBACT,GAAGM,CAAC;YACR;QACA,SAASH;IACb;IAEA,MAAM,EAAEQ,oBAAoB,EAAEC,cAAc,EAAE,GAAGrB,+EAAiBA;IAElEG,0EAAcA,CAACP,iDAAWA,CAAC;QACvB,IAAIa,uBAAuB;YACvBC,SAAS,QAAQ,CAACN;YAElB,OAAO;QACX;QAEA,OAAO;IACX,GAAG;QAACK;QAAuBC;KAAS,GAAG;IAEvC,6FAA6F;IAC7F,MAAMY,aAAaxB,4CAAMA,CAAC;IAE1B,MAAMyB,gBAAgBpB,0EAAcA,CAACP,iDAAWA,CAAC;QAC7C,IAAIuB,SAAS;YACTG,WAAW,OAAO,GAAG;YAErBX,SAAS;gBAAE,MAAM;YAAuB;YAExC,OAAO;QACX;QAEA,OAAO;IACX,GAAG;QAACQ;QAASR;KAAS;IAEtBd,+CAASA,CAAC;QACN,8CAA8C;QAC9C0B;IACJ,GAAG;QAACA;KAAc;IAElB1B,+CAASA,CAAC;QACN,IAAIyB,WAAW,OAAO,IAAIL,MAAM;YAC5BN,SAAS;gBAAE,MAAM;YAAyB;QAC9C;IACJ,GAAG;QAACM;QAAMN;KAAS;IAEnBd,+CAASA,CAAC;QACN,IAAImB,WAAW;YACX,IAAI,CAACI,wBAAwB,CAACC,kBAAkBH,cAAc,IAAI,CAACH,CAAAA,IAAKP,oBAAoBO,KAAK;gBAC7F,uHAAuH;gBACvH,kDAAkD;gBAClDJ,SAAS;oBAAE,MAAM;gBAAkB;YACvC;YAEA,sEAAsE;YACtE,IAAI,CAACO,cAAc,KAAK,CAACH,CAAAA,IAAKP,oBAAoBO,KAAK;gBACnDL,SAAS,QAAQ,CAACL,+BAA+Ba;gBAEjD,MAAM,IAAIjB,sFAAsBA,CAAC,kDAAkDiB;YACvF;QACJ;IACJ,GAAG;QAACF;QAAWE;QAAeE;QAAsBC;QAAgBb;QAAqBG;QAAUD;KAAS;IAE5G,OAAOO;AACX"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { QueriesOptions, QueriesResults, UseQueryResult } from
|
|
2
|
-
|
|
3
|
-
declare const
|
|
4
|
-
declare const PublicDataFetchFailedEvent = "squide-public-data-fetch-failed";
|
|
1
|
+
import { type QueriesOptions, type QueriesResults, type UseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
export declare const PublicDataFetchStartedEvent = "squide-public-data-fetch-started";
|
|
3
|
+
export declare const PublicDataFetchFailedEvent = "squide-public-data-fetch-failed";
|
|
5
4
|
type MapUseQueryResultToData<T> = {
|
|
6
5
|
[K in keyof T]: T[K] extends UseQueryResult<infer U> ? U : never;
|
|
7
6
|
};
|
|
8
|
-
declare function usePublicDataQueries<T extends Array<any>>(queries: QueriesOptions<T>): MapUseQueryResultToData<QueriesResults<T>>;
|
|
9
|
-
|
|
10
|
-
export { PublicDataFetchFailedEvent, PublicDataFetchStartedEvent, usePublicDataQueries };
|
|
7
|
+
export declare function usePublicDataQueries<T extends Array<any>>(queries: QueriesOptions<T>): MapUseQueryResultToData<QueriesResults<T>>;
|
|
8
|
+
export {};
|
|
@@ -1,5 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__core_src_index_js_d19dd8a6__ from "../../core/src/index.js";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__tanstack_react_query_db705f77__ from "@tanstack/react-query";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__ from "./AppRouterContext.js";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__GlobalDataQueriesError_js_0c24ca62__ from "./GlobalDataQueriesError.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useCanFetchPublicData_js_b8d90132__ from "./useCanFetchPublicData.js";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__ from "./useExecuteOnce.js";
|
|
8
|
+
|
|
9
|
+
;// CONCATENATED MODULE: external "../../core/src/index.js"
|
|
10
|
+
|
|
11
|
+
;// CONCATENATED MODULE: external "@tanstack/react-query"
|
|
12
|
+
|
|
13
|
+
;// CONCATENATED MODULE: external "react"
|
|
14
|
+
|
|
15
|
+
;// CONCATENATED MODULE: external "./AppRouterContext.js"
|
|
16
|
+
|
|
17
|
+
;// CONCATENATED MODULE: external "./GlobalDataQueriesError.js"
|
|
18
|
+
|
|
19
|
+
;// CONCATENATED MODULE: external "./useCanFetchPublicData.js"
|
|
20
|
+
|
|
21
|
+
;// CONCATENATED MODULE: external "./useExecuteOnce.js"
|
|
22
|
+
|
|
23
|
+
;// CONCATENATED MODULE: ./src/usePublicDataQueries.ts?__rslib_entry__
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const PublicDataFetchStartedEvent = "squide-public-data-fetch-started";
|
|
32
|
+
const PublicDataFetchFailedEvent = "squide-public-data-fetch-failed";
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
function usePublicDataQueries(queries) {
|
|
35
|
+
const canFetchPublicData = (0,__WEBPACK_EXTERNAL_MODULE__useCanFetchPublicData_js_b8d90132__.useCanFetchPublicData)();
|
|
36
|
+
const eventBus = (0,__WEBPACK_EXTERNAL_MODULE__core_src_index_js_d19dd8a6__.useEventBus)();
|
|
37
|
+
const dispatch = (0,__WEBPACK_EXTERNAL_MODULE__AppRouterContext_js_3c4a3c33__.useAppRouterDispatcher)();
|
|
38
|
+
const combineResults = (0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)((results)=>{
|
|
39
|
+
const errors = results.filter((x)=>x.error).map((x)=>x.error);
|
|
40
|
+
const hasErrors = errors.length > 0;
|
|
41
|
+
return {
|
|
42
|
+
data: results.map((x)=>x.data),
|
|
43
|
+
errors,
|
|
44
|
+
hasErrors,
|
|
45
|
+
isReady: !hasErrors && !results.some((x)=>x.isPending)
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
const { data, errors: queriesErrors, hasErrors, isReady } = (0,__WEBPACK_EXTERNAL_MODULE__tanstack_react_query_db705f77__.useQueries)({
|
|
49
|
+
queries: queries.map((x)=>({
|
|
50
|
+
enabled: canFetchPublicData,
|
|
51
|
+
...x
|
|
52
|
+
})),
|
|
53
|
+
combine: combineResults
|
|
54
|
+
});
|
|
55
|
+
(0,__WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__.useExecuteOnce)((0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
56
|
+
if (canFetchPublicData) {
|
|
57
|
+
eventBus.dispatch(PublicDataFetchStartedEvent);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}, [
|
|
62
|
+
canFetchPublicData,
|
|
63
|
+
eventBus
|
|
64
|
+
]), true);
|
|
65
|
+
// Using a ref seems to be the only way to prevent starting two deferred registrations scope.
|
|
66
|
+
const isReadyRef = (0,__WEBPACK_EXTERNAL_MODULE_react__.useRef)(false);
|
|
67
|
+
const dispatchReady = (0,__WEBPACK_EXTERNAL_MODULE__useExecuteOnce_js_e1f8f91b__.useExecuteOnce)((0,__WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
68
|
+
if (isReady) {
|
|
69
|
+
isReadyRef.current = true;
|
|
70
|
+
dispatch({
|
|
71
|
+
type: "public-data-ready"
|
|
72
|
+
});
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}, [
|
|
77
|
+
isReady,
|
|
78
|
+
dispatch
|
|
79
|
+
]));
|
|
80
|
+
(0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
81
|
+
// State update must be executed in useEffect.
|
|
82
|
+
dispatchReady();
|
|
83
|
+
}, [
|
|
84
|
+
dispatchReady
|
|
85
|
+
]);
|
|
86
|
+
(0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
87
|
+
if (isReadyRef.current && data) {
|
|
88
|
+
dispatch({
|
|
89
|
+
type: "public-data-updated"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}, [
|
|
93
|
+
data,
|
|
94
|
+
dispatch
|
|
95
|
+
]);
|
|
96
|
+
(0,__WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
97
|
+
if (hasErrors) {
|
|
98
|
+
eventBus.dispatch(PublicDataFetchFailedEvent, queriesErrors);
|
|
99
|
+
throw new __WEBPACK_EXTERNAL_MODULE__GlobalDataQueriesError_js_0c24ca62__.GlobalDataQueriesError("[squide] Global public data queries failed.", queriesErrors);
|
|
100
|
+
}
|
|
101
|
+
}, [
|
|
102
|
+
hasErrors,
|
|
103
|
+
queriesErrors,
|
|
104
|
+
eventBus
|
|
105
|
+
]);
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { PublicDataFetchFailedEvent, PublicDataFetchStartedEvent, usePublicDataQueries };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=usePublicDataQueries.js.map
|