@expressots/core 2.14.0 → 2.15.0

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,42 @@
1
1
 
2
2
 
3
+ ## [2.15.0](https://github.com/expressots/expressots/compare/2.14.1...2.15.0) (2024-07-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * bump @types/node from 20.14.9 to 20.14.10 ([2061291](https://github.com/expressots/expressots/commit/20612919e11dcaaebe06cf740e7513efc80acdf9))
9
+ * bump @typescript-eslint/eslint-plugin from 7.15.0 to 7.16.0 ([4c33e38](https://github.com/expressots/expressots/commit/4c33e38d1d3c7041c72758d1b9001b7e0788927a))
10
+ * bump @typescript-eslint/parser from 7.15.0 to 7.16.0 ([db38183](https://github.com/expressots/expressots/commit/db381837868cb0701b332ac5f23437c3bd5ba180))
11
+ * bump prettier from 3.3.2 to 3.3.3 ([1d3ee41](https://github.com/expressots/expressots/commit/1d3ee41902344a5fde5e79a0f6fafdde52ea31cd))
12
+ * bump release-it from 17.4.1 to 17.5.0 ([a4aa310](https://github.com/expressots/expressots/commit/a4aa3103f0b9df81dfa78f4de34ea3fbc7e407c9))
13
+ * bump vitest and @vitest/coverage-v8 ([f186dc3](https://github.com/expressots/expressots/commit/f186dc30c271267f0995276216a616f7b99e21ef))
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * remove git modules cmds ([be88854](https://github.com/expressots/expressots/commit/be888548ed225feb43ad6db6929bf8d820ff8e1b))
19
+ * update index ([ebb6e8e](https://github.com/expressots/expressots/commit/ebb6e8ece46e343203136e8fc502a95ce23c2440))
20
+
21
+
22
+ ### Code Refactoring
23
+
24
+ * remove render from core ([70ba135](https://github.com/expressots/expressots/commit/70ba135593466cccb5d895029c588e544434dd26))
25
+
26
+ ## [2.14.1](https://github.com/expressots/expressots/compare/2.14.0...2.14.1) (2024-07-04)
27
+
28
+
29
+ ### Code Refactoring
30
+
31
+ * add tests for in memory db ([6914f15](https://github.com/expressots/expressots/commit/6914f156b1fae0b09ba2926e964dc7376a47b67f))
32
+ * in memory db internal provider ([168547b](https://github.com/expressots/expressots/commit/168547b79d1b1e72b9ffdc06ec1bd5f7bebae150))
33
+ * remove inversify binding dependency ([593620c](https://github.com/expressots/expressots/commit/593620c10c3bce3c4177e92ba75a74bb45a0c789))
34
+
35
+
36
+ ### Tests
37
+
38
+ * increase code coverage ([ae71339](https://github.com/expressots/expressots/commit/ae713397c8f85a49b746cfb2a26c8b83a0e2727f))
39
+
3
40
  ## [2.14.0](https://github.com/expressots/expressots/compare/2.13.0...2.14.0) (2024-07-04)
4
41
 
5
42
 
package/lib/cjs/index.js CHANGED
@@ -23,4 +23,3 @@ __exportStar(require("./decorator"), exports);
23
23
  __exportStar(require("./error"), exports);
24
24
  __exportStar(require("./middleware"), exports);
25
25
  __exportStar(require("./provider"), exports);
26
- __exportStar(require("./render"), exports);
@@ -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.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; } });
@@ -7,4 +7,3 @@ export * from "./decorator";
7
7
  export * from "./error";
8
8
  export * from "./middleware";
9
9
  export * from "./provider";
10
- export * from "./render";
@@ -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.14.0",
3
+ "version": "2.15.0",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
5
5
  "author": "Richard Zampieri",
6
6
  "main": "./lib/cjs/index.js",
@@ -79,19 +79,19 @@
79
79
  "@expressots/adapter-express": "latest",
80
80
  "@release-it/conventional-changelog": "8.0.1",
81
81
  "@types/express": "4.17.21",
82
- "@types/node": "20.14.9",
83
- "@typescript-eslint/eslint-plugin": "7.15.0",
84
- "@typescript-eslint/parser": "7.15.0",
85
- "@vitest/coverage-v8": "1.4.0",
82
+ "@types/node": "20.14.10",
83
+ "@typescript-eslint/eslint-plugin": "7.16.0",
84
+ "@typescript-eslint/parser": "7.16.0",
85
+ "@vitest/coverage-v8": "2.0.2",
86
86
  "eslint": "8.57.0",
87
87
  "eslint-config-prettier": "9.1.0",
88
88
  "husky": "9.0.11",
89
- "prettier": "3.3.2",
90
- "release-it": "17.4.1",
89
+ "prettier": "3.3.3",
90
+ "release-it": "17.5.0",
91
91
  "typescript": "5.5.3",
92
92
  "vite": "5.3.3",
93
93
  "vite-tsconfig-paths": "4.3.2",
94
- "vitest": "1.4.0"
94
+ "vitest": "2.0.2"
95
95
  },
96
96
  "release-it": {
97
97
  "git": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/core",
3
- "version": "2.14.0",
3
+ "version": "2.15.0",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
5
5
  "author": "Richard Zampieri",
6
6
  "main": "./lib/cjs/index.js",
@@ -79,19 +79,19 @@
79
79
  "@expressots/adapter-express": "latest",
80
80
  "@release-it/conventional-changelog": "8.0.1",
81
81
  "@types/express": "4.17.21",
82
- "@types/node": "20.14.9",
83
- "@typescript-eslint/eslint-plugin": "7.15.0",
84
- "@typescript-eslint/parser": "7.15.0",
85
- "@vitest/coverage-v8": "1.4.0",
82
+ "@types/node": "20.14.10",
83
+ "@typescript-eslint/eslint-plugin": "7.16.0",
84
+ "@typescript-eslint/parser": "7.16.0",
85
+ "@vitest/coverage-v8": "2.0.2",
86
86
  "eslint": "8.57.0",
87
87
  "eslint-config-prettier": "9.1.0",
88
88
  "husky": "9.0.11",
89
- "prettier": "3.3.2",
90
- "release-it": "17.4.1",
89
+ "prettier": "3.3.3",
90
+ "release-it": "17.5.0",
91
91
  "typescript": "5.5.3",
92
92
  "vite": "5.3.3",
93
93
  "vite-tsconfig-paths": "4.3.2",
94
- "vitest": "1.4.0"
94
+ "vitest": "2.0.2"
95
95
  },
96
96
  "release-it": {
97
97
  "git": {
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,46 +0,0 @@
1
- /**
2
- * Configuration options for Express Handlebars.
3
- * @interface ConfigOptions
4
- */
5
- interface ConfigOptions {
6
- extname?: string;
7
- layoutDir?: string;
8
- defaultLayout?: string | false;
9
- }
10
- /**
11
- * Callback function for rendering templates.
12
- * @callback RenderCallback
13
- *
14
- * @param {Error | null} err - The error object.
15
- * @param {string} [content] - The rendered content.
16
- */
17
- interface RenderCallback {
18
- (err: Error | null, content?: string): void;
19
- }
20
- /**
21
- * Function for rendering templates.
22
- * @typedef Engine
23
- *
24
- * @param {string} viewPath - The path to the directory containing the templates.
25
- * @param {ConfigOptions} options - The configuration options for the template engine.
26
- * @param {RenderCallback} [callback] - The callback function for rendering templates.
27
- */
28
- type Engine = (viewPath: string, options: ConfigOptions, callback?: RenderCallback) => void;
29
- /**
30
- * Interface representing the configuration options for Handlebars templates.
31
- */
32
- interface IHandlebars {
33
- /**
34
- * Specifies the extension name for the Handlebars templates.
35
- */
36
- extName: string;
37
- /**
38
- * Specifies the path to the directory containing the Handlebars templates.
39
- */
40
- viewPath: string;
41
- /**
42
- * Specifies the function for rendering Handlebars templates.
43
- */
44
- engine: Engine;
45
- }
46
- export { IHandlebars };
@@ -1,2 +0,0 @@
1
- export { IHandlebars } from "./handlebars.interface";
2
- export { RenderTemplateOptions } from "./render.type";
@@ -1,12 +0,0 @@
1
- import { IHandlebars } from "./handlebars.interface";
2
- /**
3
- * Type alias for the configuration options for rendering templates.
4
- *
5
- * Currently, this type alias is equivalent to the `IHandlebars` interface,
6
- * and represents the configuration options for Handlebars templates.
7
- *
8
- * In the future, this type could be expanded to include configuration options
9
- * for other template engines.
10
- */
11
- type RenderTemplateOptions = IHandlebars;
12
- export { RenderTemplateOptions };