mielk-api 1.3.1 → 1.3.2
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/dist/db/pg/connection/pool.js +1 -1
- package/dist/http/apiResponse/apiResponse.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/middlewares/cors/cors.js +1 -1
- package/dist/middlewares/requestAuth/auth.middleware.js +1 -1
- package/dist/routing/DbProvider.d.ts +1 -0
- package/dist/routing/DbProvider.js +1 -0
- package/dist/routing/controllers/health.controller.js +1 -1
- package/dist/{express.d.ts → routing/express.d.ts} +5 -3
- package/dist/{express.js → routing/express.js} +7 -4
- package/dist/routing/repositories/mssql.repository.d.ts +2 -0
- package/dist/routing/repositories/mssql.repository.js +29 -0
- package/dist/routing/services/db.service.js +14 -3
- package/package.json +1 -1
- /package/dist/routing/repositories/{db.repository.d.ts → postgre.repository.d.ts} +0 -0
- /package/dist/routing/repositories/{db.repository.js → postgre.repository.js} +0 -0
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { Msg } from '../../../internal/messaging/messageTags.js';
|
|
11
11
|
import { Pool } from 'pg';
|
|
12
12
|
import { openSshTunnel } from './tunnel.js';
|
|
13
|
-
import { isProd } from '../../../express.js';
|
|
13
|
+
import { isProd } from '../../../routing/express.js';
|
|
14
14
|
let pool = null;
|
|
15
15
|
let config = null;
|
|
16
16
|
export const initDb = (dbConfig) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isObject, isPrimitive } from 'mielk-fn/variables';
|
|
2
2
|
import { HttpResponseStatus } from '../httpResponseStatus/HttpResponseStatus.js';
|
|
3
|
-
import { isProd } from '../../express.js';
|
|
3
|
+
import { isProd } from '../../routing/express.js';
|
|
4
4
|
export function success(res, status, data) {
|
|
5
5
|
const apiResponse = {
|
|
6
6
|
success: true,
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export * as mssql from './db/mssql/index.js';
|
|
|
3
3
|
export * as http from './http/index.js';
|
|
4
4
|
export { dbRouter } from './routing/routes/db.route.js';
|
|
5
5
|
export { healthRouter } from './routing/routes/health.route.js';
|
|
6
|
-
export { createExpressApp } from './express.js';
|
|
6
|
+
export { createExpressApp } from './routing/express.js';
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,4 @@ export * as mssql from './db/mssql/index.js';
|
|
|
3
3
|
export * as http from './http/index.js';
|
|
4
4
|
export { dbRouter } from './routing/routes/db.route.js';
|
|
5
5
|
export { healthRouter } from './routing/routes/health.route.js';
|
|
6
|
-
export { createExpressApp } from './express.js';
|
|
6
|
+
export { createExpressApp } from './routing/express.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpResponseStatus } from '../../http/httpResponseStatus/HttpResponseStatus.js';
|
|
2
2
|
import { Msg } from '../../internal/messaging/messageTags.js';
|
|
3
|
-
import { isProd } from '../../express.js';
|
|
3
|
+
import { isProd } from '../../routing/express.js';
|
|
4
4
|
import { failure } from '../../http/index.js';
|
|
5
5
|
import { apiKey } from '../cors/cors.js';
|
|
6
6
|
export function apiKeyAuthorization(req, res, next) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DbProvider = 'postgre' | 'mssql' | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpResponseStatus, success } from '../../http/index.js';
|
|
2
|
-
import { isProd } from '
|
|
2
|
+
import { isProd } from '../express.js';
|
|
3
3
|
export const getHealth = (_req, res) => {
|
|
4
4
|
return success(res, HttpResponseStatus.OK, new Date().toISOString());
|
|
5
5
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { PostgreDbConfig } from '
|
|
2
|
-
import { MsSqlDbConfig } from '
|
|
3
|
-
import { CorsConfig, RateLimitConfig } from '
|
|
1
|
+
import { PostgreDbConfig } from '../db/pg/index.js';
|
|
2
|
+
import { MsSqlDbConfig } from '../db/mssql/index.js';
|
|
3
|
+
import { CorsConfig, RateLimitConfig } from '../middlewares/index.js';
|
|
4
|
+
import { DbProvider } from './DbProvider.js';
|
|
4
5
|
export type DbConfig = PostgreDbConfig | MsSqlDbConfig;
|
|
5
6
|
export declare const createExpressApp: (isProd: boolean, dbConfig: DbConfig, corsConfig: CorsConfig, rateLimitConfig?: RateLimitConfig) => import("express-serve-static-core").Express;
|
|
6
7
|
export declare const isProd: () => boolean;
|
|
8
|
+
export declare const getDbProvider: () => DbProvider;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import { initDb as postgreInitDb } from '
|
|
3
|
-
import { initDb as msSqlInitDb } from '
|
|
4
|
-
import { initCors, setRateLimit } from '
|
|
2
|
+
import { initDb as postgreInitDb } from '../db/pg/index.js';
|
|
3
|
+
import { initDb as msSqlInitDb } from '../db/mssql/index.js';
|
|
4
|
+
import { initCors, setRateLimit } from '../middlewares/index.js';
|
|
5
5
|
const env = {
|
|
6
|
-
isProd: true
|
|
6
|
+
isProd: true,
|
|
7
|
+
provider: undefined
|
|
7
8
|
};
|
|
8
9
|
export const createExpressApp = (isProd, dbConfig, corsConfig, rateLimitConfig) => {
|
|
9
10
|
const app = express();
|
|
10
11
|
env.isProd = isProd;
|
|
12
|
+
env.provider = dbConfig.provider;
|
|
11
13
|
switch (dbConfig.provider) {
|
|
12
14
|
case 'mssql':
|
|
13
15
|
msSqlInitDb(dbConfig);
|
|
@@ -22,3 +24,4 @@ export const createExpressApp = (isProd, dbConfig, corsConfig, rateLimitConfig)
|
|
|
22
24
|
return app;
|
|
23
25
|
};
|
|
24
26
|
export const isProd = () => env.isProd;
|
|
27
|
+
export const getDbProvider = () => env.provider;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
import { query } from '../../db/mssql/connection/pool.js';
|
|
12
|
+
export function selectDatabaseTime() {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const field = 'timestamp';
|
|
15
|
+
const rows = yield query(`SELECT SYSDATETIME() AS [${field}]`);
|
|
16
|
+
const row = rows[0];
|
|
17
|
+
const value = row[field];
|
|
18
|
+
return value;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function selectDatabaseVersion() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const field = 'version';
|
|
24
|
+
const rows = yield query(`SELECT @@VERSION AS [${field}]`);
|
|
25
|
+
const row = rows[0];
|
|
26
|
+
const value = row[field];
|
|
27
|
+
return value;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -7,14 +7,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import * as
|
|
10
|
+
import * as postgreRepository from '../repositories/postgre.repository.js';
|
|
11
|
+
import * as msSqlRepository from '../repositories/mssql.repository.js';
|
|
12
|
+
import { getDbProvider } from '../express.js';
|
|
13
|
+
import { Msg } from '../../internal/messaging/messageTags.js';
|
|
14
|
+
const provider = getDbProvider();
|
|
15
|
+
const repository = provider === 'postgre' ? postgreRepository : provider === 'mssql' ? msSqlRepository : undefined;
|
|
11
16
|
export function getDatabaseTime() {
|
|
12
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
|
|
18
|
+
if (repository) {
|
|
19
|
+
return repository.selectDatabaseTime();
|
|
20
|
+
}
|
|
21
|
+
throw new Error(Msg.connection.notInitialized);
|
|
14
22
|
});
|
|
15
23
|
}
|
|
16
24
|
export function getDatabaseVersion() {
|
|
17
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
|
|
26
|
+
if (repository) {
|
|
27
|
+
return repository.selectDatabaseVersion();
|
|
28
|
+
}
|
|
29
|
+
throw new Error(Msg.connection.notInitialized);
|
|
19
30
|
});
|
|
20
31
|
}
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|