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

447
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}`; return `${baseUrl.replace(/\/$/, "")}/${id}`;
} }
function toHookName(actionName) {
return `use${actionName.charAt(0).toUpperCase()}${actionName.slice(1)}`;
}
export function createApi({ export function createApi({
key, key,
url, 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 { return {
key: baseKey, key: baseKey,
listKey, listKey,
@ -145,5 +156,7 @@ export function createApi({
useGet, useGet,
useItem, useItem,
useAction, useAction,
...actionHooks,
}; };
} }