rest-api-kit
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -26,3 +26,3 @@ type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; | ||
endpointName: string; | ||
successCondition: (data: unknown) => boolean; | ||
successCondition: (data: any) => boolean; | ||
transformResponse: (data: unknown) => unknown; | ||
@@ -55,3 +55,3 @@ } | ||
declare function useRest(url: string, params?: Partial<IOptions>, options?: Partial<RestOptionsType>): QueryHookReturnType; | ||
declare function useRest(url: string, paramsFromBase?: Partial<IOptions>, options?: Partial<RestOptionsType>): QueryHookReturnType; | ||
@@ -58,0 +58,0 @@ declare const createRestBase: (restBaseOptions?: Partial<RestOptionsType>) => RestBaseReturnType; |
@@ -190,3 +190,3 @@ "use strict"; | ||
}; | ||
function useRest(url, params = {}, options = {}) { | ||
function useRest(url, paramsFromBase = {}, options = {}) { | ||
const [state, dispatch] = (0, import_react2.useReducer)(reducer2, initState2); | ||
@@ -196,9 +196,9 @@ const { save: saveToStore, get: getFromStore, clear: clearFromStore } = useStore(); | ||
try { | ||
const allParams = { ...defaultOptions, params }; | ||
const params = { ...defaultOptions, ...paramsFromBase }; | ||
url = getBaseUrl(url, options?.baseUrl); | ||
let storeIdentifier = `${options.baseUrl || ""}&${params.endpointName}`; | ||
if (Object(params).hasOwnProperty("preferCachevalue")) { | ||
if (params.preferCachevalue) { | ||
let cachedResult = getFromStore(storeIdentifier); | ||
if (cachedResult) { | ||
applyChecks(allParams, dispatch, cachedResult); | ||
applyChecks(params, dispatch, cachedResult); | ||
return; | ||
@@ -211,7 +211,7 @@ } | ||
const response = await makeRequest(concatenateParamsWithUrl(url, body)); | ||
dispatch({ type: "data/success", payload: applyChecks(allParams, dispatch, response) }); | ||
dispatch({ type: "data/success", payload: applyChecks(params, dispatch, response) }); | ||
if (params?.saveToCache) { | ||
saveToStore(storeIdentifier, response, { ...defaultOptions, ...params }); | ||
} | ||
if (Object(params).hasOwnProperty("updates")) { | ||
if (params.updates.length > 0) { | ||
clearMultipleIds(params.updates, options.baseUrl || "", (id) => clearFromStore(id)); | ||
@@ -218,0 +218,0 @@ } |
{ | ||
"name": "rest-api-kit", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.mjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21345