@expressots/core 2.13.0 → 2.14.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/lib/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
 
2
2
 
3
+ ## [2.14.1](https://github.com/expressots/expressots/compare/2.14.0...2.14.1) (2024-07-04)
4
+
5
+
6
+ ### Code Refactoring
7
+
8
+ * add tests for in memory db ([6914f15](https://github.com/expressots/expressots/commit/6914f156b1fae0b09ba2926e964dc7376a47b67f))
9
+ * in memory db internal provider ([168547b](https://github.com/expressots/expressots/commit/168547b79d1b1e72b9ffdc06ec1bd5f7bebae150))
10
+ * remove inversify binding dependency ([593620c](https://github.com/expressots/expressots/commit/593620c10c3bce3c4177e92ba75a74bb45a0c789))
11
+
12
+
13
+ ### Tests
14
+
15
+ * increase code coverage ([ae71339](https://github.com/expressots/expressots/commit/ae713397c8f85a49b746cfb2a26c8b83a0e2727f))
16
+
17
+ ## [2.14.0](https://github.com/expressots/expressots/compare/2.13.0...2.14.0) (2024-07-04)
18
+
19
+
20
+ ### Features
21
+
22
+ * bump @types/node from 20.12.7 to 20.14.9 ([ca36368](https://github.com/expressots/expressots/commit/ca3636841c54ff43968e40f8005b35a262920d50))
23
+ * bump @typescript-eslint/eslint-plugin from 7.6.0 to 7.15.0 ([3255f6a](https://github.com/expressots/expressots/commit/3255f6ae16279afa35f49585c8f223f2e88c4de9))
24
+ * bump @typescript-eslint/parser from 7.6.0 to 7.15.0 ([3ac1c8c](https://github.com/expressots/expressots/commit/3ac1c8c478eb2695062ff590ef0773d276eeebaf))
25
+ * bump prettier from 3.3.1 to 3.3.2 ([56c3299](https://github.com/expressots/expressots/commit/56c329900954002d58feb0572ae6dd8f3c12b0ab))
26
+ * bump release-it and @release-it/conventional-changelog ([c68612f](https://github.com/expressots/expressots/commit/c68612fffbe1afe5586127a74a85607de7a63cb0))
27
+ * bump typescript from 5.2.2 to 5.5.3 ([ee338de](https://github.com/expressots/expressots/commit/ee338de2e7c8da77f5bd39afc42a438be708744a))
28
+ * bump vite from 5.2.8 to 5.3.3 ([0299602](https://github.com/expressots/expressots/commit/02996021fec87041dfbeee187a8f77bf3aadcd13))
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * engine bump & husky init script ([57d0549](https://github.com/expressots/expressots/commit/57d0549e4e93dd18b94bb182c29ad487963d0131))
34
+
35
+
36
+ ### Code Refactoring
37
+
38
+ * [@provide](https://github.com/provide) is available through core ([6c315e4](https://github.com/expressots/expressots/commit/6c315e4ca68eb079f09d6e4a5b0f689f9bbf810c))
39
+ * add test to validate the decorator [@provide](https://github.com/provide) ([e4981c4](https://github.com/expressots/expressots/commit/e4981c44e63197cf812f4d4f3fb010bc7f0c2e4a))
40
+
3
41
  ## [2.13.0](https://github.com/expressots/expressots/compare/2.12.0...2.13.0) (2024-06-11)
4
42
 
5
43
 
@@ -622,4 +660,4 @@
622
660
 
623
661
  ### Bug Fixes
624
662
 
625
- - fix pipeline for tag name ([b9ec52d](https://github.com/expressots/expressots/commit/b9ec52dc065763185f69364d8f083b1a95fa37e0))
663
+ - fix pipeline for tag name ([b9ec52d](https://github.com/expressots/expressots/commit/b9ec52dc065763185f69364d8f083b1a95fa37e0))
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packageResolver = void 0;
3
+ exports.packageResolver = packageResolver;
4
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
5
  const logger_provider_1 = require("../provider/logger/logger.provider");
6
6
  /**
@@ -32,4 +32,3 @@ function packageResolver(packageName, ...options) {
32
32
  logger.warn(`Package [${packageName}] not installed. Please install it using your package manager.`, "package-resolver");
33
33
  }
34
34
  }
35
- exports.packageResolver = packageResolver;
@@ -1,9 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.provideTransient = exports.provideSingleton = void 0;
3
+ exports.provideTransient = exports.provideSingleton = exports.provide = void 0;
4
4
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
5
5
  /* eslint-disable @typescript-eslint/no-explicit-any */
6
6
  const inversify_binding_decorators_1 = require("inversify-binding-decorators");
7
+ /**
8
+ * Provides a binding for the given identifier.
9
+ *
10
+ * @param identifier - The identifier (e.g., symbol, string, class) for the dependency being registered.
11
+ * @returns A fluent interface for further configuring the binding.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * @provide(ServiceIdentifier)
16
+ * class MyService {}
17
+ * ```
18
+ */
19
+ const provide = (identifier) => {
20
+ return (0, inversify_binding_decorators_1.fluentProvide)(identifier).done();
21
+ };
22
+ exports.provide = provide;
7
23
  /**
8
24
  * Provides a singleton binding for the given identifier.
9
25
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.middlewareResolver = void 0;
3
+ exports.middlewareResolver = middlewareResolver;
4
4
  const logger_provider_1 = require("../provider/logger/logger.provider");
5
5
  /**
6
6
  * MiddlewareResolver class is responsible for resolving and retrieving Express middlewares
@@ -69,4 +69,3 @@ function middlewareResolver(middleware, ...options) {
69
69
  const resolver = new MiddlewareResolver();
70
70
  return resolver.getMiddleware(middleware, ...options);
71
71
  }
72
- exports.middlewareResolver = middlewareResolver;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BaseRepository = void 0;
13
+ const inversify_binding_decorators_1 = require("inversify-binding-decorators");
14
+ const db_in_memory_provider_1 = require("./db-in-memory.provider");
15
+ const inversify_1 = require("inversify");
16
+ /**
17
+ * Base Repository Class
18
+ *
19
+ * This class provides the basic functionalities to interact with an in-memory database.
20
+ *
21
+ * @decorator @provide(BaseRepository)
22
+ */
23
+ let BaseRepository = class BaseRepository {
24
+ /**
25
+ * Constructor
26
+ * @param tableName - The name of the table to interact with.
27
+ *
28
+ */
29
+ constructor(tableName) {
30
+ this.tableName = tableName;
31
+ }
32
+ /**
33
+ * Getter for the table
34
+ * @returns {T[]} - An array of entities.
35
+ */
36
+ get table() {
37
+ return [...this.inMemoryDB.getTable(this.tableName)];
38
+ }
39
+ /**
40
+ * create Method
41
+ * @param item - The entity to be created.
42
+ * @returns {T | null} - The created entity or null if the entity already exists.
43
+ * @throws {Error} - If the entity already exists.
44
+ */
45
+ create(item) {
46
+ const existingItem = this.table.find((i) => i.id === item.id);
47
+ if (existingItem) {
48
+ throw new Error(`Object with id ${item.id} already exists`);
49
+ }
50
+ this.inMemoryDB.getTable(this.tableName).push(item);
51
+ this.inMemoryDB.printTable(this.tableName);
52
+ return item;
53
+ }
54
+ /**
55
+ * delete Method
56
+ * @param id - The id of the entity to be deleted.
57
+ * @returns {boolean} - True if the entity was deleted, false otherwise.
58
+ * @throws {Error} - If the entity does not exist.
59
+ */
60
+ delete(id) {
61
+ const db = this.inMemoryDB.getTable(this.tableName);
62
+ const index = db.findIndex((item) => item.id === id);
63
+ if (index !== -1) {
64
+ db.splice(index, 1);
65
+ this.inMemoryDB.printTable(this.tableName);
66
+ return true;
67
+ }
68
+ return false;
69
+ }
70
+ /**
71
+ * update Method
72
+ * @param item - The entity to be updated.
73
+ * @returns {T | null} - The updated entity or null if the entity does not exist
74
+ * @throws {Error} - If the entity does not exist.
75
+ */
76
+ update(item) {
77
+ const db = this.inMemoryDB.getTable(this.tableName);
78
+ const index = db.findIndex((i) => i.id === item.id);
79
+ if (index !== -1) {
80
+ db[index] = item;
81
+ this.inMemoryDB.printTable(this.tableName);
82
+ return item;
83
+ }
84
+ return null;
85
+ }
86
+ /**
87
+ * find Method
88
+ * @param id - The id of the entity to find.
89
+ * @returns {T | null} - The entity if it exists, null otherwise
90
+ * @throws {Error} - If the entity does not exist.
91
+ */
92
+ find(id) {
93
+ const item = this.table.find((item) => item.id === id);
94
+ this.inMemoryDB.printTable(this.tableName);
95
+ return item || null;
96
+ }
97
+ /**
98
+ * findAll Method
99
+ * @returns {T[] | null} - An array of entities or null if the table is empty.
100
+ */
101
+ findAll() {
102
+ this.inMemoryDB.printTable(this.tableName);
103
+ return this.table;
104
+ }
105
+ };
106
+ exports.BaseRepository = BaseRepository;
107
+ __decorate([
108
+ (0, inversify_1.inject)(db_in_memory_provider_1.InMemoryDB),
109
+ __metadata("design:type", db_in_memory_provider_1.InMemoryDB)
110
+ ], BaseRepository.prototype, "inMemoryDB", void 0);
111
+ exports.BaseRepository = BaseRepository = __decorate([
112
+ (0, inversify_binding_decorators_1.provide)(BaseRepository),
113
+ __metadata("design:paramtypes", [String])
114
+ ], BaseRepository);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidateDTO = void 0;
3
+ exports.ValidateDTO = ValidateDTO;
4
4
  require("reflect-metadata");
5
5
  const status_code_1 = require("../../error/status-code");
6
6
  const package_resolver_1 = require("../../common/package-resolver");
@@ -50,4 +50,3 @@ function ValidateDTO(type) {
50
50
  }
51
51
  };
52
52
  }
53
- exports.ValidateDTO = ValidateDTO;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InMemoryDB = exports.ValidateDTO = exports.Env = exports.Logger = exports.ProviderManager = void 0;
3
+ exports.BaseRepository = exports.InMemoryDB = exports.ValidateDTO = exports.Env = exports.Logger = exports.ProviderManager = void 0;
4
4
  var provider_manager_1 = require("./provider-manager");
5
5
  Object.defineProperty(exports, "ProviderManager", { enumerable: true, get: function () { return provider_manager_1.ProviderManager; } });
6
6
  var logger_provider_1 = require("./logger/logger.provider");
@@ -11,3 +11,5 @@ var dto_validator_provider_1 = require("./dto-validator/dto-validator.provider")
11
11
  Object.defineProperty(exports, "ValidateDTO", { enumerable: true, get: function () { return dto_validator_provider_1.ValidateDTO; } });
12
12
  var db_in_memory_provider_1 = require("./db-in-memory/db-in-memory.provider");
13
13
  Object.defineProperty(exports, "InMemoryDB", { enumerable: true, get: function () { return db_in_memory_provider_1.InMemoryDB; } });
14
+ var base_repo_repository_1 = require("./db-in-memory/base-repo.repository");
15
+ Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repo_repository_1.BaseRepository; } });
@@ -1,3 +1,16 @@
1
+ /**
2
+ * Provides a binding for the given identifier.
3
+ *
4
+ * @param identifier - The identifier (e.g., symbol, string, class) for the dependency being registered.
5
+ * @returns A fluent interface for further configuring the binding.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * @provide(ServiceIdentifier)
10
+ * class MyService {}
11
+ * ```
12
+ */
13
+ declare const provide: (identifier: any) => (target: any) => any;
1
14
  /**
2
15
  * Provides a singleton binding for the given identifier.
3
16
  *
@@ -30,4 +43,4 @@ declare const provideSingleton: (identifier: any) => (target: any) => any;
30
43
  * ```
31
44
  */
32
45
  declare const provideTransient: (identifier: any) => (target: any) => any;
33
- export { provideSingleton, provideTransient };
46
+ export { provide, provideSingleton, provideTransient };
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import * as http from "http";
4
2
  interface OptionsJson {
5
3
  /** When set to true, then deflated (compressed) bodies will be inflated; when false, deflated bodies are rejected. Defaults to true. */
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import http from "http";
3
2
  export interface StreamOptions {
4
3
  /**
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { RequestHandler } from "express";
4
2
  import { Readable } from "stream";
5
3
  declare global {
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import http from "http";
3
2
  interface ServeStaticOptions<R extends http.ServerResponse = http.ServerResponse> {
4
3
  /**
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import express, { Request, Response, NextFunction } from "express";
3
2
  import { OptionsJson } from "./interfaces/body-parser.interface";
4
3
  import { CompressionOptions } from "./interfaces/compression.interface";
@@ -0,0 +1,63 @@
1
+ import { IMemoryDBEntity } from "./db-in-memory.provider";
2
+ export interface IBaseRepository<T extends IMemoryDBEntity> {
3
+ create(item: T): T | null;
4
+ update(item: T): T | null;
5
+ delete(id: string): boolean;
6
+ find(id: string): T | null;
7
+ findAll(): Array<T> | null;
8
+ }
9
+ /**
10
+ * Base Repository Class
11
+ *
12
+ * This class provides the basic functionalities to interact with an in-memory database.
13
+ *
14
+ * @decorator @provide(BaseRepository)
15
+ */
16
+ export declare class BaseRepository<T extends IMemoryDBEntity> implements IBaseRepository<T> {
17
+ private inMemoryDB;
18
+ private tableName;
19
+ /**
20
+ * Constructor
21
+ * @param tableName - The name of the table to interact with.
22
+ *
23
+ */
24
+ constructor(tableName: string);
25
+ /**
26
+ * Getter for the table
27
+ * @returns {T[]} - An array of entities.
28
+ */
29
+ protected get table(): Array<T>;
30
+ /**
31
+ * create Method
32
+ * @param item - The entity to be created.
33
+ * @returns {T | null} - The created entity or null if the entity already exists.
34
+ * @throws {Error} - If the entity already exists.
35
+ */
36
+ create(item: T): T | null;
37
+ /**
38
+ * delete Method
39
+ * @param id - The id of the entity to be deleted.
40
+ * @returns {boolean} - True if the entity was deleted, false otherwise.
41
+ * @throws {Error} - If the entity does not exist.
42
+ */
43
+ delete(id: string): boolean;
44
+ /**
45
+ * update Method
46
+ * @param item - The entity to be updated.
47
+ * @returns {T | null} - The updated entity or null if the entity does not exist
48
+ * @throws {Error} - If the entity does not exist.
49
+ */
50
+ update(item: T): T | null;
51
+ /**
52
+ * find Method
53
+ * @param id - The id of the entity to find.
54
+ * @returns {T | null} - The entity if it exists, null otherwise
55
+ * @throws {Error} - If the entity does not exist.
56
+ */
57
+ find(id: string): T | null;
58
+ /**
59
+ * findAll Method
60
+ * @returns {T[] | null} - An array of entities or null if the table is empty.
61
+ */
62
+ findAll(): Array<T> | null;
63
+ }
@@ -3,3 +3,4 @@ export { Logger } from "./logger/logger.provider";
3
3
  export { EnvValidatorProvider as Env } from "./environment/env-validator.provider";
4
4
  export { ValidateDTO } from "./dto-validator/dto-validator.provider";
5
5
  export { InMemoryDB, IMemoryDBEntity, } from "./db-in-memory/db-in-memory.provider";
6
+ export { BaseRepository, IBaseRepository, } from "./db-in-memory/base-repo.repository";
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/core",
3
- "version": "2.13.0",
3
+ "version": "2.14.1",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
5
5
  "author": "Richard Zampieri",
6
6
  "main": "./lib/cjs/index.js",
@@ -47,10 +47,10 @@
47
47
  "server-side"
48
48
  ],
49
49
  "engines": {
50
- "node": ">=18.10.0"
50
+ "node": ">=18.18.0"
51
51
  },
52
52
  "scripts": {
53
- "prepare": "husky install",
53
+ "prepare": "husky",
54
54
  "clean": "node scripts/rm.js lib",
55
55
  "copy": "node scripts/copy.js package.json README.md CHANGELOG.md lib",
56
56
  "rename:esm": "node scripts/mv.js lib/esm/index.js lib/esm/index.mjs",
@@ -77,19 +77,19 @@
77
77
  "@commitlint/cli": "19.2.1",
78
78
  "@commitlint/config-conventional": "19.1.0",
79
79
  "@expressots/adapter-express": "latest",
80
- "@release-it/conventional-changelog": "7.0.2",
80
+ "@release-it/conventional-changelog": "8.0.1",
81
81
  "@types/express": "4.17.21",
82
- "@types/node": "20.12.7",
83
- "@typescript-eslint/eslint-plugin": "7.6.0",
84
- "@typescript-eslint/parser": "7.6.0",
82
+ "@types/node": "20.14.9",
83
+ "@typescript-eslint/eslint-plugin": "7.15.0",
84
+ "@typescript-eslint/parser": "7.15.0",
85
85
  "@vitest/coverage-v8": "1.4.0",
86
86
  "eslint": "8.57.0",
87
87
  "eslint-config-prettier": "9.1.0",
88
88
  "husky": "9.0.11",
89
- "prettier": "3.3.1",
90
- "release-it": "16.3.0",
91
- "typescript": "5.2.2",
92
- "vite": "5.2.8",
89
+ "prettier": "3.3.2",
90
+ "release-it": "17.4.1",
91
+ "typescript": "5.5.3",
92
+ "vite": "5.3.3",
93
93
  "vite-tsconfig-paths": "4.3.2",
94
94
  "vitest": "1.4.0"
95
95
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/core",
3
- "version": "2.13.0",
3
+ "version": "2.14.1",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
5
5
  "author": "Richard Zampieri",
6
6
  "main": "./lib/cjs/index.js",
@@ -47,10 +47,10 @@
47
47
  "server-side"
48
48
  ],
49
49
  "engines": {
50
- "node": ">=18.10.0"
50
+ "node": ">=18.18.0"
51
51
  },
52
52
  "scripts": {
53
- "prepare": "husky install",
53
+ "prepare": "husky",
54
54
  "clean": "node scripts/rm.js lib",
55
55
  "copy": "node scripts/copy.js package.json README.md CHANGELOG.md lib",
56
56
  "rename:esm": "node scripts/mv.js lib/esm/index.js lib/esm/index.mjs",
@@ -77,19 +77,19 @@
77
77
  "@commitlint/cli": "19.2.1",
78
78
  "@commitlint/config-conventional": "19.1.0",
79
79
  "@expressots/adapter-express": "latest",
80
- "@release-it/conventional-changelog": "7.0.2",
80
+ "@release-it/conventional-changelog": "8.0.1",
81
81
  "@types/express": "4.17.21",
82
- "@types/node": "20.12.7",
83
- "@typescript-eslint/eslint-plugin": "7.6.0",
84
- "@typescript-eslint/parser": "7.6.0",
82
+ "@types/node": "20.14.9",
83
+ "@typescript-eslint/eslint-plugin": "7.15.0",
84
+ "@typescript-eslint/parser": "7.15.0",
85
85
  "@vitest/coverage-v8": "1.4.0",
86
86
  "eslint": "8.57.0",
87
87
  "eslint-config-prettier": "9.1.0",
88
88
  "husky": "9.0.11",
89
- "prettier": "3.3.1",
90
- "release-it": "16.3.0",
91
- "typescript": "5.2.2",
92
- "vite": "5.2.8",
89
+ "prettier": "3.3.2",
90
+ "release-it": "17.4.1",
91
+ "typescript": "5.5.3",
92
+ "vite": "5.3.3",
93
93
  "vite-tsconfig-paths": "4.3.2",
94
94
  "vitest": "1.4.0"
95
95
  },