axe-api 1.7.1 → 2.0.0-alfa-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.
package/build/index.d.ts CHANGED
@@ -5,7 +5,10 @@ import RedisAdaptor from "./src/Middlewares/RateLimit/RedisAdaptor";
5
5
  import { DEFAULT_HANDLERS, DEFAULT_VERSION_CONFIG } from "./src/constants";
6
6
  import { IoCService, allow, deny, App, AxeRequest, AxeResponse } from "./src/Services";
7
7
  import { rateLimit, createRateLimitter } from "./src/Middlewares/RateLimit";
8
+ import { generateTypes } from "./src/generator";
8
9
  export * from "./src/Enums";
9
10
  export * from "./src/Interfaces";
10
11
  export * from "./src/Types";
11
- export { App, AxeRequest, AxeResponse, Server, Model, ApiError, RedisAdaptor, DEFAULT_HANDLERS, DEFAULT_VERSION_CONFIG, IoCService, allow, deny, rateLimit, createRateLimitter, };
12
+ export * from "./src/definers";
13
+ export * from "./src/newTypes";
14
+ export { App, AxeRequest, AxeResponse, Server, Model, ApiError, RedisAdaptor, DEFAULT_HANDLERS, DEFAULT_VERSION_CONFIG, IoCService, allow, deny, rateLimit, createRateLimitter, generateTypes, };
package/build/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.createRateLimitter = exports.rateLimit = exports.deny = exports.allow = exports.IoCService = exports.DEFAULT_VERSION_CONFIG = exports.DEFAULT_HANDLERS = exports.RedisAdaptor = exports.ApiError = exports.Model = exports.Server = exports.AxeResponse = exports.AxeRequest = exports.App = void 0;
20
+ exports.generateTypes = exports.createRateLimitter = exports.rateLimit = exports.deny = exports.allow = exports.IoCService = exports.DEFAULT_VERSION_CONFIG = exports.DEFAULT_HANDLERS = exports.RedisAdaptor = exports.ApiError = exports.Model = exports.Server = exports.AxeResponse = exports.AxeRequest = exports.App = void 0;
21
21
  const Server_1 = __importDefault(require("./src/Server"));
22
22
  exports.Server = Server_1.default;
23
23
  const Model_1 = __importDefault(require("./src/Model"));
@@ -39,6 +39,10 @@ Object.defineProperty(exports, "AxeResponse", { enumerable: true, get: function
39
39
  const RateLimit_1 = require("./src/Middlewares/RateLimit");
40
40
  Object.defineProperty(exports, "rateLimit", { enumerable: true, get: function () { return RateLimit_1.rateLimit; } });
41
41
  Object.defineProperty(exports, "createRateLimitter", { enumerable: true, get: function () { return RateLimit_1.createRateLimitter; } });
42
+ const generator_1 = require("./src/generator");
43
+ Object.defineProperty(exports, "generateTypes", { enumerable: true, get: function () { return generator_1.generateTypes; } });
42
44
  __exportStar(require("./src/Enums"), exports);
43
45
  __exportStar(require("./src/Interfaces"), exports);
44
46
  __exportStar(require("./src/Types"), exports);
47
+ __exportStar(require("./src/definers"), exports);
48
+ __exportStar(require("./src/newTypes"), exports);
@@ -74,7 +74,7 @@ exports.default = (request, response, next) => __awaiter(void 0, void 0, void 0,
74
74
  // Rollback transaction
75
75
  if (match.hasTransaction && trx) {
76
76
  Services_1.LogService.info("\t🛢 DBTransaction:rollback()");
77
- trx.rollback();
77
+ yield trx.rollback();
78
78
  }
79
79
  if (error.type === "ApiError") {
80
80
  const apiError = error;
@@ -94,7 +94,7 @@ exports.default = (request, response, next) => __awaiter(void 0, void 0, void 0,
94
94
  if (context.res.statusCode() >= 400 && context.res.statusCode() < 599) {
95
95
  if (match.hasTransaction && trx) {
96
96
  Services_1.LogService.info("\t🛢 DBTransaction:rollback()");
97
- trx.rollback();
97
+ yield trx.rollback();
98
98
  }
99
99
  Services_1.LogService.debug(`\tResponse ${context.res.statusCode()}`);
100
100
  break;
@@ -102,7 +102,7 @@ exports.default = (request, response, next) => __awaiter(void 0, void 0, void 0,
102
102
  // We should commit the transaction if there is any
103
103
  if (match.hasTransaction && trx) {
104
104
  Services_1.LogService.info("\t🛢 DBTransaction:commit()");
105
- trx.commit();
105
+ yield trx.commit();
106
106
  }
107
107
  Services_1.LogService.debug(`\t🟢 Response ${context.res.statusCode()}`);
108
108
  // We should brake the for-loop
@@ -24,6 +24,9 @@ class RedisAdaptor {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  try {
26
26
  yield this.client.connect();
27
+ this.client.on("error", (err) => {
28
+ Services_1.LogService.error(`Redis Client Error: ${err.message}`);
29
+ });
27
30
  Services_1.LogService.info("Redis connection done!");
28
31
  this.isConnected = true;
29
32
  }
@@ -267,6 +267,7 @@ declare class Model {
267
267
  * @tutorial https://axe-api.com/reference/model-get-search-query.html
268
268
  */
269
269
  getSearchQuery(params: IElasticSearchParameters): any;
270
+ query(): void;
270
271
  private hasStringValue;
271
272
  }
272
273
  export default Model;
@@ -429,6 +429,7 @@ class Model {
429
429
  ],
430
430
  };
431
431
  }
432
+ query() { }
432
433
  hasStringValue() {
433
434
  const tester = this.validations;
434
435
  let status = false;
@@ -79,6 +79,7 @@ exports.DEFAULT_METHODS_OF_MODELS = [
79
79
  "cache",
80
80
  "search",
81
81
  "getSearchQuery",
82
+ "query",
82
83
  ];
83
84
  exports.API_ROUTE_TEMPLATES = {
84
85
  [Enums_1.HandlerTypes.INSERT]: (prefix, parentUrl, resource) => `/${prefix}/${parentUrl}${resource}`,
@@ -0,0 +1,3 @@
1
+ import { useResource } from "./useResource";
2
+ import { useInsertHandler } from "./useInsertHandler";
3
+ export { useResource, useInsertHandler };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useInsertHandler = exports.useResource = void 0;
4
+ const useResource_1 = require("./useResource");
5
+ Object.defineProperty(exports, "useResource", { enumerable: true, get: function () { return useResource_1.useResource; } });
6
+ const useInsertHandler_1 = require("./useInsertHandler");
7
+ Object.defineProperty(exports, "useInsertHandler", { enumerable: true, get: function () { return useInsertHandler_1.useInsertHandler; } });
@@ -0,0 +1,6 @@
1
+ import { Resource } from "./useResource";
2
+ export declare const useInsertHandler: <Model>(resource: Resource<Model>) => InserHandler<Model>;
3
+ type InserHandler<T> = {
4
+ fillable: (columns: Array<keyof T>) => InserHandler<T>;
5
+ };
6
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useInsertHandler = void 0;
4
+ const useInsertHandler = (resource) => {
5
+ return {
6
+ fillable(columns) {
7
+ resource.config.fillables = columns;
8
+ return this;
9
+ },
10
+ };
11
+ };
12
+ exports.useInsertHandler = useInsertHandler;
@@ -0,0 +1,20 @@
1
+ export declare const useResource: <TSchema extends {
2
+ table: string;
3
+ primaryKey: string;
4
+ model: any;
5
+ columns: readonly string[];
6
+ }>(schema: TSchema) => Resource<ExtractModel<TSchema>>;
7
+ export type ExtractModel<T> = T extends {
8
+ model: infer M;
9
+ } ? M : never;
10
+ export type ResourceConfig<T> = {
11
+ tableName: string;
12
+ columns: string[];
13
+ primaryKey: keyof T;
14
+ fillables: Array<keyof T>;
15
+ };
16
+ export type Resource<T> = {
17
+ config: ResourceConfig<T>;
18
+ primaryKey: (column: keyof T) => void;
19
+ bind: () => void;
20
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useResource = void 0;
4
+ const useResource = (schema) => {
5
+ const config = {
6
+ tableName: schema.table,
7
+ primaryKey: schema.primaryKey,
8
+ columns: schema.columns,
9
+ fillables: [],
10
+ };
11
+ return {
12
+ config,
13
+ primaryKey(column) {
14
+ config.primaryKey = column;
15
+ },
16
+ bind: () => { },
17
+ };
18
+ };
19
+ exports.useResource = useResource;
@@ -0,0 +1,2 @@
1
+ import { IModelService } from "../Interfaces";
2
+ export declare const generateTable: (model: IModelService) => Promise<string>;
@@ -0,0 +1,24 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.generateTable = void 0;
13
+ const shared_1 = require("./shared");
14
+ const toColumnTypes = (columnNames) => {
15
+ return columnNames.map((name) => `'${name}'`).join(" | ");
16
+ };
17
+ const generateTable = (model) => __awaiter(void 0, void 0, void 0, function* () {
18
+ const tableName = (0, shared_1.toTableName)(model.instance.table);
19
+ const columnTypes = toColumnTypes(model.columnNames);
20
+ return `export namespace ${(0, shared_1.toTableName)(tableName)} {
21
+ export type Columns = ${columnTypes};
22
+ }`;
23
+ });
24
+ exports.generateTable = generateTable;
@@ -0,0 +1 @@
1
+ export declare const generateTypes: () => Promise<void>;
@@ -0,0 +1,32 @@
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
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.generateTypes = void 0;
16
+ const Services_1 = require("../Services");
17
+ const generateTable_1 = require("./generateTable");
18
+ const path_1 = __importDefault(require("path"));
19
+ const fs_1 = __importDefault(require("fs"));
20
+ const generateTypes = () => __awaiter(void 0, void 0, void 0, function* () {
21
+ const api = Services_1.APIService.getInstance();
22
+ const tables = [];
23
+ for (const version of api.versions) {
24
+ for (const model of version.modelList.get()) {
25
+ tables.push(yield (0, generateTable_1.generateTable)(model));
26
+ }
27
+ }
28
+ const content = tables.join("\\");
29
+ const filepath = path_1.default.join(process.cwd(), "app", "generated-types.ts");
30
+ fs_1.default.writeFileSync(filepath, content);
31
+ });
32
+ exports.generateTypes = generateTypes;
@@ -0,0 +1 @@
1
+ export declare const toTableName: (tableName: string) => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toTableName = void 0;
4
+ const toTableName = (tableName) => {
5
+ return tableName;
6
+ };
7
+ exports.toTableName = toTableName;
@@ -0,0 +1,6 @@
1
+ export type NewHandlerTypes = "store" | "paginate" | "show" | "update" | "destroy" | "force_delete" | "patch" | "all" | "search";
2
+ export type Resource<T> = {
3
+ table: string;
4
+ primaryKey: keyof T;
5
+ columns: Array<keyof T>;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axe-api",
3
- "version": "1.7.1",
3
+ "version": "2.0.0-alfa-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",
@@ -46,31 +46,18 @@
46
46
  "scripts": {
47
47
  "build": "rm -rf build && tsc && rm -rf build/dev-kit",
48
48
  "build:watch": "tsc -w",
49
- "dev-kit": "tsx watch dev-kit.ts",
50
- "dev-kit:install": "node ./scripts/dev-kit-install.js",
51
- "dev-kit:remove": "node ./scripts/dev-kit-remove.js",
52
- "test": "jest --runInBand",
49
+ "test": "vitest run",
53
50
  "test:all": "npm run lint && npm run prettier:check && npm run test && npm run test:sqlite",
54
- "test:dev": "jest --watch",
51
+ "test:dev": "vitest",
55
52
  "lint": "eslint --max-warnings=0 .",
56
53
  "lint:watch": "esw --watch --color",
57
- "test:postgres11": "sh ./scripts/test-postgres11.sh",
58
- "test:postgres12": "sh ./scripts/test-postgres12.sh",
59
- "test:postgres13": "sh ./scripts/test-postgres13.sh",
60
- "test:postgres14": "sh ./scripts/test-postgres14.sh",
61
- "test:postgres15": "sh ./scripts/test-postgres15.sh",
62
- "test:cockroach": "sh ./scripts/test-cockroach.sh",
63
- "test:mysql57": "sh ./scripts/test-mysql57.sh",
64
- "test:mysql8": "sh ./scripts/test-mysql8.sh",
65
- "test:mariadb": "sh ./scripts/test-mariadb.sh",
66
- "test:sqlite": "sh ./scripts/test-sqlite.sh",
67
54
  "prettier:check": "prettier --check .",
68
55
  "prettier:write": "prettier --write .",
69
56
  "prepare": "husky",
70
57
  "benchmark": "k6 run benchmark/run.js"
71
58
  },
72
59
  "engines": {
73
- "node": ">=18.0.0"
60
+ "node": ">=20.0.0"
74
61
  },
75
62
  "dependencies": {
76
63
  "body-parser": "^2.2.0",
@@ -105,7 +92,6 @@
105
92
  "@types/validatorjs": "^3.15.5",
106
93
  "@typescript-eslint/eslint-plugin": "^7.18.0",
107
94
  "@typescript-eslint/parser": "^7.18.0",
108
- "babel-jest": "^30.0.0",
109
95
  "cors": "^2.8.5",
110
96
  "eslint": "^8.57.1",
111
97
  "eslint-config-standard": "^17.1.0",
@@ -116,7 +102,6 @@
116
102
  "eslint-watch": "^8.0.0",
117
103
  "glob": "^11.0.3",
118
104
  "husky": "^9.1.7",
119
- "jest": "^30.0.0",
120
105
  "lint-staged": "^16.1.0",
121
106
  "multer": "^2.0.1",
122
107
  "mysql": "^2.18.1",
@@ -131,7 +116,8 @@
131
116
  "sqlite3": "^5.1.7",
132
117
  "ts-node": "^10.9.2",
133
118
  "tsx": "^4.20.3",
134
- "typescript": "^5.8.3"
119
+ "typescript": "^5.8.3",
120
+ "vitest": "^3.2.3"
135
121
  },
136
122
  "lint-staged": {
137
123
  "**/*": "prettier --write --ignore-unknown"
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Özgür Adem Işıklı <i.ozguradem@gmail.com>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/readme.md DELETED
@@ -1,54 +0,0 @@
1
- <h1 align="center">
2
- <br>
3
- <a href="https://axe-api.com/">
4
- <img src="https://axe-api.com/viking.png" alt="Markdownify" width="200">
5
- </a>
6
- <br>
7
- Axe API
8
- <br>
9
- <a href="https://badge.fury.io/js/axe-api">
10
- <img src="https://badge.fury.io/js/axe-api.svg" alt="npm version" height="18">
11
- </a>
12
- <a href="https://github.com/axe-api/axe-api/actions/workflows/npm-release-publish.yml" target="_blank">
13
- <img src="https://github.com/axe-api/axe-api/actions/workflows/npm-release-publish.yml/badge.svg?branch=master">
14
- </a>
15
- <a href="https://sonarcloud.io/dashboard?id=axe-api_axe-api" target="_blank">
16
- <img src="https://sonarcloud.io/api/project_badges/measure?project=axe-api_axe-api&metric=alert_status">
17
- </a>
18
- <a href="https://github.com/axe-api/axe-api/issues" target="_blank">
19
- <img src="https://img.shields.io/github/issues/axe-api/axe-api.svg">
20
- </a>
21
- <a href="https://opensource.org/licenses/MIT" target="_blank">
22
- <img src="https://img.shields.io/badge/license-MIT-blue.svg">
23
- </a>
24
- </h1>
25
-
26
- **Axe API** is a **TypeScript-based** **Node.js** framework designed to eliminate the need for repetitive tasks associated with common elements while allowing developers to focus on custom logic.
27
-
28
- It offers a comprehensive structure for your API, including numerous features and best practices that will save you time.
29
-
30
- ## 🎥 Video Introduction
31
-
32
- <div style="display: flex; justify-content: center;">
33
-
34
- <a href="https://www.youtube.com/watch?v=3p4jggsNrJA" target="_blank">
35
- <img src="https://raw.githubusercontent.com/axe-api/axe-api/master/youtube.png" />
36
- </a>
37
-
38
- </div>
39
-
40
- ## 📚 Documentation
41
-
42
- Axe API has great documentation. Please [check it out in here](https://axe-api.com/).
43
-
44
- ## 👥 Contributors
45
-
46
- <a href="https://github.com/axe-api/axe-api/graphs/contributors">
47
- <img src="https://contrib.rocks/image?repo=axe-api/axe-api" />
48
- </a>
49
-
50
- Made with [contrib.rocks](https://contrib.rocks).
51
-
52
- ## 📜 License
53
-
54
- [MIT License](LICENSE)