@expressots/core 2.6.0 → 2.7.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.
@@ -0,0 +1,75 @@
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 InMemoryDB_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.InMemoryDB = void 0;
11
+ const decorator_1 = require("../../decorator");
12
+ /**
13
+ * InMemoryDB Class
14
+ *
15
+ * This class and its methods offer functionalities to simulate an in-memory database.
16
+ * It is particularly useful for developers starting with ExpressoTS without any database connection.
17
+ *
18
+ * @decorator @provideSingleton(InMemoryDB)
19
+ */
20
+ let InMemoryDB = exports.InMemoryDB = InMemoryDB_1 = class InMemoryDB {
21
+ tables = {};
22
+ /**
23
+ * getTable Method
24
+ *
25
+ * Retrieves a table by its name from the in-memory database.
26
+ *
27
+ * @param tableName - The name of the table to retrieve.
28
+ * @returns {IEntity[]} - An array of entities.
29
+ */
30
+ getTable(tableName) {
31
+ if (!this.tables[tableName]) {
32
+ this.tables[tableName] = [];
33
+ }
34
+ return this.tables[tableName];
35
+ }
36
+ /**
37
+ * showTables Method
38
+ *
39
+ * Prints a list of all tables in the in-memory database to the standard output.
40
+ */
41
+ showTables() {
42
+ if (!this.tables) {
43
+ process.stdout.write("No tables exist.");
44
+ return;
45
+ }
46
+ process.stdout.write("List of tables:");
47
+ for (const tableName in this.tables) {
48
+ process.stdout.write(`\n- ${tableName}`);
49
+ }
50
+ }
51
+ /**
52
+ * printTable Method
53
+ *
54
+ * Prints all records in a specific table to the console.
55
+ * If the table doesn't exist or is empty, it notifies the user.
56
+ *
57
+ * @param tableName - The name of the table to print.
58
+ */
59
+ printTable(tableName) {
60
+ if (!this.tables) {
61
+ process.stdout.write("No tables exist.");
62
+ return;
63
+ }
64
+ const table = this.getTable(tableName);
65
+ if (table.length === 0) {
66
+ process.stdout.write(`Table '${tableName}' is empty.`);
67
+ return;
68
+ }
69
+ process.stdout.write(`\nRecords in table '${tableName}':\n`);
70
+ console.table(table);
71
+ }
72
+ };
73
+ exports.InMemoryDB = InMemoryDB = InMemoryDB_1 = __decorate([
74
+ (0, decorator_1.provideSingleton)(InMemoryDB_1)
75
+ ], InMemoryDB);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidateDTO = exports.Env = exports.Logger = exports.Provider = void 0;
3
+ exports.InMemoryDB = exports.ValidateDTO = exports.Env = exports.Logger = exports.Provider = void 0;
4
4
  var provider_service_1 = require("./provider-service");
5
5
  Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return provider_service_1.Provider; } });
6
6
  var logger_service_1 = require("./logger/logger-service");
@@ -9,3 +9,5 @@ var env_validator_provider_1 = require("./environment/env-validator.provider");
9
9
  Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return env_validator_provider_1.EnvValidatorProvider; } });
10
10
  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
+ var db_in_memory_provider_1 = require("./db-in-memory/db-in-memory.provider");
13
+ Object.defineProperty(exports, "InMemoryDB", { enumerable: true, get: function () { return db_in_memory_provider_1.InMemoryDB; } });
@@ -0,0 +1,38 @@
1
+ export interface IInMemoryDBEntity {
2
+ id: string;
3
+ }
4
+ /**
5
+ * InMemoryDB Class
6
+ *
7
+ * This class and its methods offer functionalities to simulate an in-memory database.
8
+ * It is particularly useful for developers starting with ExpressoTS without any database connection.
9
+ *
10
+ * @decorator @provideSingleton(InMemoryDB)
11
+ */
12
+ export declare class InMemoryDB {
13
+ private tables;
14
+ /**
15
+ * getTable Method
16
+ *
17
+ * Retrieves a table by its name from the in-memory database.
18
+ *
19
+ * @param tableName - The name of the table to retrieve.
20
+ * @returns {IEntity[]} - An array of entities.
21
+ */
22
+ getTable(tableName: string): Array<IInMemoryDBEntity>;
23
+ /**
24
+ * showTables Method
25
+ *
26
+ * Prints a list of all tables in the in-memory database to the standard output.
27
+ */
28
+ showTables(): void;
29
+ /**
30
+ * printTable Method
31
+ *
32
+ * Prints all records in a specific table to the console.
33
+ * If the table doesn't exist or is empty, it notifies the user.
34
+ *
35
+ * @param tableName - The name of the table to print.
36
+ */
37
+ printTable(tableName: string): void;
38
+ }
@@ -2,3 +2,4 @@ export { Provider, IProvider } from "./provider-service";
2
2
  export { Logger } from "./logger/logger-service";
3
3
  export { EnvValidatorProvider as Env } from "./environment/env-validator.provider";
4
4
  export { ValidateDTO } from "./dto-validator/dto-validator.provider";
5
+ export { InMemoryDB, IInMemoryDBEntity, } from "./db-in-memory/db-in-memory.provider";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/core",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
5
5
  "author": "Richard Zampieri",
6
6
  "main": "./lib/cjs/index.js",