mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge fba71210a2
into d2c3ecf2f8
This commit is contained in:
commit
14f0af2c6f
@ -9,19 +9,19 @@
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
|
||||
import { QueryType, TMutationOptions } from "@/services/types";
|
||||
import { IBaseSchema, IDynamicProps, TType } from "@/types/base.types";
|
||||
import { IBaseSchema, THook } from "@/types/base.types";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
|
||||
import { isSameEntity, useNormalizeAndCache } from "./helpers";
|
||||
|
||||
export const useCreate = <
|
||||
TEntity extends IDynamicProps["entity"],
|
||||
TAttr = TType<TEntity>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TEntity>["basic"],
|
||||
TFull extends IBaseSchema = TType<TEntity>["full"],
|
||||
TE extends THook["entity"],
|
||||
TAttr = THook<{ entity: TE }>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<{ entity: TE }>["basic"],
|
||||
TFull extends IBaseSchema = THook<{ entity: TE }>["full"],
|
||||
>(
|
||||
entity: TEntity,
|
||||
entity: TE,
|
||||
options?: Omit<
|
||||
TMutationOptions<TBasic, Error, TAttr, TBasic>,
|
||||
"mutationFn" | "mutationKey"
|
||||
|
@ -9,24 +9,19 @@
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
|
||||
import { QueryType, TMutationOptions } from "@/services/types";
|
||||
import {
|
||||
IBaseSchema,
|
||||
IDynamicProps,
|
||||
IEntityMapTypes,
|
||||
TType,
|
||||
} from "@/types/base.types";
|
||||
import { IBaseSchema, IEntityMapTypes, THook } from "@/types/base.types";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
|
||||
import { isSameEntity } from "./helpers";
|
||||
|
||||
export const useDelete = <
|
||||
TEntity extends IDynamicProps["entity"],
|
||||
TAttr = TType<TEntity>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TEntity>["basic"],
|
||||
TFull extends IBaseSchema = TType<TEntity>["full"],
|
||||
TE extends THook["entity"],
|
||||
TAttr = THook<{ entity: TE }>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<{ entity: TE }>["basic"],
|
||||
TFull extends IBaseSchema = THook<{ entity: TE }>["full"],
|
||||
>(
|
||||
entity: TEntity,
|
||||
entity: TE,
|
||||
options?: Omit<
|
||||
TMutationOptions<string, Error, string, TBasic>,
|
||||
"mutationFn" | "mutationKey"
|
||||
|
@ -9,19 +9,19 @@
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
|
||||
import { QueryType, TMutationOptions } from "@/services/types";
|
||||
import { IBaseSchema, IDynamicProps, TType } from "@/types/base.types";
|
||||
import { IBaseSchema, THook } from "@/types/base.types";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
|
||||
import { isSameEntity } from "./helpers";
|
||||
|
||||
export const useDeleteMany = <
|
||||
TEntity extends IDynamicProps["entity"],
|
||||
TAttr = TType<TEntity>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TEntity>["basic"],
|
||||
TFull extends IBaseSchema = TType<TEntity>["full"],
|
||||
TE extends THook["entity"],
|
||||
TAttr = THook<{ entity: TE }>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<{ entity: TE }>["basic"],
|
||||
TFull extends IBaseSchema = THook<{ entity: TE }>["full"],
|
||||
>(
|
||||
entity: TEntity,
|
||||
entity: TE,
|
||||
options?: Omit<
|
||||
TMutationOptions<string, Error, string[], TBasic>,
|
||||
"mutationFn" | "mutationKey"
|
||||
|
@ -8,19 +8,12 @@
|
||||
|
||||
import { useQuery, UseQueryOptions } from "react-query";
|
||||
|
||||
import {
|
||||
EntityType,
|
||||
Format,
|
||||
QueryType,
|
||||
TPopulateTypeFromFormat,
|
||||
} from "@/services/types";
|
||||
import { EntityType, Format, QueryType } from "@/services/types";
|
||||
import {
|
||||
IBaseSchema,
|
||||
IDynamicProps,
|
||||
IFindConfigProps,
|
||||
POPULATE_BY_TYPE,
|
||||
TAllowedFormat,
|
||||
TType,
|
||||
THook,
|
||||
} from "@/types/base.types";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
@ -31,13 +24,13 @@ import { useCount } from "./useCount";
|
||||
import { useGetFromCache } from "./useGet";
|
||||
|
||||
export const useFind = <
|
||||
TDynamicProps extends IDynamicProps,
|
||||
TAttr = TType<TDynamicProps["entity"]>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TDynamicProps["entity"]>["basic"],
|
||||
TFull extends IBaseSchema = TType<TDynamicProps["entity"]>["full"],
|
||||
P = TPopulateTypeFromFormat<TDynamicProps>,
|
||||
TP extends THook["params"],
|
||||
TAttr = THook<TP>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<TP>["basic"],
|
||||
TFull extends IBaseSchema = THook<TP>["full"],
|
||||
P = THook<TP>["populate"],
|
||||
>(
|
||||
{ entity, format }: TDynamicProps & TAllowedFormat<TDynamicProps["entity"]>,
|
||||
{ entity, format }: THook<TP>["params"],
|
||||
config?: IFindConfigProps,
|
||||
options?: Omit<
|
||||
UseQueryOptions<string[], Error, string[], [QueryType, EntityType, string]>,
|
||||
|
@ -11,10 +11,9 @@ import { useQuery, useQueryClient, UseQueryOptions } from "react-query";
|
||||
import { EntityType, Format, QueryType } from "@/services/types";
|
||||
import {
|
||||
IBaseSchema,
|
||||
IDynamicProps,
|
||||
IEntityMapTypes,
|
||||
POPULATE_BY_TYPE,
|
||||
TAllowedFormat,
|
||||
THook,
|
||||
TType,
|
||||
} from "@/types/base.types";
|
||||
|
||||
@ -23,13 +22,13 @@ import { useEntityApiClient } from "../useApiClient";
|
||||
import { useNormalizeAndCache } from "./helpers";
|
||||
|
||||
export const useGet = <
|
||||
TDynamicProps extends IDynamicProps,
|
||||
TAttr = TType<TDynamicProps["entity"]>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TDynamicProps["entity"]>["basic"],
|
||||
TFull extends IBaseSchema = TType<TDynamicProps["entity"]>["full"],
|
||||
T extends THook["params"],
|
||||
TAttr = THook<T>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<T>["basic"],
|
||||
TFull extends IBaseSchema = THook<T>["full"],
|
||||
>(
|
||||
id: string,
|
||||
{ entity, format }: TDynamicProps & TAllowedFormat<TDynamicProps["entity"]>,
|
||||
{ entity, format }: THook<T>["params"],
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
unknown,
|
||||
|
@ -9,18 +9,18 @@
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
|
||||
import { QueryType, TMutationOptions } from "@/services/types";
|
||||
import { IBaseSchema, IDynamicProps, TType } from "@/types/base.types";
|
||||
import { IBaseSchema, THook } from "@/types/base.types";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
|
||||
import { isSameEntity, useNormalizeAndCache } from "./helpers";
|
||||
|
||||
export const useImport = <
|
||||
TEntity extends IDynamicProps["entity"],
|
||||
TE extends THook["entity"],
|
||||
TAttr extends File = File,
|
||||
TBasic extends IBaseSchema = TType<TEntity>["basic"],
|
||||
TBasic extends IBaseSchema = THook<{ entity: TE }>["basic"],
|
||||
>(
|
||||
entity: TEntity,
|
||||
entity: TE,
|
||||
options: Omit<
|
||||
TMutationOptions<TBasic[], Error, TAttr, TBasic[]>,
|
||||
"mutationFn" | "mutationKey"
|
||||
|
@ -8,19 +8,12 @@
|
||||
|
||||
import { useInfiniteQuery, UseInfiniteQueryOptions } from "react-query";
|
||||
|
||||
import {
|
||||
EntityType,
|
||||
Format,
|
||||
QueryType,
|
||||
TPopulateTypeFromFormat,
|
||||
} from "@/services/types";
|
||||
import { EntityType, Format, QueryType } from "@/services/types";
|
||||
import {
|
||||
IBaseSchema,
|
||||
IDynamicProps,
|
||||
IFindConfigProps,
|
||||
POPULATE_BY_TYPE,
|
||||
TAllowedFormat,
|
||||
TType,
|
||||
THook,
|
||||
} from "@/types/base.types";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
@ -29,13 +22,13 @@ import { useNormalizeAndCache } from "./helpers";
|
||||
import { useGetFromCache } from "./useGet";
|
||||
|
||||
export const useInfiniteFind = <
|
||||
TDynamicProps extends IDynamicProps,
|
||||
TAttr = TType<TDynamicProps["entity"]>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TDynamicProps["entity"]>["basic"],
|
||||
TFull extends IBaseSchema = TType<TDynamicProps["entity"]>["full"],
|
||||
P = TPopulateTypeFromFormat<TDynamicProps>,
|
||||
T extends THook["params"],
|
||||
TAttr = THook<T>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<T>["basic"],
|
||||
TFull extends IBaseSchema = THook<T>["full"],
|
||||
P = THook<T>["populate"],
|
||||
>(
|
||||
{ entity, format }: TDynamicProps & TAllowedFormat<TDynamicProps["entity"]>,
|
||||
{ entity, format }: THook<T>["params"],
|
||||
config?: IFindConfigProps,
|
||||
options?: Omit<
|
||||
UseInfiniteQueryOptions<
|
||||
|
@ -8,19 +8,12 @@
|
||||
|
||||
import { useInfiniteQuery, UseInfiniteQueryOptions } from "react-query";
|
||||
|
||||
import {
|
||||
EntityType,
|
||||
Format,
|
||||
QueryType,
|
||||
TPopulateTypeFromFormat,
|
||||
} from "@/services/types";
|
||||
import { EntityType, Format, QueryType } from "@/services/types";
|
||||
import {
|
||||
IBaseSchema,
|
||||
IDynamicProps,
|
||||
IFindConfigProps,
|
||||
POPULATE_BY_TYPE,
|
||||
TAllowedFormat,
|
||||
TType,
|
||||
THook,
|
||||
} from "@/types/base.types";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
@ -32,13 +25,13 @@ import { useGetFromCache } from "./useGet";
|
||||
const PAGE_SIZE = 20;
|
||||
|
||||
export const useNormalizedInfiniteQuery = <
|
||||
TDynamicProps extends IDynamicProps,
|
||||
TAttr = TType<TDynamicProps["entity"]>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TDynamicProps["entity"]>["basic"],
|
||||
TFull extends IBaseSchema = TType<TDynamicProps["entity"]>["full"],
|
||||
P = TPopulateTypeFromFormat<TDynamicProps>,
|
||||
T extends THook["params"],
|
||||
TAttr = THook<T>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<T>["basic"],
|
||||
TFull extends IBaseSchema = THook<T>["full"],
|
||||
P = THook<T>["populate"],
|
||||
>(
|
||||
{ entity, format }: TDynamicProps & TAllowedFormat<TDynamicProps["entity"]>,
|
||||
{ entity, format }: THook<T>["params"],
|
||||
config?: IFindConfigProps,
|
||||
options?: Omit<
|
||||
UseInfiniteQueryOptions<
|
||||
|
@ -9,12 +9,7 @@
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
|
||||
import { QueryType, TMutationOptions, TSetCacheProps } from "@/services/types";
|
||||
import {
|
||||
IBaseSchema,
|
||||
IDynamicProps,
|
||||
IEntityMapTypes,
|
||||
TType,
|
||||
} from "@/types/base.types";
|
||||
import { IBaseSchema, IEntityMapTypes, THook, TType } from "@/types/base.types";
|
||||
import { merge } from "@/utils/object";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
@ -23,12 +18,12 @@ import { useNormalizeAndCache } from "./helpers";
|
||||
import { useGetFromCache } from "./useGet";
|
||||
|
||||
export const useUpdate = <
|
||||
TEntity extends IDynamicProps["entity"],
|
||||
TAttr = TType<TEntity>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TEntity>["basic"],
|
||||
TFull extends IBaseSchema = TType<TEntity>["full"],
|
||||
TE extends THook["entity"],
|
||||
TAttr = THook<{ entity: TE }>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<{ entity: TE }>["basic"],
|
||||
TFull extends IBaseSchema = THook<{ entity: TE }>["full"],
|
||||
>(
|
||||
entity: TEntity,
|
||||
entity: TE,
|
||||
options?: Omit<
|
||||
TMutationOptions<
|
||||
TBasic,
|
||||
|
@ -9,19 +9,19 @@
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
|
||||
import { QueryType, TMutationOptions } from "@/services/types";
|
||||
import { IBaseSchema, IDynamicProps, TType } from "@/types/base.types";
|
||||
import { IBaseSchema, THook } from "@/types/base.types";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
|
||||
import { isSameEntity } from "./helpers";
|
||||
|
||||
export const useUpdateMany = <
|
||||
TEntity extends IDynamicProps["entity"],
|
||||
TAttr = TType<TEntity>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TEntity>["basic"],
|
||||
TFull extends IBaseSchema = TType<TEntity>["full"],
|
||||
TE extends THook["entity"],
|
||||
TAttr = THook<{ entity: TE }>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<{ entity: TE }>["basic"],
|
||||
TFull extends IBaseSchema = THook<{ entity: TE }>["full"],
|
||||
>(
|
||||
entity: TEntity,
|
||||
entity: TE,
|
||||
options?: Omit<
|
||||
TMutationOptions<
|
||||
string,
|
||||
|
@ -10,19 +10,19 @@ import { useMutation, useQueryClient } from "react-query";
|
||||
|
||||
import { QueryType, TMutationOptions } from "@/services/types";
|
||||
import { AttachmentResourceRef } from "@/types/attachment.types";
|
||||
import { IBaseSchema, IDynamicProps, TType } from "@/types/base.types";
|
||||
import { IBaseSchema, THook } from "@/types/base.types";
|
||||
|
||||
import { useEntityApiClient } from "../useApiClient";
|
||||
|
||||
import { isSameEntity, useNormalizeAndCache } from "./helpers";
|
||||
|
||||
export const useUpload = <
|
||||
TEntity extends IDynamicProps["entity"],
|
||||
TAttr = TType<TEntity>["attributes"],
|
||||
TBasic extends IBaseSchema = TType<TEntity>["basic"],
|
||||
TFull extends IBaseSchema = TType<TEntity>["full"],
|
||||
TE extends THook["entity"],
|
||||
TAttr = THook<{ entity: TE }>["attributes"],
|
||||
TBasic extends IBaseSchema = THook<{ entity: TE }>["basic"],
|
||||
TFull extends IBaseSchema = THook<{ entity: TE }>["full"],
|
||||
>(
|
||||
entity: TEntity,
|
||||
entity: TE,
|
||||
options?: Omit<
|
||||
TMutationOptions<
|
||||
TBasic,
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import { GridPaginationModel, GridSortModel } from "@mui/x-data-grid";
|
||||
|
||||
import { EntityType, Format } from "@/services/types";
|
||||
import { EntityType, Format, TPopulateTypeFromFormat } from "@/services/types";
|
||||
|
||||
import { IAttachment, IAttachmentAttributes } from "./attachment.types";
|
||||
import {
|
||||
@ -39,8 +39,8 @@ import {
|
||||
INlpEntityFull,
|
||||
} from "./nlp-entity.types";
|
||||
import {
|
||||
INlpDatasetSampleAttributes,
|
||||
INlpSample,
|
||||
INlpSampleAttributes,
|
||||
INlpSampleFull,
|
||||
} from "./nlp-sample.types";
|
||||
import {
|
||||
@ -170,7 +170,7 @@ export interface IEntityMapTypes {
|
||||
INlpEntityFull
|
||||
>;
|
||||
[EntityType.NLP_SAMPLE]: IEntityTypes<
|
||||
INlpSampleAttributes,
|
||||
INlpDatasetSampleAttributes,
|
||||
INlpSample,
|
||||
INlpSampleFull
|
||||
>;
|
||||
@ -225,9 +225,28 @@ export type TAllowedFormat<T extends keyof IEntityMapTypes> = {
|
||||
export interface IDynamicProps {
|
||||
entity: keyof IEntityMapTypes;
|
||||
format?: Format;
|
||||
route?: keyof IEntityMapTypes;
|
||||
}
|
||||
|
||||
type AllNever<T> = {
|
||||
[K in keyof T]: never;
|
||||
};
|
||||
|
||||
export type THook<
|
||||
G extends IDynamicProps = IDynamicProps,
|
||||
TE extends keyof IEntityMapTypes = G["entity"],
|
||||
TP extends IDynamicProps = IDynamicProps &
|
||||
G &
|
||||
AllNever<Omit<G, keyof IDynamicProps>> &
|
||||
TAllowedFormat<TE>,
|
||||
> = {
|
||||
full: TType<TE>["full"];
|
||||
basic: TType<TE>["basic"];
|
||||
params: TP;
|
||||
entity: TE;
|
||||
populate: TPopulateTypeFromFormat<G>;
|
||||
attributes: TType<TE>["attributes"];
|
||||
};
|
||||
|
||||
export interface IFindConfigProps {
|
||||
params?: any;
|
||||
hasCount?: boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user