axe-api 1.2.0 → 1.3.1-beta-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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
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 dotenv_1 = __importDefault(require("dotenv"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const index_1 = require("./index");
9
+ console.log("Axe API dev-kit (1.0.1)");
10
+ dotenv_1.default.config();
11
+ const server = new index_1.Server();
12
+ server.start(path_1.default.join(__dirname, "dev-kit"));
@@ -55,8 +55,8 @@ class RouterBuilder {
55
55
  }
56
56
  });
57
57
  }
58
- createRouteByModel(model, parentPairs = [], urlPrefix = "", parentModel = null, relation = null, allowRecursive = true) {
59
- return __awaiter(this, void 0, void 0, function* () {
58
+ createRouteByModel(model_1) {
59
+ return __awaiter(this, arguments, void 0, function* (model, parentPairs = [], urlPrefix = "", parentModel = null, relation = null, allowRecursive = true) {
60
60
  if (model.instance.ignore) {
61
61
  return;
62
62
  }
@@ -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`
@@ -1,4 +1,4 @@
1
1
  declare const _default: {
2
- FetchPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ FetchPhase: (context: import("index").IContext) => Promise<void>;
3
3
  };
4
4
  export default _default;
@@ -1,7 +1,7 @@
1
1
  declare const _default: {
2
- ActionPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
3
- PreparePhase: (context: import("../../Interfaces").IContext) => Promise<void>;
4
- QueryPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
5
- ResponsePhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ ActionPhase: (context: import("index").IContext) => Promise<void>;
3
+ PreparePhase: (context: import("index").IContext) => Promise<void>;
4
+ QueryPhase: (context: import("index").IContext) => Promise<void>;
5
+ ResponsePhase: (context: import("index").IContext) => Promise<void>;
6
6
  };
7
7
  export default _default;
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
- ActionPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
3
- PreparePhase: (context: import("../../Interfaces").IContext) => Promise<void>;
4
- QueryPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ ActionPhase: (context: import("index").IContext) => Promise<void>;
3
+ PreparePhase: (context: import("index").IContext) => Promise<void>;
4
+ QueryPhase: (context: import("index").IContext) => Promise<void>;
5
5
  };
6
6
  export default _default;
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
- RelationalPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
3
- ResultPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
4
- SerializePhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ RelationalPhase: (context: import("index").IContext) => Promise<void>;
3
+ ResultPhase: (context: import("index").IContext) => Promise<void>;
4
+ SerializePhase: (context: import("index").IContext) => Promise<void>;
5
5
  };
6
6
  export default _default;
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- PreparePhase: (context: import("../../Interfaces").IContext) => Promise<void>;
3
- FetchPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ PreparePhase: (context: import("index").IContext) => Promise<void>;
3
+ FetchPhase: (context: import("index").IContext) => Promise<void>;
4
4
  };
5
5
  export default _default;
@@ -1,4 +1,4 @@
1
1
  declare const _default: {
2
- PrepareActionPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ PrepareActionPhase: (context: import("index").IContext) => Promise<void>;
3
3
  };
4
4
  export default _default;
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- PreparePhase: (context: import("../../Interfaces").IContext) => Promise<void>;
3
- FetchPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ PreparePhase: (context: import("index").IContext) => Promise<void>;
3
+ FetchPhase: (context: import("index").IContext) => Promise<void>;
4
4
  };
5
5
  export default _default;
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- PreparePhase: (context: import("../../Interfaces").IContext) => Promise<void>;
3
- FetchPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ PreparePhase: (context: import("index").IContext) => Promise<void>;
3
+ FetchPhase: (context: import("index").IContext) => Promise<void>;
4
4
  };
5
5
  export default _default;
@@ -1,8 +1,8 @@
1
1
  declare const _default: {
2
- RelationalPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
3
- ResultPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
4
- SerializePhase: (context: import("../../Interfaces").IContext) => Promise<void>;
5
- PrepareGetPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
6
- GetPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ RelationalPhase: (context: import("index").IContext) => Promise<void>;
3
+ ResultPhase: (context: import("index").IContext) => Promise<void>;
4
+ SerializePhase: (context: import("index").IContext) => Promise<void>;
5
+ PrepareGetPhase: (context: import("index").IContext) => Promise<void>;
6
+ GetPhase: (context: import("index").IContext) => Promise<void>;
7
7
  };
8
8
  export default _default;
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
- PreparePhase: (context: import("../../Interfaces").IContext) => Promise<void>;
3
- ActionPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
4
- ResultPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ PreparePhase: (context: import("index").IContext) => Promise<void>;
3
+ ActionPhase: (context: import("index").IContext) => Promise<void>;
4
+ ResultPhase: (context: import("index").IContext) => Promise<void>;
5
5
  };
6
6
  export default _default;
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- ActionPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
3
- PrepareActionPhase: (context: import("../../Interfaces").IContext) => Promise<void>;
2
+ ActionPhase: (context: import("index").IContext) => Promise<void>;
3
+ PrepareActionPhase: (context: import("index").IContext) => Promise<void>;
4
4
  };
5
5
  export default _default;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -143,9 +166,29 @@ class ModelResolver {
143
166
  if (!currentModel) {
144
167
  throw new AxeError_1.default(Enums_1.AxeErrorCode.UNDEFINED_HOOK_MODEL_RELATION, `Undefined model relation: ${subfolderPath}`);
145
168
  }
169
+ // Loading hooks via index.ts if there is any
170
+ const indexFilePath = path_1.default.join(subfolderPath, "index.ts");
171
+ if (fs_1.default.existsSync(indexFilePath)) {
172
+ // Importing the file
173
+ const content = yield Promise.resolve(`${indexFilePath}`).then(s => __importStar(require(s)));
174
+ const keys = Object.keys(content);
175
+ for (const key of keys) {
176
+ // The exported function should be a hook function
177
+ if (hookList.includes(key)) {
178
+ currentModel.setExtensions(hookType, key, content[key]);
179
+ }
180
+ else {
181
+ Services_1.LogService.warn(`Invalid ${hookType} function: "${key}()" in the index.ts: "${indexFilePath}"`);
182
+ }
183
+ }
184
+ }
146
185
  // Loading all hooks files in the subfolder
147
186
  const hooks = yield fileResolver.resolveContent(subfolderPath);
148
187
  for (const hookName in hooks) {
188
+ // We can ignore the index.ts
189
+ if (hookName === "index") {
190
+ continue;
191
+ }
149
192
  // If we have an acceptable hook
150
193
  if (hookList.includes(hookName)) {
151
194
  // We bind the hook with the model
@@ -138,8 +138,8 @@ class Server {
138
138
  });
139
139
  }
140
140
  listen() {
141
- var _a;
142
141
  return __awaiter(this, void 0, void 0, function* () {
142
+ var _a;
143
143
  const app = yield Services_1.IoCService.use("App");
144
144
  const api = Services_1.APIService.getInstance();
145
145
  // Adding the default handler for auto-created routes
@@ -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
  }
@@ -109,8 +109,8 @@ class AxeRequest {
109
109
  * @returns
110
110
  */
111
111
  files(options) {
112
- var _a, _b;
113
112
  return __awaiter(this, void 0, void 0, function* () {
113
+ var _a, _b;
114
114
  if (!((_a = this.header("content-type")) === null || _a === void 0 ? void 0 : _a.includes("multipart/form-data"))) {
115
115
  LogService_1.default.warn(`Content-type must be 'multipart/form-data'.`);
116
116
  throw new Error(`Content-type must be 'multipart/form-data'.`);
@@ -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;
@@ -48,9 +48,15 @@ class ModelService {
48
48
  this.children = [];
49
49
  }
50
50
  setHooks(hookFunctionType, data) {
51
+ if (this.hooks[hookFunctionType]) {
52
+ throw new Error(`You can define only one hook function: ${this.name}.${hookFunctionType}`);
53
+ }
51
54
  this.hooks[hookFunctionType] = data;
52
55
  }
53
56
  setEvents(hookFunctionType, data) {
57
+ if (this.events[hookFunctionType]) {
58
+ throw new Error(`You can define only one event function: ${this.name}.${hookFunctionType}`);
59
+ }
54
60
  this.events[hookFunctionType] = data;
55
61
  }
56
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axe-api",
3
- "version": "1.2.0",
3
+ "version": "1.3.1-beta-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",
@@ -67,7 +67,7 @@
67
67
  "knex-schema-inspector": "^3.1.0",
68
68
  "nanoid": "^3.3.7",
69
69
  "pino": "^8.18.0",
70
- "pino-pretty": "^10.3.1",
70
+ "pino-pretty": "^11.0.0",
71
71
  "pluralize": "^8.0.0",
72
72
  "validatorjs": "^3.22.1"
73
73
  },
@@ -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",
@@ -101,7 +101,6 @@
101
101
  "multer": "^1.4.5-lts.1",
102
102
  "mysql": "^2.18.1",
103
103
  "node-cache": "^5.1.2",
104
- "node-color-log": "^11.0.2",
105
104
  "nodemon": "^3.0.3",
106
105
  "pg": "^8.11.3",
107
106
  "prettier": "^3.2.5",