axe-api 1.3.0 → 1.3.1

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.
@@ -1,6 +1,5 @@
1
1
  import { AdaptorType } from "../../Types";
2
2
  import RedisAdaptor from "./RedisAdaptor";
3
3
  import MemoryAdaptor from "./MemoryAdaptor";
4
- import { RedisClientOptions } from "redis";
5
- declare const _default: (adaptor: AdaptorType, redisOptions: RedisClientOptions | undefined, prefix: string) => RedisAdaptor | MemoryAdaptor;
4
+ declare const _default: (adaptor: AdaptorType) => Promise<RedisAdaptor | MemoryAdaptor>;
6
5
  export default _default;
@@ -1,17 +1,26 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const RedisAdaptor_1 = __importDefault(require("./RedisAdaptor"));
7
15
  const MemoryAdaptor_1 = __importDefault(require("./MemoryAdaptor"));
8
- exports.default = (adaptor, redisOptions, prefix) => {
16
+ const Services_1 = require("../../Services");
17
+ exports.default = (adaptor) => __awaiter(void 0, void 0, void 0, function* () {
9
18
  switch (adaptor) {
10
19
  case "redis":
11
- return new RedisAdaptor_1.default(redisOptions, prefix);
20
+ return yield Services_1.IoCService.use("Redis");
12
21
  case "memory":
13
- return new MemoryAdaptor_1.default(prefix);
22
+ return new MemoryAdaptor_1.default();
14
23
  default:
15
24
  throw new Error(`Adaptor type is not found: ${adaptor}`);
16
25
  }
17
- };
26
+ });
@@ -1,8 +1,7 @@
1
1
  import { ICacheAdaptor } from "src/Interfaces";
2
2
  declare class MemoryAdaptor implements ICacheAdaptor {
3
3
  private client;
4
- private prefix;
5
- constructor(prefix: string);
4
+ constructor();
6
5
  get(key: string): Promise<string | null>;
7
6
  set(key: string, value: string, ttl: number): Promise<void>;
8
7
  decr(key: string, ttl: number): Promise<void>;
@@ -14,18 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const node_cache_1 = __importDefault(require("node-cache"));
16
16
  class MemoryAdaptor {
17
- constructor(prefix) {
17
+ constructor() {
18
18
  this.client = new node_cache_1.default();
19
- this.prefix = prefix;
20
19
  }
21
20
  get(key) {
22
21
  return __awaiter(this, void 0, void 0, function* () {
23
- return this.client.get(`${this.prefix}${key}`) || null;
22
+ return this.client.get(`${key}`) || null;
24
23
  });
25
24
  }
26
25
  set(key, value, ttl) {
27
26
  return __awaiter(this, void 0, void 0, function* () {
28
- this.client.set(`${this.prefix}${key}`, value, ttl);
27
+ this.client.set(`${key}`, value, ttl);
29
28
  });
30
29
  }
31
30
  decr(key, ttl) {
@@ -24,6 +24,7 @@ class RedisAdaptor {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  try {
26
26
  yield this.client.connect();
27
+ Services_1.LogService.info("Redis connection done!");
27
28
  this.isConnected = true;
28
29
  }
29
30
  catch (error) {
@@ -2,7 +2,7 @@
2
2
  /// <reference types="express" />
3
3
  import { IncomingMessage, ServerResponse } from "http";
4
4
  import { AxeConfig, IRateLimitOptions, IContext } from "../../Interfaces";
5
- export declare const setupRateLimitAdaptors: (config: AxeConfig) => void;
5
+ export declare const setupRateLimitAdaptors: (config: AxeConfig) => Promise<void>;
6
6
  /**
7
7
  * Add a rate limit with the `IRateLimitOptions`
8
8
  *
@@ -64,11 +64,11 @@ const getClientKeyByConfigurations = (req, config) => {
64
64
  }
65
65
  return `axe-api-rate-limit:${req.socket.remoteAddress || ""}`;
66
66
  };
67
- const setupRateLimitAdaptors = (config) => {
67
+ const setupRateLimitAdaptors = (config) => __awaiter(void 0, void 0, void 0, function* () {
68
68
  var _a;
69
69
  // Creating the correct adaptor by the configuration
70
- adaptor = (0, AdaptorFactory_1.default)(((_a = config.rateLimit) === null || _a === void 0 ? void 0 : _a.adaptor) || "memory", config.redis, "");
71
- };
70
+ adaptor = yield (0, AdaptorFactory_1.default)(((_a = config.rateLimit) === null || _a === void 0 ? void 0 : _a.adaptor) || "memory");
71
+ });
72
72
  exports.setupRateLimitAdaptors = setupRateLimitAdaptors;
73
73
  /**
74
74
  * Add a rate limit with the `IRateLimitOptions`
@@ -161,7 +161,7 @@ class Server {
161
161
  app.use(RateLimit_1.default);
162
162
  }
163
163
  server.listen(api.config.port);
164
- Services_1.LogService.info(`Axe API listens requests on http://localhost:${api.config.port}`);
164
+ Services_1.LogService.axe(`Axe API listens requests on http://localhost:${api.config.port}`);
165
165
  });
166
166
  }
167
167
  }
@@ -7,5 +7,6 @@ declare class LogService {
7
7
  static warn(message: string): void;
8
8
  static info(message: string): void;
9
9
  static debug(message: string): void;
10
+ static axe(message: string): void;
10
11
  }
11
12
  export default LogService;
@@ -6,6 +6,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const pino_1 = __importDefault(require("pino"));
7
7
  class LogService {
8
8
  static setInstance(options) {
9
+ var _a, _b, _c;
10
+ if (options) {
11
+ options.customLevels = Object.assign(Object.assign({}, options.customLevels), { axe: 100 });
12
+ if (options.transport) {
13
+ options.transport = Object.assign(Object.assign({}, options.transport), { options: Object.assign(Object.assign({}, (_a = options === null || options === void 0 ? void 0 : options.transport) === null || _a === void 0 ? void 0 : _a.options), { customLevels: [
14
+ "trace:10",
15
+ "debug:20",
16
+ "info:30",
17
+ "serious:35",
18
+ "warn:40",
19
+ "error:50",
20
+ "fatal:60",
21
+ ((_c = (_b = options === null || options === void 0 ? void 0 : options.transport) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.customLevels) || "",
22
+ `axe:100`,
23
+ ].join(",") }) });
24
+ }
25
+ }
9
26
  LogService.logger = (0, pino_1.default)(options);
10
27
  }
11
28
  static instance() {
@@ -23,5 +40,8 @@ class LogService {
23
40
  static debug(message) {
24
41
  LogService.logger.debug(message);
25
42
  }
43
+ static axe(message) {
44
+ LogService.logger.axe(message);
45
+ }
26
46
  }
27
47
  exports.default = LogService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axe-api",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
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",
@@ -92,7 +92,7 @@
92
92
  "eslint-plugin-import": "^2.29.1",
93
93
  "eslint-plugin-node": "^11.1.0",
94
94
  "eslint-plugin-promise": "^6.1.1",
95
- "eslint-plugin-unicorn": "^51.0.1",
95
+ "eslint-plugin-unicorn": "^52.0.0",
96
96
  "eslint-watch": "^8.0.0",
97
97
  "glob": "^10.3.10",
98
98
  "husky": "^9.0.11",