Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chayen

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chayen - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

9

dist/Server.d.ts

@@ -8,8 +8,10 @@ /// <reference types="node" />

}
export interface CacheOption {
ttl: number;
limit?: number;
}
export interface Endpoint {
schema: Joi.Schema;
timeout?: number;
cache?: {
ttl: number;
};
cacheOption?: CacheOption | false;
handler(payload: any, delegator: Delegator): any;

@@ -36,3 +38,4 @@ }

terminate(): Promise<void>;
private shouldReturnCache(cacheOption, cacheKey);
private executeEndpoint(topic, payload);
}

@@ -78,3 +78,2 @@ "use strict";

return;
this.server.close();
if (this.redis) {

@@ -88,5 +87,25 @@ try {

}
this.server.close();
delete this.server;
});
}
shouldReturnCache(cacheOption, cacheKey) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.redis || !cacheOption)
return false;
if (!cacheOption.limit)
return true;
try {
const cacheCount = yield this.redis.incr(`${cacheKey}::count`);
if (cacheCount === 1) {
yield this.redis.expire(`${cacheKey}::count`, cacheOption.ttl);
}
return cacheCount > cacheOption.limit;
}
catch (err) {
console.error(err);
}
return false;
});
}
executeEndpoint(topic, payload) {

@@ -103,5 +122,6 @@ return __awaiter(this, void 0, void 0, function* () {

}
if (this.redis && endpoint.cache) {
const cacheKey = _getCacheKey(topic, payload);
if (yield this.shouldReturnCache(endpoint.cacheOption, cacheKey)) {
try {
const cache = yield this.redis.get(_getCacheKey(topic, payload));
const cache = yield this.redis.get(cacheKey);
if (cache)

@@ -130,7 +150,6 @@ return JSON.parse(cache).v;

}
if (this.redis && endpoint.cache) {
if (this.redis && endpoint.cacheOption) {
try {
const key = _getCacheKey(topic, payload);
const value = JSON.stringify({ v: result });
yield this.redis.set([key, value, 'EX', endpoint.cache.ttl]);
yield this.redis.set([cacheKey, value, 'EX', endpoint.cacheOption.ttl]);
}

@@ -137,0 +156,0 @@ catch (err) {

{
"name": "chayen",
"version": "0.1.4",
"version": "0.2.0",
"description": "An RPC framework with so much hype going on. such wow.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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