axe-api 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/Handlers/Helpers.js +12 -0
- package/build/src/Middlewares/RateLimit/RedisAdaptor.d.ts +3 -0
- package/build/src/Middlewares/RateLimit/RedisAdaptor.js +16 -1
- package/build/src/Phases/GetCachePhase.js +3 -0
- package/build/src/Phases/Store/ResultPhase.js +1 -1
- package/build/src/Resolvers/ModelResolver.js +9 -0
- package/build/src/constants.js +3 -1
- package/package.json +7 -3
- package/build/dev-kit.d.ts +0 -1
- package/build/dev-kit.js +0 -16
|
@@ -338,6 +338,9 @@ const putCache = (context, data) => __awaiter(void 0, void 0, void 0, function*
|
|
|
338
338
|
}
|
|
339
339
|
// Getting the redis service
|
|
340
340
|
const redis = yield Services_1.IoCService.use("Redis");
|
|
341
|
+
if (!redis.isReady()) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
341
344
|
// Generating the cache key
|
|
342
345
|
const key = (0, exports.toCacheKey)(context);
|
|
343
346
|
// Setting the tags if the cache configuration of the model has been set as
|
|
@@ -357,12 +360,18 @@ const putCache = (context, data) => __awaiter(void 0, void 0, void 0, function*
|
|
|
357
360
|
exports.putCache = putCache;
|
|
358
361
|
const deleteCacheTagMembers = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
359
362
|
const redis = yield Services_1.IoCService.use("Redis");
|
|
363
|
+
if (!redis.isReady()) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
360
366
|
const members = yield redis.getTagMemebers(key);
|
|
361
367
|
yield redis.delete(members);
|
|
362
368
|
});
|
|
363
369
|
exports.deleteCacheTagMembers = deleteCacheTagMembers;
|
|
364
370
|
const cleanRelatedCachedObjectByModel = (model, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
365
371
|
const redis = yield Services_1.IoCService.use("Redis");
|
|
372
|
+
if (!redis.isReady()) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
366
375
|
const prefix = (0, exports.toCachePrefix)(config === null || config === void 0 ? void 0 : config.cachePrefix);
|
|
367
376
|
const tagPrefix = (config === null || config === void 0 ? void 0 : config.tagPrefix) ? config === null || config === void 0 ? void 0 : config.tagPrefix : "";
|
|
368
377
|
const modelName = model.name.toLowerCase();
|
|
@@ -376,6 +385,9 @@ const cleanRelatedCachedObjectByModel = (model, config) => __awaiter(void 0, voi
|
|
|
376
385
|
exports.cleanRelatedCachedObjectByModel = cleanRelatedCachedObjectByModel;
|
|
377
386
|
const clearCacheTags = (tag) => __awaiter(void 0, void 0, void 0, function* () {
|
|
378
387
|
const redis = yield Services_1.IoCService.use("Redis");
|
|
388
|
+
if (!redis.isReady()) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
379
391
|
const members = yield redis.getTagMemebers(tag);
|
|
380
392
|
if (members.length > 0) {
|
|
381
393
|
yield redis.delete(members);
|
|
@@ -4,7 +4,10 @@ type RedisClientOptions = Parameters<typeof createClient>[0];
|
|
|
4
4
|
declare class RedisAdaptor implements ICacheAdaptor {
|
|
5
5
|
private client;
|
|
6
6
|
private prefix;
|
|
7
|
+
private isConnected;
|
|
7
8
|
constructor(options: RedisClientOptions | undefined, prefix: string);
|
|
9
|
+
isReady(): boolean;
|
|
10
|
+
connect(): Promise<void>;
|
|
8
11
|
get(key: string): Promise<string | null>;
|
|
9
12
|
set(key: string, value: string, ttl: number): Promise<void>;
|
|
10
13
|
tags(keys: string[], value: string): Promise<void>;
|
|
@@ -10,11 +10,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const redis_1 = require("redis");
|
|
13
|
+
const Services_1 = require("../../Services");
|
|
13
14
|
class RedisAdaptor {
|
|
14
15
|
constructor(options, prefix) {
|
|
15
16
|
this.client = (0, redis_1.createClient)(options);
|
|
16
17
|
this.prefix = prefix;
|
|
17
|
-
this.
|
|
18
|
+
this.isConnected = false;
|
|
19
|
+
}
|
|
20
|
+
isReady() {
|
|
21
|
+
return this.isConnected;
|
|
22
|
+
}
|
|
23
|
+
connect() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
try {
|
|
26
|
+
yield this.client.connect();
|
|
27
|
+
this.isConnected = true;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
Services_1.LogService.error(`Redis Connection Error: ${error.message}`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
18
33
|
}
|
|
19
34
|
get(key) {
|
|
20
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -19,6 +19,9 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
19
19
|
if (config === null || config === void 0 ? void 0 : config.enable) {
|
|
20
20
|
// Getting the redis service
|
|
21
21
|
const redis = yield Services_1.IoCService.use("Redis");
|
|
22
|
+
if (!redis.isReady()) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
22
25
|
// Generating the cache key
|
|
23
26
|
const key = (0, Helpers_1.toCacheKey)(context);
|
|
24
27
|
// Try to fetch the value via Redis
|
|
@@ -15,7 +15,7 @@ exports.default = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
15
15
|
const { item, res, model, handlerType } = context;
|
|
16
16
|
// Deleting all cached result for the model
|
|
17
17
|
const config = model.getCacheConfiguration(handlerType);
|
|
18
|
-
if ((config === null || config === void 0 ? void 0 : config.invalidation) === Enums_1.CacheStrategies.TagBased) {
|
|
18
|
+
if ((config === null || config === void 0 ? void 0 : config.enable) && (config === null || config === void 0 ? void 0 : config.invalidation) === Enums_1.CacheStrategies.TagBased) {
|
|
19
19
|
(0, Helpers_1.cleanRelatedCachedObjectByModel)(model, config);
|
|
20
20
|
}
|
|
21
21
|
// Preparing the json response
|
|
@@ -49,6 +49,7 @@ class ModelResolver {
|
|
|
49
49
|
setCacheOptions(modelList) {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
51
|
const api = Services_1.APIService.getInstance();
|
|
52
|
+
let needRedisConnection = false;
|
|
52
53
|
// For each model should be analyzed
|
|
53
54
|
for (const model of modelList.get()) {
|
|
54
55
|
// For each cachable handler, developers are able to set a different
|
|
@@ -57,10 +58,18 @@ class ModelResolver {
|
|
|
57
58
|
// API configuration, version configuration and the handler type are in
|
|
58
59
|
// order. The following function gets the correct configuration
|
|
59
60
|
const configuration = (0, Helpers_1.getModelCacheConfiguration)(model, api.config.cache, this.version.config.cache, handler);
|
|
61
|
+
// We should try to connect to Redis
|
|
62
|
+
if (configuration.enable) {
|
|
63
|
+
needRedisConnection = true;
|
|
64
|
+
}
|
|
60
65
|
// We need to set this to use late in action
|
|
61
66
|
model.setCacheConfiguration(handler, configuration);
|
|
62
67
|
}
|
|
63
68
|
}
|
|
69
|
+
if (needRedisConnection) {
|
|
70
|
+
const redis = yield Services_1.IoCService.use("Redis");
|
|
71
|
+
redis.connect();
|
|
72
|
+
}
|
|
64
73
|
});
|
|
65
74
|
}
|
|
66
75
|
setModelRelations(modelList) {
|
package/build/src/constants.js
CHANGED
|
@@ -299,7 +299,9 @@ exports.DEFAULT_APP_CONFIG = {
|
|
|
299
299
|
},
|
|
300
300
|
},
|
|
301
301
|
errorHandler: ErrorHandler_1.default,
|
|
302
|
-
redis: {
|
|
302
|
+
redis: {
|
|
303
|
+
url: "redis://127.0.0.1:6379",
|
|
304
|
+
},
|
|
303
305
|
cache: Object.assign({}, exports.DEFAULT_CACHE_CONFIGURATION),
|
|
304
306
|
elasticSearch: {
|
|
305
307
|
node: "http://localhost:9200",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axe-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "AXE API is a simple tool to create Rest APIs quickly.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -52,7 +52,11 @@
|
|
|
52
52
|
"test:sqlite": "sh ./scripts/test-sqlite.sh",
|
|
53
53
|
"prettier:check": "prettier --check .",
|
|
54
54
|
"prettier:write": "prettier --write .",
|
|
55
|
-
"prepare": "husky install"
|
|
55
|
+
"prepare": "husky install",
|
|
56
|
+
"benchmark": "k6 run benchmark/run.js"
|
|
57
|
+
},
|
|
58
|
+
"engines" : {
|
|
59
|
+
"node" : ">=18.0.0"
|
|
56
60
|
},
|
|
57
61
|
"dependencies": {
|
|
58
62
|
"body-parser": "^1.20.2",
|
|
@@ -103,7 +107,7 @@
|
|
|
103
107
|
"nodemon": "^3.0.2",
|
|
104
108
|
"open-swagger-ui": "^1.2.0",
|
|
105
109
|
"pg": "^8.11.3",
|
|
106
|
-
"prettier": "^3.1.
|
|
110
|
+
"prettier": "^3.1.1",
|
|
107
111
|
"redis": "^4.6.11",
|
|
108
112
|
"set-value": ">=4.1.0",
|
|
109
113
|
"sqlite3": "^5.1.6",
|
package/build/dev-kit.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/dev-kit.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_color_log_1 = __importDefault(require("node-color-log"));
|
|
7
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const index_1 = require("./index");
|
|
10
|
-
node_color_log_1.default.bgColor("yellow").color("black").log("Axe API dev-kit (1.0.1)");
|
|
11
|
-
node_color_log_1.default
|
|
12
|
-
.color("blue")
|
|
13
|
-
.log("Docs: https://axe-api.com/contribution/fundamentals.html \n");
|
|
14
|
-
dotenv_1.default.config();
|
|
15
|
-
const server = new index_1.Server();
|
|
16
|
-
server.start(path_1.default.join(__dirname, "dev-kit"));
|