@dascompany/database 2.0.0 → 2.1.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,14 @@
1
+ import DatabaseConfig from "./DatabaseConfig";
2
+ import Connection from "./Connection";
3
+ export default class ConnectionFactory {
4
+ private static connections;
5
+ private static configName;
6
+ private static configField;
7
+ private static configPath;
8
+ private static defaultDatabaseName;
9
+ static create(name?: string): Promise<Connection>;
10
+ static isCreated(name?: string): boolean;
11
+ static get(name?: string): Connection;
12
+ private static createConnection;
13
+ protected static getDatabaseConfig(): Promise<DatabaseConfig>;
14
+ }
@@ -0,0 +1,47 @@
1
+ import Database from "./Database";
2
+ import Connection from "./Connection";
3
+ import { readFile } from 'fs/promises';
4
+ export default class ConnectionFactory {
5
+ static connections = new Map();
6
+ static configName = 'config.json';
7
+ static configField = 'database';
8
+ static configPath = './server/';
9
+ static defaultDatabaseName = 'defaultDatabaseName';
10
+ static async create(name) {
11
+ name = name || this.defaultDatabaseName;
12
+ let connection = this.connections.get(name);
13
+ if (!connection) {
14
+ connection = await this.createConnection();
15
+ this.connections.set(name, connection);
16
+ }
17
+ else
18
+ throw new Error(`Connection for name: ${name} is already created! `);
19
+ return connection;
20
+ }
21
+ static isCreated(name) {
22
+ name = name || this.defaultDatabaseName;
23
+ let connection = this.connections.get(name);
24
+ if (!connection)
25
+ return false;
26
+ else
27
+ return true;
28
+ }
29
+ static get(name) {
30
+ name = name || this.defaultDatabaseName;
31
+ const connection = this.connections.get(name);
32
+ if (!connection)
33
+ throw new Error(`Connection with name: ${name} is not create! `);
34
+ return connection;
35
+ }
36
+ static async createConnection() {
37
+ const databaseConfig = await this.getDatabaseConfig();
38
+ const pgClient = await Database.connect(databaseConfig);
39
+ return new Connection(pgClient);
40
+ }
41
+ static async getDatabaseConfig() {
42
+ let config = JSON.parse(await readFile(`${this.configPath}${this.configName}`, "utf8"));
43
+ if (this.configField)
44
+ config = config[this.configField];
45
+ return config;
46
+ }
47
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import DatabaseConnection from "./DatabaseConnection";
1
+ import ConnectionFactory from "./ConnectionFactory";
2
2
  import StockObject from "./types/StockObject";
3
3
  import StockObjectMapper from "./types/StockObjectMapper";
4
4
  import Table from "./Table";
@@ -9,8 +9,8 @@ import ParameterI from './types/ParameterI';
9
9
  import QueryOptionsI from './types/QueryOptionsI';
10
10
  import ResultLimitationI from './types/ResultLimitationI';
11
11
  import Parameters from './utils/Parameters';
12
- import OrderByI from "./utils/OrderByI";
12
+ import OrderByI from "./types/OrderByI";
13
13
  import QueryOptions from './query/QueryOptions';
14
14
  import ConnectorE from "./types/ConnectorE";
15
15
  import Connection from "./Connection";
16
- export { DatabaseConnection, StockObject, StockObjectMapper, Table, Query, ParameterType, ParameterFilter, ConnectorE, ParameterI, QueryOptionsI, ResultLimitationI, Parameters, OrderByI, QueryOptions, Connection };
16
+ export { ConnectionFactory, StockObject, StockObjectMapper, Table, Query, ParameterType, ParameterFilter, ConnectorE, ParameterI, QueryOptionsI, ResultLimitationI, Parameters, OrderByI, QueryOptions, Connection };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import DatabaseConnection from "./DatabaseConnection";
1
+ import ConnectionFactory from "./ConnectionFactory";
2
2
  import StockObject from "./types/StockObject";
3
3
  import Table from "./Table";
4
4
  import Query from "./query/Query";
@@ -7,4 +7,4 @@ import Parameters from './utils/Parameters';
7
7
  import QueryOptions from './query/QueryOptions';
8
8
  import ConnectorE from "./types/ConnectorE";
9
9
  import Connection from "./Connection";
10
- export { DatabaseConnection, StockObject, Table, Query, ParameterType, ConnectorE, Parameters, QueryOptions, Connection };
10
+ export { ConnectionFactory, StockObject, Table, Query, ParameterType, ConnectorE, Parameters, QueryOptions, Connection };
@@ -1,5 +1,5 @@
1
1
  import ResultLimitationI from "../types/ResultLimitationI";
2
- import OrderByI from "../utils/OrderByI";
2
+ import OrderByI from "../types/OrderByI";
3
3
  export default class QueryOptions {
4
4
  static correctingSorting(querySortBy: any): OrderByI[];
5
5
  static correctingLimitation(queryLimit: any, queryOffset: any): ResultLimitationI;
@@ -1,4 +1,4 @@
1
- import OrderByI from "../utils/OrderByI";
1
+ import OrderByI from "./OrderByI";
2
2
  import ParameterI from "./ParameterI";
3
3
  import ResultLimitationI from "./ResultLimitationI";
4
4
  import WhereOptionI from "./WhereOptionI";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/database",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",
@@ -18,10 +18,10 @@
18
18
  "devDependencies": {
19
19
  "types": "^0.1.1",
20
20
  "typescript": "^5.7.3",
21
- "vitest": "^3.0.2"
21
+ "vitest": "^3.0.6"
22
22
  },
23
23
  "dependencies": {
24
- "@types/pg": "^8.11.10",
25
- "pg": "^8.13.1"
24
+ "@types/pg": "^8.11.11",
25
+ "pg": "^8.13.3"
26
26
  }
27
27
  }
@@ -1,11 +0,0 @@
1
- import DatabaseConfig from "./DatabaseConfig";
2
- import Connection from "./Connection";
3
- export default class DatabaseConnection {
4
- private static connection;
5
- private static configName;
6
- private static configField;
7
- private static configPath;
8
- static get(): Connection;
9
- static create(): Promise<Connection>;
10
- static getDatabaseConfig(): Promise<DatabaseConfig>;
11
- }
@@ -1,28 +0,0 @@
1
- import Database from "./Database";
2
- import Connection from "./Connection";
3
- import { readFile } from 'fs/promises';
4
- export default class DatabaseConnection {
5
- static connection;
6
- static configName = 'config.json';
7
- static configField = 'database';
8
- static configPath = './server/';
9
- static get() {
10
- if (!this.connection)
11
- throw Error('Connection not created!');
12
- return this.connection;
13
- }
14
- static async create() {
15
- if (!this.connection) {
16
- const databaseConfig = await this.getDatabaseConfig();
17
- const pgClient = await Database.connect(databaseConfig);
18
- this.connection = new Connection(pgClient);
19
- }
20
- return this.connection;
21
- }
22
- static async getDatabaseConfig() {
23
- let config = JSON.parse(await readFile(`${this.configPath}${this.configName}`, "utf8"));
24
- if (this.configField)
25
- config = config[this.configField];
26
- return config;
27
- }
28
- }
@@ -1 +0,0 @@
1
- export default function calculateNetToGrossPrice(netPrice: number, vatPercentage: number): number;
@@ -1,7 +0,0 @@
1
- export default function calculateNetToGrossPrice(netPrice, vatPercentage) {
2
- const netPriceInPenny = Math.round(netPrice * 100);
3
- const vatPriceInPenny = Math.round((netPriceInPenny * vatPercentage) / 100);
4
- const grossPriceInPenny = netPriceInPenny + vatPriceInPenny;
5
- const grossPrice = (grossPriceInPenny / 100).toFixed(2);
6
- return Number(grossPrice);
7
- }
@@ -1 +0,0 @@
1
- export default function correctPhoneNumber(phoneNumber: any): string;
@@ -1,14 +0,0 @@
1
- export default function correctPhoneNumber(phoneNumber) {
2
- let phoneStr = String(phoneNumber);
3
- phoneStr = phoneStr.replaceAll(' ', '');
4
- phoneStr = phoneStr.replaceAll('-', '');
5
- if (phoneStr.startsWith('48') && phoneStr.length == 11)
6
- phoneStr = `+${phoneStr}`;
7
- else if (phoneStr.startsWith('+48') && phoneStr.length == 12)
8
- phoneStr = phoneStr;
9
- else if (phoneStr.length == 9)
10
- phoneStr = `+48${phoneStr}`;
11
- else
12
- phoneStr = phoneStr;
13
- return phoneStr;
14
- }
File without changes
File without changes