mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
update & fix typing, updated examples
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
import type { DataApi } from "data/api/DataApi";
|
||||
import { useApi } from "ui/client";
|
||||
|
||||
type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => any
|
||||
? (...args: P) => ReturnType<F>
|
||||
: never;
|
||||
|
||||
/**
|
||||
* Maps all DataApi functions and omits
|
||||
* the first argument "entity" for convenience
|
||||
* @param entity
|
||||
*/
|
||||
export const useData = <T extends keyof DataApi<DB>>(entity: string) => {
|
||||
const api = useApi().data;
|
||||
const methods = [
|
||||
"readOne",
|
||||
"readMany",
|
||||
"readManyByReference",
|
||||
"createOne",
|
||||
"updateOne",
|
||||
"deleteOne"
|
||||
] as const;
|
||||
|
||||
return methods.reduce(
|
||||
(acc, method) => {
|
||||
// @ts-ignore
|
||||
acc[method] = (...params) => {
|
||||
// @ts-ignore
|
||||
return api[method](entity, ...params);
|
||||
};
|
||||
return acc;
|
||||
},
|
||||
{} as {
|
||||
[K in (typeof methods)[number]]: OmitFirstArg<(typeof api)[K]>;
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { PrimaryFieldType } from "core";
|
||||
import type { DB, PrimaryFieldType } from "core";
|
||||
import { encodeSearch, objectTransform } from "core/utils";
|
||||
import type { EntityData, RepoQuery } from "data";
|
||||
import type { ModuleApi, ResponseObject } from "modules/ModuleApi";
|
||||
|
||||
@@ -7,7 +7,6 @@ export {
|
||||
} from "./ClientProvider";
|
||||
|
||||
export * from "./api/use-api";
|
||||
export * from "./api/use-data";
|
||||
export * from "./api/use-entity";
|
||||
export { useAuth } from "./schema/auth/use-auth";
|
||||
export { Api } from "../../Api";
|
||||
|
||||
Reference in New Issue
Block a user