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

@amplication/plugin-cache-redis

Package Overview
Dependencies
Maintainers
8
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amplication/plugin-cache-redis - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

4

.amplicationrc.json

@@ -7,5 +7,5 @@ {

"max": 100,
"username": null,
"password": null
"username": "",
"password": ""
}
}

@@ -151,26 +151,36 @@ /******/ (() => { // webpackBootstrap

const cacheModuleInstantiation = () => {
return ast_types_1.builders.callExpression(ast_types_1.builders.memberExpression(ast_types_1.builders.identifier("CacheModule"), ast_types_1.builders.identifier("register")), [
return ast_types_1.builders.callExpression(ast_types_1.builders.memberExpression(ast_types_1.builders.identifier("CacheModule"), ast_types_1.builders.identifier("registerAsync")), [
ast_types_1.builders.objectExpression([
objProp("isGlobal", ast_types_1.builders.booleanLiteral(true)),
objProp("store", ast_types_1.builders.identifier("redisStore")),
objProp("host", envVar("REDIS_HOST")),
objProp("port", envVar("REDIS_PORT")),
objProp("username", envVar("REDIS_USERNAME")),
objProp("password", envVar("REDIS_PASSWORD")),
objProp("ttl", parseIntOr(envVar("REDIS_TTL"), "5")),
objProp("max", parseIntOr(envVar("REDIS_MAX_REQUESTS_CACHED"), "100"))
objProp("imports", ast_types_1.builders.arrayExpression([ast_types_1.builders.identifier("ConfigModule")])),
objProp("useFactory", useFactoryConfigFunc()),
objProp("inject", ast_types_1.builders.arrayExpression([ast_types_1.builders.identifier("ConfigService")]))
]),
]);
};
const parseIntOr = (val, defaultVal) => {
return ast_types_1.builders.callExpression(ast_types_1.builders.identifier("parseInt"), [
ast_types_1.builders.conditionalExpression(val, val, ast_types_1.builders.stringLiteral(defaultVal))
]);
const useFactoryConfigFunc = () => {
return ast_types_1.builders.arrowFunctionExpression([ast_types_1.builders.identifier("configService")], ast_types_1.builders.blockStatement([
configAssign("host", "REDIS_HOST"),
configAssign("port", "REDIS_PORT"),
configAssign("username", "REDIS_USERNAME"),
configAssign("password", "REDIS_PASSWORD"),
configAssign("ttl", "REDIS_TTL", ast_types_1.builders.literal(5)),
configAssign("max", "REDIS_MAX_REQUESTS_CACHED", ast_types_1.builders.literal(100)),
ast_types_1.builders.returnStatement(ast_types_1.builders.objectExpression([
objProp("store", ast_types_1.builders.identifier("redisStore")),
objProp("host", ast_types_1.builders.identifier("host")),
objProp("port", ast_types_1.builders.identifier("port")),
objProp("username", ast_types_1.builders.identifier("username")),
objProp("password", ast_types_1.builders.identifier("password")),
objProp("ttl", ast_types_1.builders.identifier("ttl")),
objProp("max", ast_types_1.builders.identifier("max"))
]))
]));
};
const configAssign = (name, key, ...others) => {
return ast_types_1.builders.variableDeclaration("const", [ast_types_1.builders.variableDeclarator(ast_types_1.builders.identifier(name), ast_types_1.builders.callExpression(ast_types_1.builders.memberExpression(ast_types_1.builders.identifier("configService"), ast_types_1.builders.identifier("get")), [ast_types_1.builders.stringLiteral(key), ...others]))]);
};
const objProp = (key, val) => {
return ast_types_1.builders.objectProperty(ast_types_1.builders.identifier(key), val);
};
const envVar = (variable) => {
return ast_types_1.builders.memberExpression(ast_types_1.builders.memberExpression(ast_types_1.builders.identifier("process"), ast_types_1.builders.identifier("env")), ast_types_1.builders.identifier(variable));
};
exports["default"] = RedisCachePlugin;

@@ -374,3 +384,3 @@

module.exports = JSON.parse('{"settings":{"host":"localhost","port":6379,"ttl":5,"max":100,"username":null,"password":null}}');
module.exports = JSON.parse('{"settings":{"host":"localhost","port":6379,"ttl":5,"max":100,"username":"","password":""}}');

@@ -382,3 +392,3 @@ /***/ }),

module.exports = JSON.parse('{"name":"@amplication/plugin-cache-redis","version":"0.0.1","description":"Use Redis as a Cache in services generated with Amplication","main":"dist/index.js","scripts":{"prepublishOnly":"npm run build","dev":"webpack --watch","build":"webpack","test":"jest","prebuild":"rimraf dist","format:write":"prettier --write \\"**/*.{js,ts}\\""},"author":"Demilade Sonuga","license":"Apache-2.0","devDependencies":{"@amplication/code-gen-types":"^2.0.5","@babel/parser":"^7.20.7","@babel/types":"^7.20.7","@jest/globals":"^29.6.2","@types/jest":"^29.5.3","@types/lodash":"^4.14.196","@typescript-eslint/eslint-plugin":"^5.33.0","@typescript-eslint/parser":"^5.33.0","copy-webpack-plugin":"^11.0.0","eslint":"^8.21.0","jest-mock-extended":"^3.0.1","lodash":"^4.17.21","prettier":"^2.8.7","recast":"^0.23.4","rimraf":"^4.4.1","ts-jest":"^29.1.1","ts-loader":"^9.4.2","typescript":"^4.9.3","webpack":"^5.76.0","webpack-cli":"^5.0.1","webpack-node-externals":"^3.0.0"},"jest":{"moduleFileExtensions":["js","json","ts"],"rootDir":"src/tests","testRegex":".*\\\\.spec\\\\.ts$","transform":{"^.+\\\\.(t|j)s$":"ts-jest"},"collectCoverageFrom":["**/*.(t|j)s"],"testEnvironment":"node"}}');
module.exports = JSON.parse('{"name":"@amplication/plugin-cache-redis","version":"1.0.0","description":"Use Redis as a Cache in services generated with Amplication","main":"dist/index.js","scripts":{"prepublishOnly":"npm run build","dev":"webpack --watch","build":"webpack","test":"jest","prebuild":"rimraf dist","format:write":"prettier --write \\"**/*.{js,ts}\\""},"author":"Demilade Sonuga","license":"Apache-2.0","devDependencies":{"@amplication/code-gen-types":"^2.0.5","@babel/parser":"^7.20.7","@babel/types":"^7.20.7","@jest/globals":"^29.6.2","@types/jest":"^29.5.3","@types/lodash":"^4.14.196","@typescript-eslint/eslint-plugin":"^5.33.0","@typescript-eslint/parser":"^5.33.0","copy-webpack-plugin":"^11.0.0","eslint":"^8.21.0","jest-mock-extended":"^3.0.1","lodash":"^4.17.21","prettier":"^2.8.7","recast":"^0.23.4","rimraf":"^4.4.1","ts-jest":"^29.1.1","ts-loader":"^9.4.2","typescript":"^4.9.3","webpack":"^5.76.0","webpack-cli":"^5.0.1","webpack-node-externals":"^3.0.0"},"jest":{"moduleFileExtensions":["js","json","ts"],"rootDir":"src/tests","testRegex":".*\\\\.spec\\\\.ts$","transform":{"^.+\\\\.(t|j)s$":"ts-jest"},"collectCoverageFrom":["**/*.(t|j)s"],"testEnvironment":"node"}}');

@@ -385,0 +395,0 @@ /***/ })

{
"name": "@amplication/plugin-cache-redis",
"version": "0.0.1",
"version": "1.0.0",
"description": "Use Redis as a Cache in services generated with Amplication",

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

@@ -124,3 +124,3 @@ import type {

builders.identifier("CacheModule"),
builders.identifier("register")
builders.identifier("registerAsync")
),

@@ -130,9 +130,5 @@ [

objProp("isGlobal", builders.booleanLiteral(true)),
objProp("store", builders.identifier("redisStore")),
objProp("host", envVar("REDIS_HOST")),
objProp("port", envVar("REDIS_PORT")),
objProp("username", envVar("REDIS_USERNAME")),
objProp("password", envVar("REDIS_PASSWORD")),
objProp("ttl", parseIntOr(envVar("REDIS_TTL"), "5")),
objProp("max", parseIntOr(envVar("REDIS_MAX_REQUESTS_CACHED"), "100"))
objProp("imports", builders.arrayExpression([builders.identifier("ConfigModule")])),
objProp("useFactory", useFactoryConfigFunc()),
objProp("inject", builders.arrayExpression([builders.identifier("ConfigService")]))
]),

@@ -143,15 +139,37 @@ ]

const parseIntOr = (val: namedTypes.MemberExpression, defaultVal: string) => {
return builders.callExpression(
builders.identifier("parseInt"),
[
builders.conditionalExpression(
val,
val,
builders.stringLiteral(defaultVal)
)
]
)
const useFactoryConfigFunc = (): namedTypes.ArrowFunctionExpression => {
return builders.arrowFunctionExpression([builders.identifier("configService")],
builders.blockStatement([
configAssign("host", "REDIS_HOST"),
configAssign("port", "REDIS_PORT"),
configAssign("username", "REDIS_USERNAME"),
configAssign("password", "REDIS_PASSWORD"),
configAssign("ttl", "REDIS_TTL", builders.literal(5)),
configAssign("max", "REDIS_MAX_REQUESTS_CACHED", builders.literal(100)),
builders.returnStatement(builders.objectExpression([
objProp("store", builders.identifier("redisStore")),
objProp("host", builders.identifier("host")),
objProp("port", builders.identifier("port")),
objProp("username", builders.identifier("username")),
objProp("password", builders.identifier("password")),
objProp("ttl", builders.identifier("ttl")),
objProp("max", builders.identifier("max"))
]))
]));
}
const configAssign = (
name: string,
key: string,
...others: any[]
): namedTypes.VariableDeclaration => {
return builders.variableDeclaration("const", [builders.variableDeclarator(
builders.identifier(name),
builders.callExpression(builders.memberExpression(
builders.identifier("configService"),
builders.identifier("get")
), [builders.stringLiteral(key), ...others])
)])
}
const objProp = (key: string, val: any): namedTypes.ObjectProperty => {

@@ -164,12 +182,2 @@ return builders.objectProperty(

const envVar = (variable: string): namedTypes.MemberExpression => {
return builders.memberExpression(
builders.memberExpression(
builders.identifier("process"),
builders.identifier("env")
),
builders.identifier(variable)
)
}
export default RedisCachePlugin;

@@ -52,11 +52,24 @@ import { CreateServerAppModuleParams, DsgContext } from "@amplication/code-gen-types";

let expectedModules = prettyCode(`
[CacheModule.register({
[CacheModule.registerAsync({
isGlobal: true,
store: redisStore,
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
username: process.env.REDIS_USERNAME,
password: process.env.REDIS_PASSWORD,
ttl: parseInt(process.env.REDIS_TTL ? process.env.REDIS_TTL : "5"),
max: parseInt(process.env.REDIS_MAX_REQUESTS_CACHED ? process.env.REDIS_MAX_REQUESTS_CACHED : "100")
imports: [ConfigModule],
useFactory: (configService) => {
const host = configService.get("REDIS_HOST");
const port = configService.get("REDIS_PORT");
const username = configService.get("REDIS_USERNAME");
const password = configService.get("REDIS_PASSWORD");
const ttl = configService.get("REDIS_TTL", 5);
const max = configService.get("REDIS_MAX_REQUESTS_CACHED", 100);
return {
store: redisStore,
host: host,
port: port,
username: username,
password: password,
ttl: ttl,
max: max
}
},
inject: [ConfigService]
})]`);

@@ -73,2 +86,2 @@ // Remove the trailing semi-colon from the end which is inserted

return recast.prettyPrint(utils.parse(code)).code
}
}

@@ -32,3 +32,5 @@ import { CreateServerDotEnvParams, DsgContext, VariableDictionary } from "@amplication/code-gen-types";

ttl: 10000,
max: 1000000
max: 1000000,
username: "name",
password: "password"
}

@@ -35,0 +37,0 @@ context.pluginInstallations[0].settings = userSpecifiedSettings;

@@ -6,4 +6,4 @@ export interface Settings {

max: number,
username?: string | null,
password?: string | null
username: string,
password: string
}

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