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

@javien/mikro-orm-redis-cache-adapter

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@javien/mikro-orm-redis-cache-adapter - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

dist/options.d.ts

152

dist/redisCacheAdapter.js

@@ -1,1 +0,151 @@

"use strict";var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var u=(s,e)=>{for(var t in e)d(s,t,{get:e[t],enumerable:!0})},f=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of p(e))!h.call(s,i)&&i!==t&&d(s,i,{get:()=>e[i],enumerable:!(r=g(e,i))||r.enumerable});return s};var m=s=>f(d({},"__esModule",{value:!0}),s);var y={};u(y,{RedisCacheAdapter:()=>c});module.exports=m(y);var a=class{debug=!1;prefix="mikro";prefixDelimiter=":";logger=console.log;client;gracefulShutdown=!0;constructor(e){Object.assign(this,e)}};var l=require("node:v8"),c=class{options;serializer=l.serialize;deserializer=l.deserialize;constructor(e){this.options=e instanceof a?e:new a(e)}async get(e){try{let t=this.generateKey(e),r=await this.options.client.getBuffer(t);if(!r)return;let i=this.deserializer(r);return this.debug("Get",t,i),i}catch(t){this.options.logger("Failed to fetch data."),this.options.logger(t);return}}async set(e,t,r,i){try{let o=this.generateKey(e),n=this.serializer(t);i?this.options.client.set(o,n,"PX",i):this.options.client.set(o,n),this.debug("Set",o,n)}catch(o){this.options.logger("Failed to store data."),this.options.logger(o)}}async remove(e){try{let t=this.generateKey(e);await this.options.client.del(t),this.debug("Remove",t,void 0)}catch(t){this.options.logger("Failed to remove data."),this.options.logger(t)}}clear(){return new Promise((e,t)=>{let r=this.options.client.scanStream({match:`${this.options.prefix}${this.options.prefixDelimiter}*`}),i=this.options.client.pipeline();r.on("data",o=>{if(o.length!==0)for(let n of o)i.del(n)}),r.on("end",()=>{i.exec(o=>{if(o)return this.options.logger("Failed to clear data."),this.options.logger(o),t(o);this.options.logger("Cache has been successfully cleared."),e()})})})}close(){}debug(e,t,r){this.options.debug&&this.options.logger(`${e} ${t}: ${JSON.stringify(r)}`)}generateKey(e){return`${this.options.prefix}:${e}`}};0&&(module.exports={RedisCacheAdapter});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/redisCacheAdapter.ts
var redisCacheAdapter_exports = {};
__export(redisCacheAdapter_exports, {
RedisCacheAdapter: () => RedisCacheAdapter
});
module.exports = __toCommonJS(redisCacheAdapter_exports);
// src/options.ts
var Options = class {
/**
* Debug mode. Defaults to `false`.
*/
debug = false;
/**
* The prefix for the cache keys. Defaults to `mikro`.
*/
prefix = "mikro";
/**
* The delimiter between the prefix and the cache key. Defaults to `:`.
*/
prefixDelimiter = ":";
/**
* Logger. Defaults to `console.log`.
*/
logger = console.log;
/**
* Redis client.
*/
client;
/**
* If you want to close the Redis connection by yourself, set it to `false`.
* Defaults to `true`.
*/
gracefulShutdown = true;
constructor(options) {
Object.assign(this, options);
}
};
// src/redisCacheAdapter.ts
var import_node_v8 = require("node:v8");
var RedisCacheAdapter = class {
options;
serializer = import_node_v8.serialize;
deserializer = import_node_v8.deserialize;
constructor(options) {
this.options = options instanceof Options ? options : new Options(options);
}
async get(name) {
try {
const key = this.generateKey(name);
const data = await this.options.client.getBuffer(key);
if (!data) {
return void 0;
}
const deserializedData = this.deserializer(data);
this.debug("Get", key, deserializedData);
return deserializedData;
} catch (error) {
this.options.logger("Failed to fetch data.");
this.options.logger(error);
return void 0;
}
}
async set(name, data, _origin, expiration) {
try {
const key = this.generateKey(name);
const serializedData = this.serializer(data);
if (expiration) {
this.options.client.set(key, serializedData, "PX", expiration);
} else {
this.options.client.set(key, serializedData);
}
this.debug("Set", key, serializedData);
} catch (error) {
this.options.logger("Failed to store data.");
this.options.logger(error);
}
}
async remove(name) {
try {
const key = this.generateKey(name);
await this.options.client.del(key);
this.debug("Remove", key, void 0);
} catch (error) {
this.options.logger("Failed to remove data.");
this.options.logger(error);
}
}
clear() {
return new Promise((resolve, reject) => {
const stream = this.options.client.scanStream({
match: `${this.options.prefix}${this.options.prefixDelimiter}*`
});
const pipeline = this.options.client.pipeline();
stream.on("data", (keys) => {
if (keys.length === 0) {
return;
}
for (const key of keys) {
pipeline.del(key);
}
});
stream.on("end", () => {
pipeline.exec((err) => {
if (err) {
this.options.logger("Failed to clear data.");
this.options.logger(err);
return reject(err);
}
this.options.logger("Cache has been successfully cleared.");
resolve();
});
});
});
}
close() {
}
debug(method, key, data) {
if (!this.options.debug) {
return;
}
this.options.logger(`${method} ${key}: ${JSON.stringify(data)}`);
}
generateKey(name) {
return `${this.options.prefix}:${name}`;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
RedisCacheAdapter
});

6

package.json
{
"name": "@javien/mikro-orm-redis-cache-adapter",
"license": "ISC",
"license": "MIT",
"description": "",
"version": "0.0.1",
"version": "0.0.2",
"author": "Javien Lee <kraccoon@dimipay.io> (https://github.com/SnowMarble/)",

@@ -13,3 +13,3 @@ "keywords": ["mikro-orm", "redis", "cache", "adapter"],

"check:apply": "biome check --apply src",
"build": "esbuild src/redisCacheAdapter.ts --bundle --platform=node --outdir=dist --minify"
"build": "rm -rf dist && esbuild src/redisCacheAdapter.ts --bundle --platform=node --outdir=dist& tsc --emitDeclarationOnly --outdir dist"
},

@@ -16,0 +16,0 @@ "devDependencies": {

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