tspace-mysql 1.2.9 → 1.3.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.
Files changed (56) hide show
  1. package/README.md +64 -14
  2. package/dist/cli/dump/db.d.ts +4 -4
  3. package/dist/cli/dump/db.js +25 -25
  4. package/dist/cli/generate/make.d.ts +4 -4
  5. package/dist/cli/generate/make.js +45 -45
  6. package/dist/cli/generate/model.d.ts +2 -2
  7. package/dist/cli/generate/model.js +6 -6
  8. package/dist/cli/index.d.ts +2 -2
  9. package/dist/cli/index.js +58 -58
  10. package/dist/cli/migrate/make.d.ts +4 -4
  11. package/dist/cli/migrate/make.js +30 -30
  12. package/dist/cli/models/make.d.ts +4 -4
  13. package/dist/cli/models/make.js +51 -51
  14. package/dist/cli/models/model.d.ts +2 -2
  15. package/dist/cli/models/model.js +20 -11
  16. package/dist/cli/query/index.d.ts +4 -4
  17. package/dist/cli/query/index.js +7 -7
  18. package/dist/cli/tables/make.d.ts +4 -4
  19. package/dist/cli/tables/make.js +26 -26
  20. package/dist/cli/tables/table.d.ts +2 -2
  21. package/dist/cli/tables/table.js +6 -6
  22. package/dist/lib/connection/index.d.ts +30 -30
  23. package/dist/lib/connection/index.js +144 -143
  24. package/dist/lib/connection/options.d.ts +15 -4
  25. package/dist/lib/connection/options.js +43 -42
  26. package/dist/lib/constants/index.d.ts +5 -8
  27. package/dist/lib/constants/index.js +162 -158
  28. package/dist/lib/index.d.ts +8 -8
  29. package/dist/lib/index.js +36 -36
  30. package/dist/lib/tspace/{AbstractDatabase.d.ts → AbstractBuilder.d.ts} +124 -116
  31. package/dist/lib/tspace/{AbstractDatabase.js → AbstractBuilder.js} +36 -34
  32. package/dist/lib/tspace/AbstractDB.d.ts +18 -18
  33. package/dist/lib/tspace/AbstractDB.js +11 -11
  34. package/dist/lib/tspace/AbstractModel.d.ts +41 -41
  35. package/dist/lib/tspace/AbstractModel.js +11 -11
  36. package/dist/lib/tspace/Blueprint.d.ts +136 -136
  37. package/dist/lib/tspace/Blueprint.js +228 -228
  38. package/dist/lib/tspace/{Database.d.ts → Builder.d.ts} +833 -706
  39. package/dist/lib/tspace/{Database.js → Builder.js} +2556 -2363
  40. package/dist/lib/tspace/DB.d.ts +152 -126
  41. package/dist/lib/tspace/DB.js +373 -264
  42. package/dist/lib/tspace/Interface.d.ts +110 -109
  43. package/dist/lib/tspace/Interface.js +2 -2
  44. package/dist/lib/tspace/Logger.d.ts +8 -8
  45. package/dist/lib/tspace/Logger.js +49 -49
  46. package/dist/lib/tspace/Model.d.ts +708 -609
  47. package/dist/lib/tspace/Model.js +2520 -2477
  48. package/dist/lib/tspace/ProxyHandler.d.ts +14 -14
  49. package/dist/lib/tspace/ProxyHandler.js +31 -31
  50. package/dist/lib/tspace/Schema.d.ts +8 -8
  51. package/dist/lib/tspace/Schema.js +45 -44
  52. package/dist/lib/tspace/index.d.ts +15 -15
  53. package/dist/lib/tspace/index.js +20 -20
  54. package/dist/lib/utils/index.d.ts +15 -15
  55. package/dist/lib/utils/index.js +155 -165
  56. package/package.json +2 -4
@@ -1,6 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Model = (model, npm) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Model = (model, npm) => {
4
4
  return `import { Model } from '${npm}'
5
5
  class ${model} extends Model {
6
6
  constructor(){
@@ -10,21 +10,30 @@ class ${model} extends Model {
10
10
  * Assign setting global in your model
11
11
  * @useMethod
12
12
  *
13
- * this.useDebug() // => runing a uuid (universally unique identifier) when insert new data
14
- * this.usePrimaryKey('id') // => runing a uuid (universally unique identifier) when insert new data
15
- * this.useTimestamp({ createdAt : 'created_at' , updatedAt : 'updated_at' }) // runing a timestamp when insert or update
13
+ * this.useDebug()
14
+ * this.usePrimaryKey('id')
15
+ * this.useTimestamp({
16
+ * createdAt : 'created_at',
17
+ * updatedAt : 'updated_at'
18
+ * }) // runing a timestamp when insert or update
16
19
  * this.useSoftDelete()
17
20
  * this.useTable('users')
18
21
  * this.useTableSingular() // 'user'
19
22
  * this.useTablePlural() // 'users'
20
- * this.usePattern('snake_case')
21
- * this.useUUID('uuid')
23
+ * this.usePattern('snake_case') // by defalut snake_case
24
+ * this.useUUID('uuid') // => runing a uuid (universally unique identifier) when insert new data
22
25
  * this.useRegistry()
26
+ * this.useSchema({
27
+ * id : Number,
28
+ * username : String
29
+ * created_at : Date,
30
+ * updated_at : Date,
31
+ * }) // validate type of schema when return result
23
32
  */
24
33
  }
25
34
  }
26
35
  export { ${model} }
27
36
  export default ${model}
28
- `;
29
- };
30
- exports.default = Model;
37
+ `;
38
+ };
39
+ exports.default = Model;
@@ -1,4 +1,4 @@
1
- declare const _default: (cmd: {
2
- [x: string]: any;
3
- }) => void;
4
- export default _default;
1
+ declare const _default: (cmd: {
2
+ [x: string]: any;
3
+ }) => void;
4
+ export default _default;
@@ -1,7 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const lib_1 = require("../../lib");
4
- exports.default = (cmd) => {
5
- const { sql } = cmd;
6
- new lib_1.DB().rawQuery(sql === null || sql === void 0 ? void 0 : sql.replace(/`/g, '')).then(result => console.log(result));
7
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lib_1 = require("../../lib");
4
+ exports.default = (cmd) => {
5
+ const { sql } = cmd;
6
+ new lib_1.DB().rawQuery(sql === null || sql === void 0 ? void 0 : sql.replace(/`/g, '')).then(result => console.log(result));
7
+ };
@@ -1,4 +1,4 @@
1
- declare const _default: (formCommand: {
2
- [x: string]: any;
3
- }) => void;
4
- export default _default;
1
+ declare const _default: (formCommand: {
2
+ [x: string]: any;
3
+ }) => void;
4
+ export default _default;
@@ -1,26 +1,26 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const table_1 = __importDefault(require("./table"));
7
- exports.default = (formCommand) => {
8
- const { file, type, cwd, dir, fs, npm } = formCommand;
9
- try {
10
- fs.accessSync(cwd + `/${file}`, fs.F_OK, {
11
- recursive: true
12
- });
13
- }
14
- catch (e) {
15
- fs.mkdirSync(cwd + `/${file}`, {
16
- recursive: true
17
- });
18
- }
19
- const folderMigrate = dir ? `${cwd}/${dir}/create_${file}_table${type}` : `${cwd}/create_${file}_table${type}`;
20
- const table = (0, table_1.default)(file, npm);
21
- fs.writeFile(folderMigrate, table, (err) => {
22
- if (err)
23
- console.log(err.message);
24
- });
25
- console.log(`Migration : ${file} created successfully`);
26
- };
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const table_1 = __importDefault(require("./table"));
7
+ exports.default = (formCommand) => {
8
+ const { file, type, cwd, dir, fs, npm } = formCommand;
9
+ try {
10
+ fs.accessSync(cwd + `/${file}`, fs.F_OK, {
11
+ recursive: true
12
+ });
13
+ }
14
+ catch (e) {
15
+ fs.mkdirSync(cwd + `/${file}`, {
16
+ recursive: true
17
+ });
18
+ }
19
+ const folderMigrate = dir ? `${cwd}/${dir}/create_${file}_table${type}` : `${cwd}/create_${file}_table${type}`;
20
+ const table = (0, table_1.default)(file, npm);
21
+ fs.writeFile(folderMigrate, table, (err) => {
22
+ if (err)
23
+ console.log(err.message);
24
+ });
25
+ console.log(`Migration : ${file} created successfully`);
26
+ };
@@ -1,2 +1,2 @@
1
- declare const Table: (table: string, npm: string) => string;
2
- export default Table;
1
+ declare const Table: (table: string, npm: string) => string;
2
+ export default Table;
@@ -1,6 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Table = (table, npm) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Table = (table, npm) => {
4
4
  return `import { Schema , Blueprint , DB } from '${npm}'
5
5
  (async () => {
6
6
  await new Schema().table('${table}',{
@@ -21,6 +21,6 @@ const Table = (table, npm) => {
21
21
  * await new DB().table('${table}').faker(5)
22
22
  */
23
23
  })()
24
- `;
25
- };
26
- exports.default = Table;
24
+ `;
25
+ };
26
+ exports.default = Table;
@@ -1,30 +1,30 @@
1
- import { Connection, Options } from '../tspace/Interface';
2
- export declare class PoolConnection {
3
- private OPTIONS;
4
- /**
5
- *
6
- * @Init a options connection pool
7
- */
8
- constructor(options?: Options);
9
- /**
10
- *
11
- * Get a connection to database
12
- * @return {Connection} Connection
13
- * @property {Function} Connection.query
14
- * @property {Function} Connection.connection
15
- */
16
- connection(): Connection;
17
- private _defaultOptions;
18
- private _loadOptions;
19
- private _messageError;
20
- }
21
- /**
22
- *
23
- * Connection to database when service is started
24
- * @return {Connection} Connection
25
- * @property {Function} Connection.query
26
- * @property {Function} Connection.connection
27
- */
28
- declare const pool: Connection;
29
- export { pool as Pool };
30
- export default pool;
1
+ import { Connection, Options } from '../tspace/Interface';
2
+ export declare class PoolConnection {
3
+ private OPTIONS;
4
+ /**
5
+ *
6
+ * @Init a options connection pool
7
+ */
8
+ constructor(options?: Options);
9
+ /**
10
+ *
11
+ * Get a connection to database
12
+ * @return {Connection} Connection
13
+ * @property {Function} Connection.query
14
+ * @property {Function} Connection.connection
15
+ */
16
+ connection(): Connection;
17
+ private _defaultOptions;
18
+ private _loadOptions;
19
+ private _messageError;
20
+ }
21
+ /**
22
+ *
23
+ * Connection to database when service is started
24
+ * @return {Connection} Connection
25
+ * @property {Function} Connection.query
26
+ * @property {Function} Connection.connection
27
+ */
28
+ declare const pool: Connection;
29
+ export { pool as Pool };
30
+ export default pool;
@@ -1,132 +1,133 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Pool = exports.PoolConnection = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const options_1 = __importDefault(require("./options"));
10
- const mysql2_1 = require("mysql2");
11
- class PoolConnection {
12
- /**
13
- *
14
- * @Init a options connection pool
15
- */
16
- constructor(options) {
17
- this.OPTIONS = this._loadOptions();
18
- if (options) {
19
- this.OPTIONS = new Map(Object.entries(Object.assign(Object.assign({}, Object.fromEntries(this.OPTIONS)), JSON.parse(JSON.stringify(options)))));
20
- }
21
- }
22
- /**
23
- *
24
- * Get a connection to database
25
- * @return {Connection} Connection
26
- * @property {Function} Connection.query
27
- * @property {Function} Connection.connection
28
- */
29
- connection() {
30
- const pool = (0, mysql2_1.createPool)(Object.fromEntries(this.OPTIONS));
31
- if (options_1.default.CONNECTION_ERROR) {
32
- pool.getConnection((err, _) => {
33
- if (err == null || !err)
34
- return;
35
- const message = this._messageError.bind(this);
36
- process.nextTick(() => {
37
- console.log(message());
38
- return process.exit();
39
- });
40
- });
41
- }
42
- return {
43
- query: (sql) => {
44
- return new Promise((resolve, reject) => {
45
- pool.query(sql, (err, results) => {
46
- if (err)
47
- return reject(err);
48
- return resolve(results);
49
- });
50
- });
51
- },
52
- connection: () => {
53
- return new Promise((resolve, reject) => {
54
- pool.getConnection((err, connection) => {
55
- if (err)
56
- return reject(err);
57
- const query = (sql) => {
58
- return new Promise((resolve, reject) => {
59
- connection.query(sql, (err, result) => {
60
- if (err)
61
- return reject(err);
62
- return resolve(result);
63
- });
64
- });
65
- };
66
- const startTransaction = () => query('START TRANSACTION');
67
- const commit = () => query('COMMIT');
68
- const rollback = () => query('ROLLBACK');
69
- return resolve({
70
- query,
71
- startTransaction,
72
- commit,
73
- rollback
74
- });
75
- });
76
- });
77
- }
78
- };
79
- }
80
- _defaultOptions() {
81
- return new Map(Object.entries({
82
- connectionLimit: Number(options_1.default.CONNECTION_LIMIT),
83
- dateStrings: Boolean(options_1.default.DATE_STRINGS),
84
- connectTimeout: Number(options_1.default.TIMEOUT),
85
- waitForConnections: Boolean(options_1.default.WAIT_FOR_CONNECTIONS),
86
- queueLimit: Number(options_1.default.QUEUE_LIMIT),
87
- charset: String(options_1.default.CHARSET),
88
- host: String(options_1.default.HOST),
89
- port: Number.isNaN(Number(options_1.default.PORT))
90
- ? 3306
91
- : Number(options_1.default.PORT),
92
- database: String(options_1.default.DATABASE),
93
- user: String(options_1.default.USERNAME),
94
- password: String(options_1.default.PASSWORD) !== ''
95
- ? String(options_1.default.PASSWORD)
96
- : ''
97
- }));
98
- }
99
- _loadOptions() {
100
- try {
101
- /**
102
- *
103
- * @Json connection
104
- *
105
- "host" : "",
106
- "port" : "",
107
- "database" : "",
108
- "user" : "",
109
- "password" : "",
110
- "connectionLimit" : "",
111
- "dateStrings" : "",
112
- "idleTimeout" : "",
113
- "waitForConnections" : "",
114
- "queueLimit" : "",
115
- "charset" : ""
116
- */
117
- const jsonPath = path_1.default.join(path_1.default.resolve(), 'tspace-mysql.json');
118
- const jsonOptionsExists = fs_1.default.existsSync(jsonPath);
119
- if (!jsonOptionsExists)
120
- return this._defaultOptions();
121
- const jsonOptions = fs_1.default.readFileSync(jsonPath, 'utf8');
122
- const options = JSON.parse(jsonOptions);
123
- return new Map(Object.entries(options));
124
- }
125
- catch (e) {
126
- return this._defaultOptions();
127
- }
128
- }
129
- _messageError() {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Pool = exports.PoolConnection = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const options_1 = __importDefault(require("./options"));
10
+ const mysql2_1 = require("mysql2");
11
+ class PoolConnection {
12
+ /**
13
+ *
14
+ * @Init a options connection pool
15
+ */
16
+ constructor(options) {
17
+ this.OPTIONS = this._loadOptions();
18
+ if (options) {
19
+ this.OPTIONS = new Map(Object.entries(Object.assign(Object.assign({}, Object.fromEntries(this.OPTIONS)), JSON.parse(JSON.stringify(options)))));
20
+ }
21
+ }
22
+ /**
23
+ *
24
+ * Get a connection to database
25
+ * @return {Connection} Connection
26
+ * @property {Function} Connection.query
27
+ * @property {Function} Connection.connection
28
+ */
29
+ connection() {
30
+ const pool = (0, mysql2_1.createPool)(Object.fromEntries(this.OPTIONS));
31
+ if (options_1.default.CONNECTION_ERROR) {
32
+ pool.getConnection((err, _) => {
33
+ if (err == null || !err)
34
+ return;
35
+ const message = this._messageError.bind(this);
36
+ process.nextTick(() => {
37
+ console.log(message());
38
+ return process.exit();
39
+ });
40
+ });
41
+ }
42
+ return {
43
+ query: (sql) => {
44
+ return new Promise((resolve, reject) => {
45
+ pool.query(sql, (err, results) => {
46
+ if (err)
47
+ return reject(err);
48
+ return resolve(results);
49
+ });
50
+ });
51
+ },
52
+ connection: () => {
53
+ return new Promise((resolve, reject) => {
54
+ pool.getConnection((err, connection) => {
55
+ if (err)
56
+ return reject(err);
57
+ const query = (sql) => {
58
+ return new Promise((resolve, reject) => {
59
+ connection.query(sql, (err, result) => {
60
+ if (err)
61
+ return reject(err);
62
+ return resolve(result);
63
+ });
64
+ });
65
+ };
66
+ const startTransaction = () => query('START TRANSACTION');
67
+ const commit = () => query('COMMIT');
68
+ const rollback = () => query('ROLLBACK');
69
+ return resolve({
70
+ query,
71
+ startTransaction,
72
+ commit,
73
+ rollback
74
+ });
75
+ });
76
+ });
77
+ }
78
+ };
79
+ }
80
+ _defaultOptions() {
81
+ return new Map(Object.entries({
82
+ connectionLimit: Number(options_1.default.CONNECTION_LIMIT),
83
+ dateStrings: Boolean(options_1.default.DATE_STRINGS),
84
+ connectTimeout: Number(options_1.default.TIMEOUT),
85
+ waitForConnections: Boolean(options_1.default.WAIT_FOR_CONNECTIONS),
86
+ queueLimit: Number(options_1.default.QUEUE_LIMIT),
87
+ multipleStatements: true,
88
+ charset: String(options_1.default.CHARSET),
89
+ host: String(options_1.default.HOST),
90
+ port: Number.isNaN(Number(options_1.default.PORT))
91
+ ? 3306
92
+ : Number(options_1.default.PORT),
93
+ database: String(options_1.default.DATABASE),
94
+ user: String(options_1.default.USERNAME),
95
+ password: String(options_1.default.PASSWORD) !== ''
96
+ ? String(options_1.default.PASSWORD)
97
+ : ''
98
+ }));
99
+ }
100
+ _loadOptions() {
101
+ try {
102
+ /**
103
+ *
104
+ * @Json connection
105
+ *
106
+ "host" : "",
107
+ "port" : "",
108
+ "database" : "",
109
+ "user" : "",
110
+ "password" : "",
111
+ "connectionLimit" : "",
112
+ "dateStrings" : "",
113
+ "idleTimeout" : "",
114
+ "waitForConnections" : "",
115
+ "queueLimit" : "",
116
+ "charset" : ""
117
+ */
118
+ const jsonPath = path_1.default.join(path_1.default.resolve(), 'tspace-mysql.json');
119
+ const jsonOptionsExists = fs_1.default.existsSync(jsonPath);
120
+ if (!jsonOptionsExists)
121
+ return this._defaultOptions();
122
+ const jsonOptions = fs_1.default.readFileSync(jsonPath, 'utf8');
123
+ const options = JSON.parse(jsonOptions);
124
+ return new Map(Object.entries(options));
125
+ }
126
+ catch (e) {
127
+ return this._defaultOptions();
128
+ }
129
+ }
130
+ _messageError() {
130
131
  return `
131
132
  \x1b[1m\x1b[31m
132
133
  Connection lost to database ! \x1b[0m
@@ -137,17 +138,17 @@ class PoolConnection {
137
138
  USERNAME : ${this.OPTIONS.get('user')}
138
139
  PASSWORD : ${this.OPTIONS.get('password')} \x1b[0m
139
140
  ---------------------------------
140
- `;
141
- }
142
- }
143
- exports.PoolConnection = PoolConnection;
144
- /**
145
- *
146
- * Connection to database when service is started
147
- * @return {Connection} Connection
148
- * @property {Function} Connection.query
149
- * @property {Function} Connection.connection
150
- */
151
- const pool = new PoolConnection().connection();
152
- exports.Pool = pool;
153
- exports.default = pool;
141
+ `;
142
+ }
143
+ }
144
+ exports.PoolConnection = PoolConnection;
145
+ /**
146
+ *
147
+ * Connection to database when service is started
148
+ * @return {Connection} Connection
149
+ * @property {Function} Connection.query
150
+ * @property {Function} Connection.connection
151
+ */
152
+ const pool = new PoolConnection().connection();
153
+ exports.Pool = pool;
154
+ exports.default = pool;
@@ -1,4 +1,15 @@
1
- declare const _default: Readonly<{
2
- [x: string]: any;
3
- }>;
4
- export default _default;
1
+ declare const _default: Readonly<{
2
+ HOST?: string | null | undefined;
3
+ PORT?: string | number | undefined;
4
+ USERNAME?: string | undefined;
5
+ PASSWORD?: string | undefined;
6
+ DATABASE?: string | undefined;
7
+ CONNECTION_LIMIT?: string | number | undefined;
8
+ QUEUE_LIMIT?: string | number | undefined;
9
+ TIMEOUT?: string | number | undefined;
10
+ CHARSET?: string | undefined;
11
+ CONNECTION_ERROR?: string | boolean | undefined;
12
+ WAIT_FOR_CONNECTIONS?: string | boolean | undefined;
13
+ DATE_STRINGS?: string | boolean | undefined;
14
+ }>;
15
+ export default _default;
@@ -1,42 +1,43 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const dotenv_1 = __importDefault(require("dotenv"));
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const environment = () => {
10
- var _a;
11
- const NODE_ENV = (_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV;
12
- const env = path_1.default.join(path_1.default.resolve(), '.env');
13
- const envWithEnviroment = path_1.default.join(path_1.default.resolve(), `.env.${NODE_ENV}`);
14
- if (NODE_ENV == null)
15
- return env;
16
- if (fs_1.default.existsSync(envWithEnviroment))
17
- return envWithEnviroment;
18
- return env;
19
- };
20
- dotenv_1.default.config({ path: environment() });
21
- const env = {
22
- HOST: process.env.DB_HOST || process.env.TSPACE_HOST,
23
- PORT: process.env.DB_PORT || process.env.TSPACE_PORT || 3306,
24
- USERNAME: process.env.DB_USERNAME || process.env.TSPACE_USERNAME,
25
- PASSWORD: process.env.DB_PASSWORD || process.env.TSPACE_PASSWORD || '',
26
- DATABASE: process.env.DB_DATABASE || process.env.TSPACE_DATABASE,
27
- CONNECTION_LIMIT: process.env.DB_CONNECTION_LIMIT || process.env.TSPACE_CONNECTION_LIMIT || 10,
28
- QUEUE_LIMIT: process.env.DB_QUEUE_LIMIT || process.env.TSPACE_QUEUE_LIMIT || 0,
29
- TIMEOUT: process.env.DB_TIMEOUT || process.env.TSPACE_TIMEOUT || 1000 * 60,
30
- CHARSET: process.env.DB_CHARSET || process.env.TSPACE_CHARSET || 'utf8mb4',
31
- CONNECTION_ERROR: process.env.DB_CONNECTION_ERROR || process.env.TSPACE_CONNECTION_ERROR || true,
32
- WAIT_FOR_CONNECTIONS: process.env.DB_WAIT_FOR_CONNECTIONS || process.env.TSPACE_WAIT_FOR_CONNECTIONS || true,
33
- DATE_STRINGS: process.env.DB_DATE_STRINGS || process.env.TSPACE_DATE_STRINGS || true
34
- };
35
- for (const [key, value] of Object.entries(env)) {
36
- if (value == null)
37
- continue;
38
- if (typeof value === 'string' && ['true', 'false'].some(v => value.toLowerCase() === v)) {
39
- env[key] = JSON.parse(value.toLowerCase());
40
- }
41
- }
42
- exports.default = Object.freeze(Object.assign({}, env));
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const dotenv_1 = __importDefault(require("dotenv"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const environment = () => {
10
+ var _a;
11
+ const NODE_ENV = (_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV;
12
+ const env = path_1.default.join(path_1.default.resolve(), '.env');
13
+ if (NODE_ENV == null)
14
+ return env;
15
+ const envWithEnviroment = path_1.default.join(path_1.default.resolve(), `.env.${NODE_ENV}`);
16
+ if (fs_1.default.existsSync(envWithEnviroment))
17
+ return envWithEnviroment;
18
+ return env;
19
+ };
20
+ dotenv_1.default.config({ path: environment() });
21
+ const env = {
22
+ HOST: process.env.DB_HOST || process.env.TSPACE_HOST,
23
+ PORT: process.env.DB_PORT || process.env.TSPACE_PORT || 3306,
24
+ USERNAME: process.env.DB_USERNAME || process.env.TSPACE_USERNAME,
25
+ PASSWORD: process.env.DB_PASSWORD || process.env.TSPACE_PASSWORD || '',
26
+ DATABASE: process.env.DB_DATABASE || process.env.TSPACE_DATABASE,
27
+ CONNECTION_LIMIT: process.env.DB_CONNECTION_LIMIT || process.env.TSPACE_CONNECTION_LIMIT || 10,
28
+ QUEUE_LIMIT: process.env.DB_QUEUE_LIMIT || process.env.TSPACE_QUEUE_LIMIT || 0,
29
+ TIMEOUT: process.env.DB_TIMEOUT || process.env.TSPACE_TIMEOUT || 1000 * 60,
30
+ CHARSET: process.env.DB_CHARSET || process.env.TSPACE_CHARSET || 'utf8mb4',
31
+ CONNECTION_ERROR: process.env.DB_CONNECTION_ERROR || process.env.TSPACE_CONNECTION_ERROR || true,
32
+ WAIT_FOR_CONNECTIONS: process.env.DB_WAIT_FOR_CONNECTIONS || process.env.TSPACE_WAIT_FOR_CONNECTIONS || true,
33
+ DATE_STRINGS: process.env.DB_DATE_STRINGS || process.env.TSPACE_DATE_STRINGS || true
34
+ };
35
+ for (const [key, value] of Object.entries(env)) {
36
+ if (value == null)
37
+ continue;
38
+ if (typeof value === 'string' && ['true', 'false'].some(v => value.toLowerCase() === v)) {
39
+ const configEnv = env;
40
+ configEnv[key] = JSON.parse(value.toLowerCase());
41
+ }
42
+ }
43
+ exports.default = Object.freeze(Object.assign({}, env));
@@ -1,8 +1,5 @@
1
- declare const CONSTANTS: {
2
- [key: string]: string | Object;
3
- };
4
- export { CONSTANTS };
5
- declare const _default: Readonly<{
6
- [key: string]: string | Object;
7
- }>;
8
- export default _default;
1
+ declare const CONSTANTS: {
2
+ [key: string]: string | Object;
3
+ };
4
+ export { CONSTANTS };
5
+ export default CONSTANTS;