update createApi

This commit is contained in:
Mohamadzadeh 2026-06-21 15:09:19 +03:30
parent af068a945e
commit 8652f81ade
2 changed files with 238 additions and 220 deletions

445
dist/core.js vendored

File diff suppressed because one or more lines are too long

View File

@ -46,6 +46,10 @@ function joinUrl(baseUrl, id) {
return `${baseUrl.replace(/\/$/, "")}/${id}`;
}
function toHookName(actionName) {
return `use${actionName.charAt(0).toUpperCase()}${actionName.slice(1)}`;
}
export function createApi({
key,
url,
@ -138,6 +142,13 @@ export function createApi({
});
}
const actionHooks = Object.keys(actions).reduce((acc, actionName) => {
acc[toHookName(actionName)] = (options = {}) =>
useAction(actionName, options);
return acc;
}, {});
return {
key: baseKey,
listKey,
@ -145,5 +156,7 @@ export function createApi({
useGet,
useItem,
useAction,
...actionHooks,
};
}