rastack 0.0.16 → 0.0.19
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 +43874 -43013
- package/dist/.prettierrc +7 -7
- package/dist/compile/analyze.js +19 -11
- package/dist/compile/index.js +26 -17
- package/dist/compile/manifest.js +2 -3
- package/dist/compile/openapi.js +5 -8
- package/dist/compile/program.js +19 -10
- package/dist/csv-schema.js +5 -6
- package/dist/define/index.js +2 -2
- package/dist/entity-generation/delete-method.js +8 -10
- package/dist/entity-generation/form.js +80 -82
- package/dist/entity-generation/get-method.js +35 -36
- package/dist/entity-generation/imports.js +24 -20
- package/dist/entity-generation/sync-method.d.ts +1 -1
- package/dist/entity-generation/sync-method.js +45 -46
- package/dist/entity-generation/update-method.js +9 -10
- package/dist/rad-wasm-build.d.ts +1 -1
- package/dist/rad-wasm-build.js +15 -6
- package/dist/rad.js +9 -2
- package/dist/schema/camel-to-pastel.js +1 -2
- package/dist/schema/capitalise-first-letter.js +1 -2
- package/dist/schema/extract-response.js +3 -4
- package/dist/schema/fetch-schema.js +4 -16
- package/dist/schema/remove-non-model-paths.js +1 -2
- package/dist/schema/to-camel-case.js +1 -2
- package/dist/schema/to-pastel-case.js +1 -2
- package/dist/schema-convert.js +22 -33
- package/dist/schema-entities.js +177 -189
- package/dist/schema-fetch.js +46 -63
- package/dist/schema-full.js +23 -36
- package/dist/schema-index.js +16 -27
- package/dist/schema-params.js +11 -22
- package/dist/seed.js +95 -97
- package/hooks/form/form.ts +207 -207
- package/hooks/form/index.ts +8 -8
- package/hooks/form/interfaces.ts +217 -217
- package/hooks/form/structure.ts +39 -39
- package/hooks/form/validate-schema.ts +49 -49
- package/hooks/index.ts +3 -3
- package/hooks/query/api.ts +42 -42
- package/hooks/query/delete.ts +45 -45
- package/hooks/query/fetch.ts +48 -48
- package/hooks/query/index.ts +21 -21
- package/hooks/query/interfaces.ts +111 -111
- package/hooks/query/list.ts +286 -286
- package/hooks/query/update.ts +88 -88
- package/hooks/query/url.ts +31 -31
- package/hooks/real-time/index.ts +1 -1
- package/hooks/real-time/pusher.ts +43 -43
- package/jest.config.cjs +6 -6
- package/package.json +57 -57
- package/provider/index.ts +13 -13
- package/provider/provider.tsx +187 -187
- package/provider/types.ts +114 -114
- package/provider/warehouse.ts +167 -167
- package/provider/wasm.ts +124 -124
- package/runtime.ts +3 -3
- package/src/.prettierrc +7 -7
- package/src/compile/analyze.ts +224 -224
- package/src/compile/index.ts +86 -86
- package/src/compile/manifest.ts +10 -10
- package/src/compile/model.ts +69 -69
- package/src/compile/openapi.ts +266 -266
- package/src/compile/program.ts +40 -40
- package/src/csv-schema.ts +187 -187
- package/src/define/index.ts +162 -162
- package/src/entity-generation/delete-method.ts +37 -37
- package/src/entity-generation/form.ts +169 -169
- package/src/entity-generation/get-method.ts +80 -80
- package/src/entity-generation/imports.ts +110 -110
- package/src/entity-generation/sync-method.ts +222 -222
- package/src/entity-generation/update-method.ts +38 -38
- package/src/index.ts +77 -77
- package/src/rad-compile.ts +88 -88
- package/src/rad-wasm-build.ts +102 -102
- package/src/rad.ts +101 -101
- package/src/scan.ts +89 -89
- package/src/schema/camel-to-pastel.ts +3 -3
- package/src/schema/capitalise-first-letter.ts +3 -3
- package/src/schema/extract-response.ts +38 -38
- package/src/schema/fetch-schema.ts +12 -12
- package/src/schema/remove-non-model-paths.ts +13 -13
- package/src/schema/to-camel-case.ts +7 -7
- package/src/schema/to-pastel-case.ts +6 -6
- package/src/schema-convert.ts +61 -61
- package/src/schema-entities.ts +401 -401
- package/src/schema-fetch.ts +82 -82
- package/src/schema-full.ts +38 -38
- package/src/schema-index.ts +29 -29
- package/src/schema-params.ts +116 -116
- package/src/seed.ts +297 -297
- package/sync/engine.ts +392 -392
- package/sync/hooks.ts +450 -450
- package/sync/index.ts +8 -8
- package/sync/persistence.ts +237 -237
- package/sync/provider.tsx +91 -91
- package/sync/registry.ts +36 -36
- package/sync/store.ts +126 -126
- package/sync/transactions.ts +300 -300
- package/sync/types.ts +94 -94
- package/test/compile.spec.ts +192 -192
- package/test/csv-schema.spec.ts +143 -143
- package/test/schema-entities.spec.ts +688 -688
- package/tsconfig.json +24 -24
- package/types.ts +18 -18
package/hooks/query/api.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import axios, { AxiosAdapter, AxiosInstance } from "axios";
|
|
2
|
-
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
const defaultBaseURL = process.env.NEXT_PUBLIC_BASE_URL || "http://127.0.0.1:8000";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The shared axios client every generated hook talks through. It is a stable
|
|
8
|
-
* singleton — imported directly all over the codegen — so `<RAStackProvider>`
|
|
9
|
-
* reconfigures it *in place* (base URL for `remote` mode, or a WASM adapter for
|
|
10
|
-
* `local`/`s3` mode) rather than swapping the instance. That is what lets the
|
|
11
|
-
* same hooks hit a Lambda over HTTP or an in-browser WASM engine with no
|
|
12
|
-
* codegen changes.
|
|
13
|
-
*/
|
|
14
|
-
export const API: AxiosInstance = axios.create({
|
|
15
|
-
baseURL: defaultBaseURL,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export interface ApiConfig {
|
|
19
|
-
/** Base URL for HTTP (`remote`) mode. */
|
|
20
|
-
baseURL?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Axios adapter override. Pass the WASM adapter to route requests into the
|
|
23
|
-
* in-browser engine; pass `null` to restore axios's default HTTP transport.
|
|
24
|
-
*/
|
|
25
|
-
adapter?: AxiosAdapter | null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Reconfigure the shared client. Called by `<RAStackProvider>` on mode changes. */
|
|
29
|
-
export function configureApi(config: ApiConfig): void {
|
|
30
|
-
if (config.baseURL !== undefined) {
|
|
31
|
-
API.defaults.baseURL = config.baseURL;
|
|
32
|
-
}
|
|
33
|
-
if ("adapter" in config) {
|
|
34
|
-
API.defaults.adapter = config.adapter ?? undefined;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Restore the client to its default HTTP transport and base URL. */
|
|
39
|
-
export function resetApi(): void {
|
|
40
|
-
API.defaults.baseURL = defaultBaseURL;
|
|
41
|
-
API.defaults.adapter = undefined;
|
|
42
|
-
}
|
|
1
|
+
import axios, { AxiosAdapter, AxiosInstance } from "axios";
|
|
2
|
+
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
const defaultBaseURL = process.env.NEXT_PUBLIC_BASE_URL || "http://127.0.0.1:8000";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The shared axios client every generated hook talks through. It is a stable
|
|
8
|
+
* singleton — imported directly all over the codegen — so `<RAStackProvider>`
|
|
9
|
+
* reconfigures it *in place* (base URL for `remote` mode, or a WASM adapter for
|
|
10
|
+
* `local`/`s3` mode) rather than swapping the instance. That is what lets the
|
|
11
|
+
* same hooks hit a Lambda over HTTP or an in-browser WASM engine with no
|
|
12
|
+
* codegen changes.
|
|
13
|
+
*/
|
|
14
|
+
export const API: AxiosInstance = axios.create({
|
|
15
|
+
baseURL: defaultBaseURL,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export interface ApiConfig {
|
|
19
|
+
/** Base URL for HTTP (`remote`) mode. */
|
|
20
|
+
baseURL?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Axios adapter override. Pass the WASM adapter to route requests into the
|
|
23
|
+
* in-browser engine; pass `null` to restore axios's default HTTP transport.
|
|
24
|
+
*/
|
|
25
|
+
adapter?: AxiosAdapter | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Reconfigure the shared client. Called by `<RAStackProvider>` on mode changes. */
|
|
29
|
+
export function configureApi(config: ApiConfig): void {
|
|
30
|
+
if (config.baseURL !== undefined) {
|
|
31
|
+
API.defaults.baseURL = config.baseURL;
|
|
32
|
+
}
|
|
33
|
+
if ("adapter" in config) {
|
|
34
|
+
API.defaults.adapter = config.adapter ?? undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Restore the client to its default HTTP transport and base URL. */
|
|
39
|
+
export function resetApi(): void {
|
|
40
|
+
API.defaults.baseURL = defaultBaseURL;
|
|
41
|
+
API.defaults.adapter = undefined;
|
|
42
|
+
}
|
package/hooks/query/delete.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { AxiosResponse } from "axios";
|
|
2
|
-
import { UseMutationResult } from "react-query/types/react/types";
|
|
3
|
-
import { useMutation, useQueryClient } from "react-query";
|
|
4
|
-
import { IDeleteQueryResult } from "./interfaces";
|
|
5
|
-
import { API } from "./api";
|
|
6
|
-
|
|
7
|
-
interface DeleteQueryProps {
|
|
8
|
-
deleteUrl?: ((id: string) => string) | string;
|
|
9
|
-
listQueryCacheKey?: string | undefined;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function useDeleteQuery<TResult>({
|
|
13
|
-
deleteUrl,
|
|
14
|
-
listQueryCacheKey,
|
|
15
|
-
}: DeleteQueryProps): IDeleteQueryResult<TResult> {
|
|
16
|
-
const queryClient = useQueryClient();
|
|
17
|
-
|
|
18
|
-
return useMutation(
|
|
19
|
-
async (params: { id?: string }) => {
|
|
20
|
-
if (params.id === undefined) {
|
|
21
|
-
throw new Error("ID is required for delete operation");
|
|
22
|
-
}
|
|
23
|
-
let url: string = "";
|
|
24
|
-
if (typeof deleteUrl === "function") {
|
|
25
|
-
if (params.id) {
|
|
26
|
-
url = deleteUrl(params.id);
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
if (deleteUrl) {
|
|
30
|
-
url = deleteUrl;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const response: AxiosResponse = await API.delete(url);
|
|
35
|
-
return response.data.results;
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
onSuccess: () => {
|
|
39
|
-
if (listQueryCacheKey) {
|
|
40
|
-
queryClient.invalidateQueries(listQueryCacheKey);
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
) as UseMutationResult<TResult>;
|
|
45
|
-
}
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { UseMutationResult } from "react-query/types/react/types";
|
|
3
|
+
import { useMutation, useQueryClient } from "react-query";
|
|
4
|
+
import { IDeleteQueryResult } from "./interfaces";
|
|
5
|
+
import { API } from "./api";
|
|
6
|
+
|
|
7
|
+
interface DeleteQueryProps {
|
|
8
|
+
deleteUrl?: ((id: string) => string) | string;
|
|
9
|
+
listQueryCacheKey?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useDeleteQuery<TResult>({
|
|
13
|
+
deleteUrl,
|
|
14
|
+
listQueryCacheKey,
|
|
15
|
+
}: DeleteQueryProps): IDeleteQueryResult<TResult> {
|
|
16
|
+
const queryClient = useQueryClient();
|
|
17
|
+
|
|
18
|
+
return useMutation(
|
|
19
|
+
async (params: { id?: string }) => {
|
|
20
|
+
if (params.id === undefined) {
|
|
21
|
+
throw new Error("ID is required for delete operation");
|
|
22
|
+
}
|
|
23
|
+
let url: string = "";
|
|
24
|
+
if (typeof deleteUrl === "function") {
|
|
25
|
+
if (params.id) {
|
|
26
|
+
url = deleteUrl(params.id);
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
if (deleteUrl) {
|
|
30
|
+
url = deleteUrl;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const response: AxiosResponse = await API.delete(url);
|
|
35
|
+
return response.data.results;
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
onSuccess: () => {
|
|
39
|
+
if (listQueryCacheKey) {
|
|
40
|
+
queryClient.invalidateQueries(listQueryCacheKey);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
) as UseMutationResult<TResult>;
|
|
45
|
+
}
|
package/hooks/query/fetch.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { AxiosResponse } from "axios";
|
|
2
|
-
import { useQuery } from "react-query";
|
|
3
|
-
import { API } from "./api";
|
|
4
|
-
import { stringifyQueryParams } from "./url";
|
|
5
|
-
import { GetQueryOptions, IGetQueryResult } from "./interfaces";
|
|
6
|
-
|
|
7
|
-
export interface GetQueryProps<TParam> {
|
|
8
|
-
getUrl: string;
|
|
9
|
-
queryKey: string;
|
|
10
|
-
pathParameters: (keyof TParam)[];
|
|
11
|
-
requiredParams: (keyof TParam)[];
|
|
12
|
-
isAuthenticated: boolean;
|
|
13
|
-
options?: GetQueryOptions<TParam>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function useGetQuery<TParam, TResult>({
|
|
17
|
-
getUrl,
|
|
18
|
-
queryKey,
|
|
19
|
-
pathParameters,
|
|
20
|
-
requiredParams,
|
|
21
|
-
isAuthenticated,
|
|
22
|
-
options,
|
|
23
|
-
}: GetQueryProps<TParam>): IGetQueryResult<TResult> {
|
|
24
|
-
const isRequiredParamsPresent = requiredParams?.every((param) => {
|
|
25
|
-
if (!options?.params) {
|
|
26
|
-
return false;
|
|
27
|
-
} else {
|
|
28
|
-
return options?.params[param as keyof TParam] !== undefined;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const params = options?.params;
|
|
33
|
-
|
|
34
|
-
return useQuery(
|
|
35
|
-
[queryKey, getUrl, params],
|
|
36
|
-
async () => {
|
|
37
|
-
const urlParams = stringifyQueryParams(pathParameters, params);
|
|
38
|
-
const serverURL = `${getUrl}${urlParams ? `?${urlParams}` : ""}`;
|
|
39
|
-
|
|
40
|
-
const response: AxiosResponse<TResult> = await API.get(serverURL);
|
|
41
|
-
|
|
42
|
-
return response.data;
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
enabled: isAuthenticated && isRequiredParamsPresent,
|
|
46
|
-
},
|
|
47
|
-
);
|
|
48
|
-
}
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { useQuery } from "react-query";
|
|
3
|
+
import { API } from "./api";
|
|
4
|
+
import { stringifyQueryParams } from "./url";
|
|
5
|
+
import { GetQueryOptions, IGetQueryResult } from "./interfaces";
|
|
6
|
+
|
|
7
|
+
export interface GetQueryProps<TParam> {
|
|
8
|
+
getUrl: string;
|
|
9
|
+
queryKey: string;
|
|
10
|
+
pathParameters: (keyof TParam)[];
|
|
11
|
+
requiredParams: (keyof TParam)[];
|
|
12
|
+
isAuthenticated: boolean;
|
|
13
|
+
options?: GetQueryOptions<TParam>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useGetQuery<TParam, TResult>({
|
|
17
|
+
getUrl,
|
|
18
|
+
queryKey,
|
|
19
|
+
pathParameters,
|
|
20
|
+
requiredParams,
|
|
21
|
+
isAuthenticated,
|
|
22
|
+
options,
|
|
23
|
+
}: GetQueryProps<TParam>): IGetQueryResult<TResult> {
|
|
24
|
+
const isRequiredParamsPresent = requiredParams?.every((param) => {
|
|
25
|
+
if (!options?.params) {
|
|
26
|
+
return false;
|
|
27
|
+
} else {
|
|
28
|
+
return options?.params[param as keyof TParam] !== undefined;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const params = options?.params;
|
|
33
|
+
|
|
34
|
+
return useQuery(
|
|
35
|
+
[queryKey, getUrl, params],
|
|
36
|
+
async () => {
|
|
37
|
+
const urlParams = stringifyQueryParams(pathParameters, params);
|
|
38
|
+
const serverURL = `${getUrl}${urlParams ? `?${urlParams}` : ""}`;
|
|
39
|
+
|
|
40
|
+
const response: AxiosResponse<TResult> = await API.get(serverURL);
|
|
41
|
+
|
|
42
|
+
return response.data;
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
enabled: isAuthenticated && isRequiredParamsPresent,
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
}
|
package/hooks/query/index.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export { useGetQuery } from "./fetch";
|
|
2
|
-
export type {
|
|
3
|
-
IGetQueryResult,
|
|
4
|
-
IUpdateQueryResult,
|
|
5
|
-
IDeleteQueryResult,
|
|
6
|
-
IListQuery,
|
|
7
|
-
ListQueryOptions,
|
|
8
|
-
GetQueryOptions,
|
|
9
|
-
} from "./interfaces";
|
|
10
|
-
export { useGetPaginatedQueryList } from "./list";
|
|
11
|
-
export { useUpdateQuery } from "./update";
|
|
12
|
-
export { useDeleteQuery } from "./delete";
|
|
13
|
-
export type {
|
|
14
|
-
IPaginationActions,
|
|
15
|
-
ISearchingActions,
|
|
16
|
-
IFilterActions,
|
|
17
|
-
ISortingActions,
|
|
18
|
-
ReturnedHeader,
|
|
19
|
-
} from "./interfaces";
|
|
20
|
-
export { API, configureApi, resetApi } from "./api";
|
|
21
|
-
export type { ApiConfig } from "./api";
|
|
1
|
+
export { useGetQuery } from "./fetch";
|
|
2
|
+
export type {
|
|
3
|
+
IGetQueryResult,
|
|
4
|
+
IUpdateQueryResult,
|
|
5
|
+
IDeleteQueryResult,
|
|
6
|
+
IListQuery,
|
|
7
|
+
ListQueryOptions,
|
|
8
|
+
GetQueryOptions,
|
|
9
|
+
} from "./interfaces";
|
|
10
|
+
export { useGetPaginatedQueryList } from "./list";
|
|
11
|
+
export { useUpdateQuery } from "./update";
|
|
12
|
+
export { useDeleteQuery } from "./delete";
|
|
13
|
+
export type {
|
|
14
|
+
IPaginationActions,
|
|
15
|
+
ISearchingActions,
|
|
16
|
+
IFilterActions,
|
|
17
|
+
ISortingActions,
|
|
18
|
+
ReturnedHeader,
|
|
19
|
+
} from "./interfaces";
|
|
20
|
+
export { API, configureApi, resetApi } from "./api";
|
|
21
|
+
export type { ApiConfig } from "./api";
|
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
import {
|
|
2
|
-
UseMutationResult,
|
|
3
|
-
UseQueryResult,
|
|
4
|
-
} from "react-query/types/react/types";
|
|
5
|
-
import { ExtractKey } from "../../types";
|
|
6
|
-
|
|
7
|
-
export interface IPaginationActions {
|
|
8
|
-
currentPage: number;
|
|
9
|
-
pageSize: number;
|
|
10
|
-
itemCount: number;
|
|
11
|
-
pageCount: number;
|
|
12
|
-
nextPage: () => void;
|
|
13
|
-
previousPage: () => void;
|
|
14
|
-
setPageSize: (pageSize: number) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ISearchingActions<TParam> {
|
|
18
|
-
searchText: string | undefined;
|
|
19
|
-
setSearchText: (value: string | undefined) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface IPagination {
|
|
23
|
-
next: number | null;
|
|
24
|
-
previous: number | null;
|
|
25
|
-
current: number;
|
|
26
|
-
last: number;
|
|
27
|
-
page_size: number;
|
|
28
|
-
count: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface ISortingActions<TParam> {
|
|
32
|
-
sortField: (key: NormalizedField<ExtractKey<TParam, "order_by">>) => void;
|
|
33
|
-
getSortingDirection: (
|
|
34
|
-
key: NormalizedField<ExtractKey<TParam, "order_by">>,
|
|
35
|
-
) => "asc" | "desc" | undefined;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface IFilterActions<TParam> {
|
|
39
|
-
getFilterFieldValue: (key: keyof TParam) => TParam[keyof TParam];
|
|
40
|
-
setFilterFieldValue: (
|
|
41
|
-
key: keyof TParam,
|
|
42
|
-
) => (value: TParam[keyof TParam]) => void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface IFilter {
|
|
46
|
-
[key: string]: unknown;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type UseQueryResultWithoutData<TResult> = Omit<
|
|
50
|
-
UseQueryResult<IPaginatedResponse<TResult>>,
|
|
51
|
-
"data"
|
|
52
|
-
>;
|
|
53
|
-
|
|
54
|
-
export type NormalizedField<T> = T extends `-${infer U}` ? U : T;
|
|
55
|
-
|
|
56
|
-
export interface ReturnedHeader {
|
|
57
|
-
key: string;
|
|
58
|
-
name: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export type IPaginatedResponse<TResult> = {
|
|
62
|
-
[key in keyof TResult]: TResult[key];
|
|
63
|
-
} & {
|
|
64
|
-
headers?: ReturnedHeader[];
|
|
65
|
-
pagination: IPagination;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export interface IListQuery<TParam, TQuery>
|
|
69
|
-
extends UseQueryResultWithoutData<TQuery> {
|
|
70
|
-
pagination: IPaginationActions;
|
|
71
|
-
searching: ISearchingActions<TParam>;
|
|
72
|
-
sorting: ISortingActions<TParam>;
|
|
73
|
-
filtering: IFilterActions<TParam>;
|
|
74
|
-
header: ReturnedHeader[] | undefined;
|
|
75
|
-
data: TQuery[] | undefined;
|
|
76
|
-
raw: IPaginatedResponse<TQuery> | undefined;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export type IGetQueryResult<TResult> = UseQueryResult<TResult>;
|
|
80
|
-
|
|
81
|
-
export interface WriteQueryVariables<TParams, TPayload> {
|
|
82
|
-
params: TParams;
|
|
83
|
-
payload: TPayload;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export type IUpdateQueryResult<TParams, TPayload, TResult> = UseMutationResult<
|
|
87
|
-
TResult,
|
|
88
|
-
unknown,
|
|
89
|
-
WriteQueryVariables<TParams, TPayload>,
|
|
90
|
-
unknown
|
|
91
|
-
>;
|
|
92
|
-
|
|
93
|
-
export type IDeleteQueryResult<TResult> = UseMutationResult<TResult>;
|
|
94
|
-
|
|
95
|
-
export interface ListQueryOptions<TParam, TResult> {
|
|
96
|
-
params?: Partial<TParam>;
|
|
97
|
-
requiredParams?: (keyof TParam)[];
|
|
98
|
-
searchKey?: keyof TParam;
|
|
99
|
-
defaultSortFields?: (string & ExtractKey<TParam, "order_by">)[];
|
|
100
|
-
onSuccess?: (result: IPaginatedResponse<TResult>) => void;
|
|
101
|
-
localCache?: boolean;
|
|
102
|
-
pageSize?: number;
|
|
103
|
-
localSearchFunction?: (
|
|
104
|
-
searchValue: string | undefined,
|
|
105
|
-
searchData: TResult,
|
|
106
|
-
) => boolean;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface GetQueryOptions<TParam> {
|
|
110
|
-
params?: Partial<TParam>;
|
|
111
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
UseMutationResult,
|
|
3
|
+
UseQueryResult,
|
|
4
|
+
} from "react-query/types/react/types";
|
|
5
|
+
import { ExtractKey } from "../../types";
|
|
6
|
+
|
|
7
|
+
export interface IPaginationActions {
|
|
8
|
+
currentPage: number;
|
|
9
|
+
pageSize: number;
|
|
10
|
+
itemCount: number;
|
|
11
|
+
pageCount: number;
|
|
12
|
+
nextPage: () => void;
|
|
13
|
+
previousPage: () => void;
|
|
14
|
+
setPageSize: (pageSize: number) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ISearchingActions<TParam> {
|
|
18
|
+
searchText: string | undefined;
|
|
19
|
+
setSearchText: (value: string | undefined) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IPagination {
|
|
23
|
+
next: number | null;
|
|
24
|
+
previous: number | null;
|
|
25
|
+
current: number;
|
|
26
|
+
last: number;
|
|
27
|
+
page_size: number;
|
|
28
|
+
count: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ISortingActions<TParam> {
|
|
32
|
+
sortField: (key: NormalizedField<ExtractKey<TParam, "order_by">>) => void;
|
|
33
|
+
getSortingDirection: (
|
|
34
|
+
key: NormalizedField<ExtractKey<TParam, "order_by">>,
|
|
35
|
+
) => "asc" | "desc" | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface IFilterActions<TParam> {
|
|
39
|
+
getFilterFieldValue: (key: keyof TParam) => TParam[keyof TParam];
|
|
40
|
+
setFilterFieldValue: (
|
|
41
|
+
key: keyof TParam,
|
|
42
|
+
) => (value: TParam[keyof TParam]) => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface IFilter {
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type UseQueryResultWithoutData<TResult> = Omit<
|
|
50
|
+
UseQueryResult<IPaginatedResponse<TResult>>,
|
|
51
|
+
"data"
|
|
52
|
+
>;
|
|
53
|
+
|
|
54
|
+
export type NormalizedField<T> = T extends `-${infer U}` ? U : T;
|
|
55
|
+
|
|
56
|
+
export interface ReturnedHeader {
|
|
57
|
+
key: string;
|
|
58
|
+
name: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type IPaginatedResponse<TResult> = {
|
|
62
|
+
[key in keyof TResult]: TResult[key];
|
|
63
|
+
} & {
|
|
64
|
+
headers?: ReturnedHeader[];
|
|
65
|
+
pagination: IPagination;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export interface IListQuery<TParam, TQuery>
|
|
69
|
+
extends UseQueryResultWithoutData<TQuery> {
|
|
70
|
+
pagination: IPaginationActions;
|
|
71
|
+
searching: ISearchingActions<TParam>;
|
|
72
|
+
sorting: ISortingActions<TParam>;
|
|
73
|
+
filtering: IFilterActions<TParam>;
|
|
74
|
+
header: ReturnedHeader[] | undefined;
|
|
75
|
+
data: TQuery[] | undefined;
|
|
76
|
+
raw: IPaginatedResponse<TQuery> | undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type IGetQueryResult<TResult> = UseQueryResult<TResult>;
|
|
80
|
+
|
|
81
|
+
export interface WriteQueryVariables<TParams, TPayload> {
|
|
82
|
+
params: TParams;
|
|
83
|
+
payload: TPayload;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type IUpdateQueryResult<TParams, TPayload, TResult> = UseMutationResult<
|
|
87
|
+
TResult,
|
|
88
|
+
unknown,
|
|
89
|
+
WriteQueryVariables<TParams, TPayload>,
|
|
90
|
+
unknown
|
|
91
|
+
>;
|
|
92
|
+
|
|
93
|
+
export type IDeleteQueryResult<TResult> = UseMutationResult<TResult>;
|
|
94
|
+
|
|
95
|
+
export interface ListQueryOptions<TParam, TResult> {
|
|
96
|
+
params?: Partial<TParam>;
|
|
97
|
+
requiredParams?: (keyof TParam)[];
|
|
98
|
+
searchKey?: keyof TParam;
|
|
99
|
+
defaultSortFields?: (string & ExtractKey<TParam, "order_by">)[];
|
|
100
|
+
onSuccess?: (result: IPaginatedResponse<TResult>) => void;
|
|
101
|
+
localCache?: boolean;
|
|
102
|
+
pageSize?: number;
|
|
103
|
+
localSearchFunction?: (
|
|
104
|
+
searchValue: string | undefined,
|
|
105
|
+
searchData: TResult,
|
|
106
|
+
) => boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface GetQueryOptions<TParam> {
|
|
110
|
+
params?: Partial<TParam>;
|
|
111
|
+
}
|