Socket
Socket
Sign inDemoInstall

@quantos/micro-request

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@quantos/micro-request - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

2

dist/fallback_error_handler.js

@@ -6,3 +6,3 @@ "use strict";

const fallbackErrorHandler = (e, fallback) => {
if (utils_1.is500error(e)) {
if ((0, utils_1.is500error)(e)) {
if (fallback) {

@@ -9,0 +9,0 @@ return fallback;

export interface MicroRequestOptions {
cache?: boolean;
cachePrefix?: string;
headers?: any;

@@ -4,0 +5,0 @@ retry?: number;

@@ -25,4 +25,5 @@ "use strict";

const _url = options.url(options.serviceUrl, options.id);
const _cachePrefix = options.cachePrefix || options.serviceUrl;
if (options.cache) {
const cached = yield redis_cache_1.RedisCache.get(`${options.id}`, options.serviceUrl);
const cached = yield redis_cache_1.RedisCache.get(`${options.id}`, _cachePrefix);
if (cached) {

@@ -36,3 +37,3 @@ return cached;

if (options.cache) {
yield redis_cache_1.RedisCache.set(options.id, _res.data, options.serviceUrl);
yield redis_cache_1.RedisCache.set(options.id, _res.data, _cachePrefix);
}

@@ -42,3 +43,3 @@ return _res.data;

catch (e) {
return fallback_error_handler_1.fallbackErrorHandler(e, options.fallback);
return (0, fallback_error_handler_1.fallbackErrorHandler)(e, options.fallback);
}

@@ -51,5 +52,6 @@ });

const _url = options.url(options.serviceUrl, options.ids);
const _cachePrefix = options.cachePrefix || options.serviceUrl;
const results = [];
if (options.cache) {
const _cached = yield redis_cache_1.RedisCache.getMany(options.ids, options.serviceUrl);
const _cached = yield redis_cache_1.RedisCache.getMany(options.ids, _cachePrefix);
if (_cached && _cached.length) {

@@ -68,7 +70,7 @@ results.push(..._cached);

catch (e) {
return fallback_error_handler_1.fallbackErrorHandler(e, options.fallback);
return (0, fallback_error_handler_1.fallbackErrorHandler)(e, options.fallback);
}
if (options.cache) {
for (const t of fetched) {
yield redis_cache_1.RedisCache.set(t.id, t, options.serviceUrl);
yield redis_cache_1.RedisCache.set(t.id, t, _cachePrefix);
}

@@ -85,4 +87,5 @@ }

const _url = options.url;
const _cachePrefix = options.cachePrefix;
if (options.cache) {
const cached = yield redis_cache_1.RedisCache.get(_url);
const cached = yield redis_cache_1.RedisCache.get(_url, _cachePrefix);
if (cached) {

@@ -96,3 +99,3 @@ return cached;

if (options.cache) {
yield redis_cache_1.RedisCache.set(_url, _res.data);
yield redis_cache_1.RedisCache.set(_url, _res.data, _cachePrefix);
}

@@ -102,3 +105,3 @@ return _res.data;

catch (e) {
return fallback_error_handler_1.fallbackErrorHandler(e, options.fallback);
return (0, fallback_error_handler_1.fallbackErrorHandler)(e, options.fallback);
}

@@ -105,0 +108,0 @@ });

@@ -35,3 +35,3 @@ "use strict";

catch (e) {
if (utils_1.is500error(e)) {
if ((0, utils_1.is500error)(e)) {
if (retry < this.retry) {

@@ -38,0 +38,0 @@ yield this.sleep();

{
"name": "@quantos/micro-request",
"version": "1.0.5",
"version": "1.0.6",
"description": "Quantos http client with cache, retry and fallback mechanism",

@@ -5,0 +5,0 @@ "author": "fabriziotognetto <info@quantos.it>",

export interface MicroRequestOptions {
cache?: boolean;
cachePrefix?: string;
headers?: any;

@@ -5,0 +6,0 @@ retry?: number;

@@ -25,5 +25,6 @@ import { fallbackErrorHandler } from './fallback_error_handler';

const _url = options.url(options.serviceUrl, options.id);
const _cachePrefix = options.cachePrefix || options.serviceUrl;
if (options.cache) {
const cached = await RedisCache.get<T>(`${options.id}`, options.serviceUrl);
const cached = await RedisCache.get<T>(`${options.id}`, _cachePrefix);
if (cached) { return cached; }

@@ -37,3 +38,3 @@ }

// salvo nella cache
if (options.cache) { await RedisCache.set<Y, T>(options.id, _res.data, options.serviceUrl); }
if (options.cache) { await RedisCache.set<Y, T>(options.id, _res.data, _cachePrefix); }
// torno la risposta

@@ -54,3 +55,3 @@ return _res.data;

const _url = options.url(options.serviceUrl, options.ids);
const _cachePrefix = options.cachePrefix || options.serviceUrl;
const results: T[] = [];

@@ -60,3 +61,3 @@

// prendo prima dalla cache
const _cached = await RedisCache.getMany<Y, T>(options.ids, options.serviceUrl); // cache.getCacheds(options.ids.map(String));
const _cached = await RedisCache.getMany<Y, T>(options.ids, _cachePrefix); // cache.getCacheds(options.ids.map(String));
if (_cached && _cached.length) {

@@ -83,3 +84,3 @@ results.push(..._cached);

for (const t of fetched) {
await RedisCache.set<Y, T>(t.id, t, options.serviceUrl);
await RedisCache.set<Y, T>(t.id, t, _cachePrefix);
}

@@ -100,5 +101,6 @@ }

const _url = options.url;
const _cachePrefix = options.cachePrefix;
if (options.cache) {
const cached = await RedisCache.get(_url);
const cached = await RedisCache.get(_url, _cachePrefix);
if (cached) { return cached; }

@@ -112,3 +114,3 @@ }

// salvo nella cache
if (options.cache) { await RedisCache.set(_url, _res.data); }
if (options.cache) { await RedisCache.set(_url, _res.data, _cachePrefix); }
// torno la risposta

@@ -115,0 +117,0 @@ return _res.data;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc