Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
init: (context, next, makeRequest) => {
const cacheKey = getCacheKeyUtil(context, getCacheKey);
if (lruCache.has(cacheKey)) {
context.updateExternalMeta(metaTypes.CACHE, {
memoryCache: true,
memoryCacheOutdated: false,
});
return next({
status: Status.COMPLETE,
response: lruCache.get(cacheKey),
});
}
const allowOutdated = propOr('memoryCacheAllowStale', allowStale, context.getRequest());
const outdated = allowOutdated && lruCache.peek(cacheKey);
if (outdated) {
const request = context.getRequest();
context.updateExternalMeta(metaTypes.CACHE, {
memoryCache: true,
memoryCacheOutdated: true,
});
lruCache.set(cacheKey, outdated, staleTtl); // remember outdated value, to prevent losing it
setTimeout(
() =>
makeRequest({
...request,
memoryCacheForce: true,
context.setState(newState);
const state = context.getState();
if (state.status !== initialStatus) {
return cb(true);
}
i += direction;
if (i < 0 || i >= len) {
return cb(false);
}
const plugin = plugins[i];
const pluginAction = plugin[event];
if (!pluginAction || !applyOrReturn([context], propOr('shouldExecute', true, plugin))) {
return next();
}
try {
pluginAction(context, once(next), makeRequest);
} catch (err) {
return next({ status: Status.ERROR, error: err });
}
};
responseType,
} = context.getRequest();
let ended = false;
const method = httpMethod.toLowerCase();
const noBody = method === HttpMethods.GET || method === HttpMethods.HEAD;
let body;
let formHeaders;
if (attaches.length) {
body = createForm(payload, isBrowser ? attaches : []);
formHeaders = body.getHeaders && body.getHeaders();
} else {
const contentType = propOr(type, type, REQUEST_TYPES);
formHeaders = contentType ? { 'Content-type': contentType } : {};
if (!noBody) {
body = serialize(type, payload);
}
}
let timer;
let signal;
if (AbortController) {
const controller = new AbortController();
signal = controller.signal;
const abort = (abortOptions?) => {
if (ended) {
export default (name: string, dflt: boolean) => (context: Context) => {
const request = context.getRequest();
const forced = prop('cacheForce', request);
const forcedSpecific = prop(`${name}CacheForce`, request);
const disabled = propEq('cache', false, request);
const enabledSpecific = propOr(`${name}Cache`, disabled ? false : dflt, request);
const isComplete = context.getStatus() === Status.COMPLETE;
if (context.getStatus() === Status.INIT) {
context.updateExternalMeta(CACHE, {
forced,
enabled: !disabled,
[`${name}Enabled`]: enabledSpecific,
[`${name}Force`]: forcedSpecific,
});
}
if (forcedSpecific) {
return isComplete;
}
if (isUndefined(forcedSpecific) && forced) {
init: (context, next) => {
const request = context.getRequest();
const batchKey: string = prop('batchKey', request);
const batchTimeout = propOr('batchTimeout', timeout, request);
context.updateExternalMeta(BATCH, {
batched: true,
});
const running = batchRequests[batchKey];
if (running) {
running.requests.push(request);
running.nexts.push(next);
return;
}
batchRequests[batchKey] = { requests: [request], nexts: [next] };
setTimeout(() => {