@tiny-server/core 0.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/dist/api/apiResults.d.ts +48 -0
- package/dist/api/entity.d.ts +27 -0
- package/dist/api/index.d.ts +8 -0
- package/dist/api/paginationOptions.d.ts +13 -0
- package/dist/api/permissions.d.ts +55 -0
- package/dist/api/problemDetails.d.ts +16 -0
- package/dist/api/session.d.ts +38 -0
- package/dist/api/sortOptions.d.ts +17 -0
- package/dist/api/status.d.ts +27 -0
- package/dist/app/App.d.ts +12 -0
- package/dist/app/context.d.ts +6 -0
- package/dist/app/create.d.ts +12 -0
- package/dist/app/features/extensions/Extension.d.ts +32 -0
- package/dist/app/features/extensions/index.d.ts +2 -0
- package/dist/app/features/extensions/types.d.ts +43 -0
- package/dist/app/features/index.d.ts +6 -0
- package/dist/app/features/layout/Error.d.ts +15 -0
- package/dist/app/features/layout/Layout.d.ts +4 -0
- package/dist/app/features/layout/Loading.d.ts +14 -0
- package/dist/app/features/layout/Page.d.ts +6 -0
- package/dist/app/features/layout/index.d.ts +6 -0
- package/dist/app/features/layout/initializer.d.ts +2 -0
- package/dist/app/features/layout/types.d.ts +13 -0
- package/dist/app/features/menu/Menu.d.ts +7 -0
- package/dist/app/features/menu/MenuContainer.d.ts +4 -0
- package/dist/app/features/menu/MenuItem.d.ts +11 -0
- package/dist/app/features/menu/index.d.ts +5 -0
- package/dist/app/features/menu/initializer.d.ts +2 -0
- package/dist/app/features/menu/types.d.ts +71 -0
- package/dist/app/features/modals/Modal.d.ts +5 -0
- package/dist/app/features/modals/ModalBody.d.ts +4 -0
- package/dist/app/features/modals/ModalContent.d.ts +7 -0
- package/dist/app/features/modals/ModalFooter.d.ts +5 -0
- package/dist/app/features/modals/ModalHeader.d.ts +5 -0
- package/dist/app/features/modals/Modals.d.ts +4 -0
- package/dist/app/features/modals/index.d.ts +8 -0
- package/dist/app/features/modals/initializer.d.ts +2 -0
- package/dist/app/features/modals/store.d.ts +14 -0
- package/dist/app/features/modals/types.d.ts +84 -0
- package/dist/app/features/query/AppQueryClientProvider.d.ts +2 -0
- package/dist/app/features/query/client.d.ts +2 -0
- package/dist/app/features/query/index.d.ts +3 -0
- package/dist/app/features/query/initializer.d.ts +2 -0
- package/dist/app/features/query/types.d.ts +9 -0
- package/dist/app/features/router/AppLayout.d.ts +1 -0
- package/dist/app/features/router/AppRouteLayout.d.ts +5 -0
- package/dist/app/features/router/AppRouter.d.ts +4 -0
- package/dist/app/features/router/RouterErrorBoundary.d.ts +1 -0
- package/dist/app/features/router/context.d.ts +5 -0
- package/dist/app/features/router/index.d.ts +3 -0
- package/dist/app/features/router/middlewares.d.ts +42 -0
- package/dist/app/index.d.ts +5 -0
- package/dist/app/types.d.ts +78 -0
- package/dist/components/ErrorBoundary.d.ts +19 -0
- package/dist/components/WithPermissions.d.ts +30 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/fetch.d.ts +84 -0
- package/dist/i18n/InitI18n.d.ts +6 -0
- package/dist/i18n/defineLocales.d.ts +10 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/useGlobalT.d.ts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +557 -0
- package/dist/module.d.ts +7 -0
- package/dist/utils/dates.d.ts +3 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/usePagination.d.ts +31 -0
- package/dist/utils/useSearch.d.ts +19 -0
- package/dist/utils/useSession.d.ts +22 -0
- package/package.json +52 -0
- package/src/api/apiResults.ts +50 -0
- package/src/api/entity.ts +29 -0
- package/src/api/index.ts +8 -0
- package/src/api/paginationOptions.ts +13 -0
- package/src/api/permissions.ts +63 -0
- package/src/api/problemDetails.ts +19 -0
- package/src/api/session.ts +51 -0
- package/src/api/sortOptions.ts +18 -0
- package/src/api/status.ts +34 -0
- package/src/app/App.tsx +33 -0
- package/src/app/context.ts +17 -0
- package/src/app/create.ts +34 -0
- package/src/app/features/extensions/Extension.tsx +69 -0
- package/src/app/features/extensions/index.ts +2 -0
- package/src/app/features/extensions/types.tsx +52 -0
- package/src/app/features/index.ts +6 -0
- package/src/app/features/layout/Error.tsx +20 -0
- package/src/app/features/layout/Layout.tsx +7 -0
- package/src/app/features/layout/Loading.tsx +21 -0
- package/src/app/features/layout/Page.tsx +42 -0
- package/src/app/features/layout/index.ts +6 -0
- package/src/app/features/layout/initializer.ts +12 -0
- package/src/app/features/layout/types.ts +14 -0
- package/src/app/features/menu/Menu.tsx +66 -0
- package/src/app/features/menu/MenuContainer.tsx +9 -0
- package/src/app/features/menu/MenuItem.tsx +46 -0
- package/src/app/features/menu/index.ts +5 -0
- package/src/app/features/menu/initializer.ts +8 -0
- package/src/app/features/menu/types.ts +84 -0
- package/src/app/features/modals/Modal.tsx +20 -0
- package/src/app/features/modals/ModalBody.tsx +8 -0
- package/src/app/features/modals/ModalContent.tsx +35 -0
- package/src/app/features/modals/ModalFooter.tsx +19 -0
- package/src/app/features/modals/ModalHeader.tsx +15 -0
- package/src/app/features/modals/Modals.tsx +33 -0
- package/src/app/features/modals/index.ts +8 -0
- package/src/app/features/modals/initializer.ts +17 -0
- package/src/app/features/modals/store.ts +35 -0
- package/src/app/features/modals/types.ts +94 -0
- package/src/app/features/query/AppQueryClientProvider.tsx +7 -0
- package/src/app/features/query/client.ts +3 -0
- package/src/app/features/query/index.ts +3 -0
- package/src/app/features/query/initializer.ts +6 -0
- package/src/app/features/query/types.ts +10 -0
- package/src/app/features/router/AppLayout.tsx +18 -0
- package/src/app/features/router/AppRouteLayout.tsx +31 -0
- package/src/app/features/router/AppRouter.tsx +45 -0
- package/src/app/features/router/RouterErrorBoundary.tsx +20 -0
- package/src/app/features/router/context.ts +7 -0
- package/src/app/features/router/index.ts +3 -0
- package/src/app/features/router/middlewares.ts +76 -0
- package/src/app/index.ts +6 -0
- package/src/app/types.ts +82 -0
- package/src/components/ErrorBoundary.tsx +34 -0
- package/src/components/WithPermissions.tsx +59 -0
- package/src/components/index.ts +2 -0
- package/src/fetch.ts +185 -0
- package/src/i18n/InitI18n.tsx +24 -0
- package/src/i18n/defineLocales.ts +59 -0
- package/src/i18n/index.ts +3 -0
- package/src/i18n/useGlobalT.ts +13 -0
- package/src/index.ts +8 -0
- package/src/module.tsx +27 -0
- package/src/utils/dates.ts +34 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/usePagination.ts +64 -0
- package/src/utils/useSearch.ts +40 -0
- package/src/utils/useSession.ts +42 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useSearchParams } from 'react-router';
|
|
3
|
+
|
|
4
|
+
export interface UsePaginationOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The default name of the page query parameter in the URL.
|
|
7
|
+
* @default 'page'
|
|
8
|
+
*/
|
|
9
|
+
pageParamName?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The default name of the page size query parameter in the URL.
|
|
12
|
+
* @default 'pageSize'
|
|
13
|
+
*/
|
|
14
|
+
pageSizeParamName?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The default page value to be used as a fallback for missing values.
|
|
17
|
+
* @default 1
|
|
18
|
+
*/
|
|
19
|
+
defaultPage?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The default page size value to be used as a fallback for missing values.
|
|
22
|
+
* @default 20
|
|
23
|
+
*/
|
|
24
|
+
defaultPageSize?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Manages pagination query parameters for handling page and page size values in the URL.
|
|
29
|
+
*/
|
|
30
|
+
export function usePagination({
|
|
31
|
+
pageParamName = 'page',
|
|
32
|
+
pageSizeParamName = 'pageSize',
|
|
33
|
+
defaultPage = 1,
|
|
34
|
+
defaultPageSize = 20,
|
|
35
|
+
}: UsePaginationOptions = {}) {
|
|
36
|
+
const [params, setParams] = useSearchParams();
|
|
37
|
+
|
|
38
|
+
const parsedPage = +(params.get(pageParamName) || defaultPage);
|
|
39
|
+
const parsedPageSize = +(params.get(pageSizeParamName) || defaultPageSize);
|
|
40
|
+
const page = isNaN(parsedPage) ? defaultPage : parsedPage;
|
|
41
|
+
const pageSize = isNaN(parsedPageSize) ? defaultPageSize : parsedPageSize;
|
|
42
|
+
|
|
43
|
+
const setPage = useCallback(
|
|
44
|
+
(newPage: number) => {
|
|
45
|
+
setParams((params) => {
|
|
46
|
+
params.set(pageParamName, newPage.toString());
|
|
47
|
+
return params;
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
[pageParamName, setParams],
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const setPageSize = useCallback(
|
|
54
|
+
(newPageSize: number) => {
|
|
55
|
+
setParams((params) => {
|
|
56
|
+
params.set(pageSizeParamName, newPageSize.toString());
|
|
57
|
+
return params;
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
[pageSizeParamName, setParams],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
return { page, pageSize, setPage, setPageSize };
|
|
64
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useSearchParams } from 'react-router';
|
|
3
|
+
|
|
4
|
+
export interface UseSearchOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The default name of the search query parameter in the URL.
|
|
7
|
+
* @default 'search'
|
|
8
|
+
*/
|
|
9
|
+
searchParamName?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The default search value to be used as a fallback for missing values.
|
|
12
|
+
* @default ''
|
|
13
|
+
*/
|
|
14
|
+
defaultSearch?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Manages a "search" query parameter used for filtering and searching page content.
|
|
19
|
+
*/
|
|
20
|
+
export function useSearch({ searchParamName = 'search', defaultSearch = '' }: UseSearchOptions = {}) {
|
|
21
|
+
const [params, setParams] = useSearchParams();
|
|
22
|
+
|
|
23
|
+
const search = params.get(searchParamName) || defaultSearch;
|
|
24
|
+
|
|
25
|
+
const setSearch = useCallback(
|
|
26
|
+
(newSearch: string) => {
|
|
27
|
+
setParams((params) => {
|
|
28
|
+
if (newSearch && newSearch !== defaultSearch) {
|
|
29
|
+
params.set(searchParamName, newSearch);
|
|
30
|
+
} else {
|
|
31
|
+
params.delete(searchParamName);
|
|
32
|
+
}
|
|
33
|
+
return params;
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
[defaultSearch, searchParamName, setParams],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return { search, setSearch };
|
|
40
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
2
|
+
import { readSessionStateQuery, type Permission, type SessionRead, type SessionState } from '../api';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the app's current {@link SessionState}.
|
|
6
|
+
* This is a convenience hook which returns the data of the current {@link readSessionStateQuery}.
|
|
7
|
+
*/
|
|
8
|
+
export function useSessionState(): SessionState {
|
|
9
|
+
const { data } = useSuspenseQuery(readSessionStateQuery());
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the app's active {@link SessionRead} session data.
|
|
15
|
+
*
|
|
16
|
+
* **⚠️ Important**:
|
|
17
|
+
* This hook should only be used in components which are guaranteed to be rendered in an active session context.
|
|
18
|
+
* If no active session exists, this hook will throw an error.
|
|
19
|
+
*/
|
|
20
|
+
export function useSession(): SessionRead {
|
|
21
|
+
const sessionState = useSessionState();
|
|
22
|
+
|
|
23
|
+
if (!sessionState.hasSession) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
'useSession was called, but no active user session exists. ' +
|
|
26
|
+
'This hook should only be called in components which are guaranteed to be rendered in an active session context.',
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return sessionState.session;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns the app's active session's permissions.
|
|
35
|
+
*
|
|
36
|
+
* **⚠️ Important**:
|
|
37
|
+
* This hook should only be used in components which are guaranteed to be rendered in an active session context.
|
|
38
|
+
* If no active session exists, this hook will throw an error.
|
|
39
|
+
*/
|
|
40
|
+
export function usePermissions(): Array<Permission> {
|
|
41
|
+
return useSession().permissions;
|
|
42
|
+
}
|