|
@@ -0,0 +1,101 @@
|
|
|
+import { ComponentType } from 'react';
|
|
|
+import { GetUserRolesFunc } from '../router';
|
|
|
+import { Pub } from '../pub';
|
|
|
+
|
|
|
+type QueryRoute = {
|
|
|
+ path? : string,
|
|
|
+ args: any[]|Function,
|
|
|
+ component? : ComponentType,
|
|
|
+
|
|
|
+ /*
|
|
|
+ //TODO; options override in query on createQuery level
|
|
|
+ //it aren't works for now
|
|
|
+ query: QueryFuncType,
|
|
|
+ cacheTimeout?: number,
|
|
|
+ hidePendingOnRefresh?: boolean
|
|
|
+ avoidRepeatInProgress?: boolean,
|
|
|
+ forceRefreshAfterTimeout?: boolean,
|
|
|
+ */
|
|
|
+
|
|
|
+ //pending, error and prop names configuration override on route level
|
|
|
+ Pending?: ComponentType,
|
|
|
+ Error?: ComponentType,
|
|
|
+
|
|
|
+ errorQueryComponentErrorProp?: string,
|
|
|
+ componentQueryResultProp? : string,
|
|
|
+}
|
|
|
+
|
|
|
+type QueryRoutes = {
|
|
|
+ [name: string]: QueryRoute
|
|
|
+}
|
|
|
+
|
|
|
+type CreateQueryRoutesOptions = {
|
|
|
+ //global query configuration, basic query function are mandatory
|
|
|
+ query: QueryFuncType,
|
|
|
+ cacheTimeout?: number,
|
|
|
+ hidePendingOnRefresh?: boolean
|
|
|
+ avoidRepeatInProgress?: boolean,
|
|
|
+ forceRefreshAfterTimeout?: boolean,
|
|
|
+
|
|
|
+ //global route configuration, pending, error and prop names configuration
|
|
|
+ Pending?: ComponentType,
|
|
|
+ Error?: ComponentType,
|
|
|
+ errorQueryComponentErrorProp?: string,
|
|
|
+ componentQueryResultProp? : string,
|
|
|
+
|
|
|
+ //global private routing configuration
|
|
|
+ getUserRoles: GetUserRolesFunc, //function to get roles of current user
|
|
|
+ fallback: string|Function //function/string to be redirected to in case of lack of permission
|
|
|
+ routeRoles: string[] //default roles (like ['anon']
|
|
|
+
|
|
|
+ queryRoutes: QueryRoutes
|
|
|
+}
|
|
|
+
|
|
|
+type QueryRoutesResult = {
|
|
|
+ //results about routing:
|
|
|
+
|
|
|
+ //NamedRoute decorated
|
|
|
+ Route: ComponentType,
|
|
|
+ //Same value as for Route, but named. For example, if name "category" it will be CategoryRoute
|
|
|
+ [name: string]: ComponentType,
|
|
|
+ //NamedLink to exactly this route
|
|
|
+ Link: ComponentType,
|
|
|
+ //Same value as for Link, but named. Like CategoryLink
|
|
|
+ [name: string]: ComponentType,
|
|
|
+
|
|
|
+
|
|
|
+ //results about queries
|
|
|
+ makeQuery: Function,
|
|
|
+ query: Function,
|
|
|
+ forceQuery: Function,
|
|
|
+ Hook: ComponentType,
|
|
|
+
|
|
|
+ //named hook useNameQuery
|
|
|
+ [name: string]: ComponentType,
|
|
|
+}
|
|
|
+
|
|
|
+type QueryRoutesResults = {
|
|
|
+ [name: string]: QueryRoutesResult
|
|
|
+}
|
|
|
+
|
|
|
+type CreateQueryRoutesResult = {
|
|
|
+ //Global results:
|
|
|
+ //routing:
|
|
|
+ NamedRoute: ComponentType,
|
|
|
+ PrivateRoute: ComponentType,
|
|
|
+ NamedLink ; ComponentType, //just copy of NamedLink, nothing special
|
|
|
+ //Component renders all routes in one place. Shortcut, but isn't flexible if you want routes
|
|
|
+ //in different places of page layout
|
|
|
+ AllRoutes: ComponentType,
|
|
|
+
|
|
|
+ //queryPub
|
|
|
+ queryPub: Pub,
|
|
|
+ withQueryFunc: Function, //type it
|
|
|
+ createQuery: Function, //type it
|
|
|
+
|
|
|
+ queryRoutes: QueryRoutesResults
|
|
|
+}
|
|
|
+
|
|
|
+export const createQueryRoutes = (options) => {
|
|
|
+
|
|
|
+}
|