@creator.co/wapi 1.4.0-alpha5 → 1.5.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/dist/index.d.ts +22 -14
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/package.json +2 -1
- package/dist/src/Cache/Redis.d.ts +34 -0
- package/dist/src/Cache/Redis.js +127 -0
- package/dist/src/Cache/Redis.js.map +1 -0
- package/dist/src/Cache/types.d.ts +30 -0
- package/dist/src/Cache/types.js +3 -0
- package/dist/src/Cache/types.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +1 -6
- package/dist/src/Database/DatabaseManager.js +1 -1
- package/dist/src/Database/DatabaseManager.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +2 -2
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +5 -6
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
- package/dist/src/Server/lib/Server.js +0 -1
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/index.ts +22 -13
- package/package.json +2 -1
- package/src/Cache/Redis.ts +65 -0
- package/src/Cache/types.ts +32 -0
- package/src/Database/DatabaseManager.ts +1 -1
- package/src/Database/integrations/knex/KnexDatabase.ts +1 -1
- package/src/Database/integrations/kysely/KyselyDatabase.ts +4 -4
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +1 -1
- package/src/Server/lib/Server.ts +0 -1
- package/tests/Cache/Redis.test.ts +98 -0
- package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +8 -5
- package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import Utils from './src/API/Utils';
|
|
|
4
4
|
import EventProcessor from './src/BaseEvent/EventProcessor';
|
|
5
5
|
import Process from './src/BaseEvent/Process';
|
|
6
6
|
import Transaction from './src/BaseEvent/Transaction';
|
|
7
|
+
import Redis from './src/Cache/Redis';
|
|
7
8
|
import Configuration from './src/Config/Configuration';
|
|
8
9
|
import Crypto from './src/Crypto/Crypto';
|
|
9
10
|
import JWT from './src/Crypto/JWT';
|
|
@@ -11,18 +12,25 @@ import * as Database from './src/Database';
|
|
|
11
12
|
import Mailer from './src/Mailer/Mailer';
|
|
12
13
|
import Router, { Route } from './src/Server/Router';
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
15
|
+
* This module exports various classes and utilities for handling transactions, processes, events, routing,
|
|
16
|
+
* mailing, cryptography, JWT, configuration, Redis, responses, utilities, routes, response error types,
|
|
17
|
+
* HTTP methods, and databases.
|
|
18
|
+
* @exports {
|
|
19
|
+
* Transaction,
|
|
20
|
+
* Process,
|
|
21
|
+
* EventProcessor,
|
|
22
|
+
* Router,
|
|
23
|
+
* Mailer,
|
|
24
|
+
* Crypto,
|
|
25
|
+
* JWT,
|
|
26
|
+
* Configuration,
|
|
27
|
+
* Redis,
|
|
28
|
+
* Response,
|
|
29
|
+
* Utils,
|
|
30
|
+
* Route,
|
|
31
|
+
* ResponseErrorType,
|
|
32
|
+
* HttpMethod,
|
|
33
|
+
* Database,
|
|
34
|
+
* }
|
|
27
35
|
*/
|
|
28
|
-
export { Transaction, Process, EventProcessor, Router, Mailer, Crypto, JWT, Configuration, Response, Utils, Route, ResponseErrorType, HttpMethod, Database, };
|
|
36
|
+
export { Transaction, Process, EventProcessor, Router, Mailer, Crypto, JWT, Configuration, Redis, Response, Utils, Route, ResponseErrorType, HttpMethod, Database, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Database = exports.HttpMethod = exports.Utils = exports.Response = exports.Configuration = exports.JWT = exports.Crypto = exports.Mailer = exports.Router = exports.EventProcessor = exports.Process = exports.Transaction = void 0;
|
|
3
|
+
exports.Database = exports.HttpMethod = exports.Utils = exports.Response = exports.Redis = exports.Configuration = exports.JWT = exports.Crypto = exports.Mailer = exports.Router = exports.EventProcessor = exports.Process = exports.Transaction = void 0;
|
|
4
4
|
var Request_1 = require("./src/API/Request");
|
|
5
5
|
Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function () { return Request_1.HttpMethod; } });
|
|
6
6
|
var Response_1 = require("./src/API/Response");
|
|
@@ -13,6 +13,8 @@ var Process_1 = require("./src/BaseEvent/Process");
|
|
|
13
13
|
exports.Process = Process_1.default;
|
|
14
14
|
var Transaction_1 = require("./src/BaseEvent/Transaction");
|
|
15
15
|
exports.Transaction = Transaction_1.default;
|
|
16
|
+
var Redis_1 = require("./src/Cache/Redis");
|
|
17
|
+
exports.Redis = Redis_1.default;
|
|
16
18
|
var Configuration_1 = require("./src/Config/Configuration");
|
|
17
19
|
exports.Configuration = Configuration_1.default;
|
|
18
20
|
var Crypto_1 = require("./src/Crypto/Crypto");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAA8C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAA8C;AAuD5C,2FAvDO,oBAAU,OAuDP;AAtDZ,+CAAgE;AAgD9D,mBAhDK,kBAAQ,CAgDL;AA/CV,yCAAmC;AAiDjC,gBAjDK,eAAK,CAiDL;AAhDP,iEAA2D;AAqCzD,yBArCK,wBAAc,CAqCL;AApChB,mDAA6C;AAmC3C,kBAnCK,iBAAO,CAmCL;AAlCT,2DAAqD;AAiCnD,sBAjCK,qBAAW,CAiCL;AAhCb,2CAAqC;AAyCnC,gBAzCK,eAAK,CAyCL;AAxCP,4DAAsD;AAuCpD,wBAvCK,uBAAa,CAuCL;AAtCf,8CAAwC;AAoCtC,iBApCK,gBAAM,CAoCL;AAnCR,wCAAkC;AAoChC,cApCK,aAAG,CAoCL;AAnCL,yCAA0C;AA8CxC,4BAAQ;AA7CV,8CAAwC;AAgCtC,iBAhCK,gBAAM,CAgCL;AA/BR,8CAAmD;AA6BjD,iBA7BK,gBAAM,CA6BL"}
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creator.co/wapi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"parse-duration": "^1.1.0",
|
|
42
42
|
"path-to-regexp": "^6.2.1",
|
|
43
43
|
"pg": "^8.11.3",
|
|
44
|
+
"redis": "^4.6.13",
|
|
44
45
|
"sha1": "^1.1.1",
|
|
45
46
|
"stack-trace": "0.0.10",
|
|
46
47
|
"zod": "^3.22.4"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { RedisClientType } from 'redis';
|
|
2
|
+
import { CacheConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a Redis cache connection class.
|
|
5
|
+
*/
|
|
6
|
+
export default class Redis {
|
|
7
|
+
/**
|
|
8
|
+
* Private static property that holds the connection to a Redis client.
|
|
9
|
+
* @type {RedisClientType}
|
|
10
|
+
*/
|
|
11
|
+
private static _connection;
|
|
12
|
+
/**
|
|
13
|
+
* A private static property that holds a reference to the redis.createClient function.
|
|
14
|
+
* This property is used to create client.
|
|
15
|
+
*/
|
|
16
|
+
private static ClientFactory;
|
|
17
|
+
private static awaitingConnectionQueue;
|
|
18
|
+
/**
|
|
19
|
+
* Establishes a connection to a Redis cache based on the provided configuration.
|
|
20
|
+
* If a connection is already established, it returns the existing connection.
|
|
21
|
+
* If a connection is pending, it waits for the connection to be established and then returns it.
|
|
22
|
+
* @param {CacheConfig<'redis'>} config - The configuration object for connecting to Redis cache.
|
|
23
|
+
* @returns {Promise<RedisClientType>} A promise that resolves to the Redis client once the connection is established.
|
|
24
|
+
*/
|
|
25
|
+
static connection(config: CacheConfig<'redis'>): Promise<RedisClientType>;
|
|
26
|
+
/**
|
|
27
|
+
* Establishes a connection to a Redis client based on the provided configuration
|
|
28
|
+
* and holds it for reusability. If connection is detected closed, new connection is
|
|
29
|
+
* initialized and established.
|
|
30
|
+
* @param {CacheConfig<'redis'>} config - The configuration object for connecting to the Redis client.
|
|
31
|
+
* @returns {Promise<RedisClientType>} A promise that resolves to the Redis client connection.
|
|
32
|
+
*/
|
|
33
|
+
private static redisConnection;
|
|
34
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
var redis_1 = require("redis");
|
|
51
|
+
/**
|
|
52
|
+
* Represents a Redis cache connection class.
|
|
53
|
+
*/
|
|
54
|
+
var Redis = /** @class */ (function () {
|
|
55
|
+
function Redis() {
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Establishes a connection to a Redis cache based on the provided configuration.
|
|
59
|
+
* If a connection is already established, it returns the existing connection.
|
|
60
|
+
* If a connection is pending, it waits for the connection to be established and then returns it.
|
|
61
|
+
* @param {CacheConfig<'redis'>} config - The configuration object for connecting to Redis cache.
|
|
62
|
+
* @returns {Promise<RedisClientType>} A promise that resolves to the Redis client once the connection is established.
|
|
63
|
+
*/
|
|
64
|
+
Redis.connection = function (config) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var con;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
// No connection, but waiting connection queue is valid? wait until other promise
|
|
71
|
+
// fulfill this promise
|
|
72
|
+
if (!Redis._connection && Redis.awaitingConnectionQueue) {
|
|
73
|
+
return [2 /*return*/, new Promise(function (resolve) { return Redis.awaitingConnectionQueue.push(resolve); })];
|
|
74
|
+
}
|
|
75
|
+
else if (Redis._connection)
|
|
76
|
+
return [2 /*return*/, Redis._connection
|
|
77
|
+
// Connect
|
|
78
|
+
]; //already connected
|
|
79
|
+
// Connect
|
|
80
|
+
Redis.awaitingConnectionQueue = [];
|
|
81
|
+
return [4 /*yield*/, Redis.redisConnection(config)];
|
|
82
|
+
case 1:
|
|
83
|
+
con = _a.sent();
|
|
84
|
+
if (Redis.awaitingConnectionQueue) {
|
|
85
|
+
Redis.awaitingConnectionQueue.forEach(function (resolve) { return resolve(con); });
|
|
86
|
+
}
|
|
87
|
+
Redis.awaitingConnectionQueue = null;
|
|
88
|
+
return [2 /*return*/, con];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Establishes a connection to a Redis client based on the provided configuration
|
|
95
|
+
* and holds it for reusability. If connection is detected closed, new connection is
|
|
96
|
+
* initialized and established.
|
|
97
|
+
* @param {CacheConfig<'redis'>} config - The configuration object for connecting to the Redis client.
|
|
98
|
+
* @returns {Promise<RedisClientType>} A promise that resolves to the Redis client connection.
|
|
99
|
+
*/
|
|
100
|
+
Redis.redisConnection = function (config) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
var connection;
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
if (Redis._connection && Redis._connection.isOpen)
|
|
107
|
+
return [2 /*return*/, Redis._connection];
|
|
108
|
+
console.debug('Starting remote cache connection');
|
|
109
|
+
connection = Redis.ClientFactory(__assign(__assign({ username: config.username }, (config.password ? { password: config.password } : {})), { disableOfflineQueue: true, socket: __assign(__assign({ host: config.hostname }, (config.enableTLS ? { tls: true } : {})), { connectTimeout: 10000 }) }));
|
|
110
|
+
return [4 /*yield*/, connection.connect()];
|
|
111
|
+
case 1:
|
|
112
|
+
_a.sent();
|
|
113
|
+
Redis._connection = connection;
|
|
114
|
+
return [2 /*return*/, Redis._connection];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* A private static property that holds a reference to the redis.createClient function.
|
|
121
|
+
* This property is used to create client.
|
|
122
|
+
*/
|
|
123
|
+
Redis.ClientFactory = redis_1.createClient;
|
|
124
|
+
return Redis;
|
|
125
|
+
}());
|
|
126
|
+
exports.default = Redis;
|
|
127
|
+
//# sourceMappingURL=Redis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Redis.js","sourceRoot":"","sources":["../../../src/Cache/Redis.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAqD;AAGrD;;GAEG;AACH;IAAA;IA0DA,CAAC;IA9CC;;;;;;OAMG;IACiB,gBAAU,GAA9B,UAA+B,MAA4B;;;;;;wBACzD,iFAAiF;wBACjF,uBAAuB;wBACvB,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,uBAAuB,EAAE,CAAC;4BACxD,sBAAO,IAAI,OAAO,CAAC,UAAA,OAAO,IAAI,OAAA,KAAK,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,EAA3C,CAA2C,CAAC,EAAA;wBAC5E,CAAC;6BAAM,IAAI,KAAK,CAAC,WAAW;4BAAE,sBAAO,KAAK,CAAC,WAAW;gCACtD,UAAU;8BAD4C,CAAC,mBAAmB;wBAC1E,UAAU;wBACV,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAA;wBACtB,qBAAM,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAA;;wBAAzC,GAAG,GAAG,SAAmC;wBAC/C,IAAI,KAAK,CAAC,uBAAuB,EAAE,CAAC;4BAClC,KAAK,CAAC,uBAAuB,CAAC,OAAO,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,GAAG,CAAC,EAAZ,CAAY,CAAC,CAAA;wBAChE,CAAC;wBACD,KAAK,CAAC,uBAAuB,GAAG,IAAI,CAAA;wBACpC,sBAAO,GAAG,EAAA;;;;KACX;IACD;;;;;;OAMG;IACkB,qBAAe,GAApC,UAAqC,MAA4B;;;;;;wBAC/D,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,CAAC,MAAM;4BAAE,sBAAO,KAAK,CAAC,WAAW,EAAA;wBAC3E,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAA;wBAC3C,UAAU,GAAG,KAAK,CAAC,aAAa,qBACpC,QAAQ,EAAE,MAAM,CAAC,QAAQ,IACtB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KACzD,mBAAmB,EAAE,IAAI,EACzB,MAAM,sBACJ,IAAI,EAAE,MAAM,CAAC,QAAQ,IAClB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAC1C,cAAc,EAAE,KAAK,OAEvB,CAAA;wBACF,qBAAM,UAAU,CAAC,OAAO,EAAE,EAAA;;wBAA1B,SAA0B,CAAA;wBAC1B,KAAK,CAAC,WAAW,GAAG,UAAiB,CAAA;wBACrC,sBAAO,KAAK,CAAC,WAAW,EAAA;;;;KACzB;IAnDD;;;OAGG;IACY,mBAAa,GAAG,oBAAY,CAAA;IAgD7C,YAAC;CAAA,AA1DD,IA0DC;kBA1DoB,KAAK"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Redis from './Redis';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a type alias for specifying the cache type as 'redis'.
|
|
4
|
+
*/
|
|
5
|
+
export type CacheType = 'redis';
|
|
6
|
+
/**
|
|
7
|
+
* Defines a CacheClass type that has a 'redis' property which is a constructor function
|
|
8
|
+
* that takes in any number of arguments and returns an instance of Redis.
|
|
9
|
+
*/
|
|
10
|
+
export type CacheClass = {
|
|
11
|
+
redis: new (...args: any[]) => Redis;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents the base configuration for a cache, including host, username, password, and TLS settings.
|
|
15
|
+
*/
|
|
16
|
+
export type CacheBaseConfig = {
|
|
17
|
+
hostname: string;
|
|
18
|
+
username: string;
|
|
19
|
+
password?: string;
|
|
20
|
+
enableTLS: boolean;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Defines a CacheConfig type that extends CacheBaseConfig and includes a specific cache type.
|
|
24
|
+
* @template S - The specific cache type to be included in the CacheConfig.
|
|
25
|
+
* @extends CacheBaseConfig
|
|
26
|
+
* @property {S} type - The specific cache type included in the CacheConfig.
|
|
27
|
+
*/
|
|
28
|
+
export type CacheConfig<S extends CacheType> = CacheBaseConfig & {
|
|
29
|
+
type: S;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/Cache/types.ts"],"names":[],"mappings":""}
|
|
@@ -12,12 +12,7 @@ import type { DatabaseImplType, DatabaseType, DbConfig } from './types';
|
|
|
12
12
|
export declare const DATABASES: {
|
|
13
13
|
knex: typeof KnexDatabase;
|
|
14
14
|
pg: typeof PostgresDatabase;
|
|
15
|
-
kysely:
|
|
16
|
-
new (config: DbConfig<"kysely">): KyselyDatabase<any>;
|
|
17
|
-
kyselyPgProvider: typeof import("kysely").PostgresDialect;
|
|
18
|
-
kyselyProvider: typeof import("kysely").Kysely;
|
|
19
|
-
pgProvider: typeof import("pg").Pool;
|
|
20
|
-
};
|
|
15
|
+
kysely: typeof KyselyDatabase;
|
|
21
16
|
};
|
|
22
17
|
/**
|
|
23
18
|
* Manages the creation and storage of database instances.
|
|
@@ -15,7 +15,7 @@ var PostgresDatabase_1 = require("./integrations/pgsql/PostgresDatabase");
|
|
|
15
15
|
exports.DATABASES = {
|
|
16
16
|
knex: KnexDatabase_1.KnexDatabase,
|
|
17
17
|
pg: PostgresDatabase_1.PostgresDatabase,
|
|
18
|
-
kysely:
|
|
18
|
+
kysely: KyselyDatabase_1.KyselyDatabase,
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* Manages the creation and storage of database instances.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseManager.js","sourceRoot":"","sources":["../../../src/Database/DatabaseManager.ts"],"names":[],"mappings":";;;AAAA,kCAAmC;AAEnC,iEAA+D;AAC/D,uEAAqE;AACrE,0EAAwE;AAGxE;;;;;;GAMG;AACU,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,2BAAY;IAClB,EAAE,EAAE,mCAAgB;IACpB,MAAM,EAAE
|
|
1
|
+
{"version":3,"file":"DatabaseManager.js","sourceRoot":"","sources":["../../../src/Database/DatabaseManager.ts"],"names":[],"mappings":";;;AAAA,kCAAmC;AAEnC,iEAA+D;AAC/D,uEAAqE;AACrE,0EAAwE;AAGxE;;;;;;GAMG;AACU,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,2BAAY;IAClB,EAAE,EAAE,mCAAgB;IACpB,MAAM,EAAE,+BAAc;CACvB,CAAA;AAED;;GAEG;AACH;IAAA;QAME;;;WAGG;QACK,cAAS,GAAqB,iBAAS,CAAA;QAC/C;;;WAGG;QACK,cAAS,GAAgD,EAAE,CAAA;IA6BrE,CAAC;IA3BC;;;;OAIG;IACI,gCAAM,GAAb,UACE,MAAmB;QAEnB,IAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;QAC/B,IAAI,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAQ,CAAA;QAC1C,CAAC;QACD,IAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAc,MAAa,CAAC,CAAA;QAC/D,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAA;QACrC,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED;;;;OAIG;IACK,uCAAa,GAArB,UACE,MAA8D;QAE9D,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAa,CAAQ,CAAA;IAC9D,CAAC;IA1CD;;;OAGG;IACoB,wBAAQ,GAAG,IAAI,eAAe,EAAE,AAAxB,CAAwB;IAuCzD,sBAAC;CAAA,AA5CD,IA4CC;AA5CY,0CAAe"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
2
|
import { KnexTransaction } from './KnexTransaction';
|
|
3
3
|
import { Database } from '../../Database';
|
|
4
4
|
import type { DbConfig } from '../../types';
|
|
@@ -11,7 +11,7 @@ export declare class KnexDatabase extends Database<KnexTransaction> {
|
|
|
11
11
|
* @param {knex.Knex.Config<any>} config - The configuration object for Knex.
|
|
12
12
|
* @returns {knex.Knex<any, unknown[]>} A Knex instance based on the provided configuration.
|
|
13
13
|
*/
|
|
14
|
-
static knexProvider
|
|
14
|
+
private static knexProvider;
|
|
15
15
|
/**
|
|
16
16
|
* Represents a Knex client for interacting with a database.
|
|
17
17
|
* @type {Knex}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnexDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/knex/KnexDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAiC;AACjC,gDAAiD;AAEjD,qDAAwE;AACxE,2CAAyC;AAGzC;;GAEG;AACH;IAAkC,gCAAyB;IAazD;;;;OAIG;IACH,sBAAmB,MAAwB;QACzC,YAAA,MAAK,YAAC,MAAM,CAAC,SAAA;QAEb,KAAI,CAAC,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,KAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAA;;IACvE,CAAC;IAED;;;;OAIG;IACK,sCAAe,GAAvB,UAAwB,MAAwB;QAC9C,IAAM,UAAU,GAAG;YACjB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,UAAU,EAAE;gBACV,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B;YACD,IAAI,EAAE;gBACJ,GAAG,EAAE,CAAC;gBACN,GAAG,EAAE,MAAM,CAAC,cAAc;aAC3B;SACF,CAAA;QAED,OAAO,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;IAC7E,CAAC;IAED;;;OAGG;IACmB,kCAAW,GAAjC;;;;4BACS,qBAAM,qCAAmB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAA;4BAAlE,sBAAO,SAA2D,EAAA;;;;KACnE;IArDD;;;;OAIG;
|
|
1
|
+
{"version":3,"file":"KnexDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/knex/KnexDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAiC;AACjC,gDAAiD;AAEjD,qDAAwE;AACxE,2CAAyC;AAGzC;;GAEG;AACH;IAAkC,gCAAyB;IAazD;;;;OAIG;IACH,sBAAmB,MAAwB;QACzC,YAAA,MAAK,YAAC,MAAM,CAAC,SAAA;QAEb,KAAI,CAAC,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,KAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAA;;IACvE,CAAC;IAED;;;;OAIG;IACK,sCAAe,GAAvB,UAAwB,MAAwB;QAC9C,IAAM,UAAU,GAAG;YACjB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,UAAU,EAAE;gBACV,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B;YACD,IAAI,EAAE;gBACJ,GAAG,EAAE,CAAC;gBACN,GAAG,EAAE,MAAM,CAAC,cAAc;aAC3B;SACF,CAAA;QAED,OAAO,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;IAC7E,CAAC;IAED;;;OAGG;IACmB,kCAAW,GAAjC;;;;4BACS,qBAAM,qCAAmB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAA;4BAAlE,sBAAO,SAA2D,EAAA;;;;KACnE;IArDD;;;;OAIG;IACY,yBAAY,GAAiE,cAAI,CAAA;IAiDlG,mBAAC;CAAA,AAvDD,CAAkC,mBAAQ,GAuDzC;AAvDY,oCAAY"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Kysely
|
|
2
|
-
import { Pool } from 'pg';
|
|
1
|
+
import { Kysely } from 'kysely';
|
|
3
2
|
import { KyselyTransaction } from './KyselyTransaction';
|
|
4
3
|
import { Database } from '../../Database';
|
|
5
4
|
import type { DbConfig } from '../../types';
|
|
@@ -7,22 +6,22 @@ import type { DbConfig } from '../../types';
|
|
|
7
6
|
* Represents a database connection using the Kysely library with support for transactions.
|
|
8
7
|
* @template DBSchema - The schema type for the database.
|
|
9
8
|
*/
|
|
10
|
-
export declare class KyselyDatabase<DBSchema> extends Database<KyselyTransaction<DBSchema>> {
|
|
9
|
+
export declare class KyselyDatabase<DBSchema = never> extends Database<KyselyTransaction<DBSchema>> {
|
|
11
10
|
/**
|
|
12
11
|
* Represents a PostgreSQL provider for querying data using the PostgresDialect.
|
|
13
12
|
* @type {PostgresDialect}
|
|
14
13
|
*/
|
|
15
|
-
static kyselyPgProvider
|
|
14
|
+
private static kyselyPgProvider;
|
|
16
15
|
/**
|
|
17
16
|
* A public static property that provides access to the Kysely class.
|
|
18
17
|
* This property can be accessed without creating an instance of the class.
|
|
19
18
|
*/
|
|
20
|
-
static kyselyProvider
|
|
19
|
+
private static kyselyProvider;
|
|
21
20
|
/**
|
|
22
21
|
* A static property that represents a connection pool for PostgreSQL database connections.
|
|
23
22
|
* @type {Pool}
|
|
24
23
|
*/
|
|
25
|
-
static pgProvider
|
|
24
|
+
private static pgProvider;
|
|
26
25
|
/**
|
|
27
26
|
* Represents a PostgreSQL client using the PostgresDialect.
|
|
28
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KyselyDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/kysely/KyselyDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAiE;AACjE,yBAAyB;AAEzB,yDAA8E;AAC9E,2CAAyC;AAGzC;;;GAGG;AACH;
|
|
1
|
+
{"version":3,"file":"KyselyDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/kysely/KyselyDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAiE;AACjE,yBAAyB;AAEzB,yDAA8E;AAC9E,2CAAyC;AAGzC;;;GAGG;AACH;IAAsD,kCAAqC;IAmCzF;;;;OAIG;IACH,wBAAmB,MAA0B;QAC3C,YAAA,MAAK,YAAC,MAAM,CAAC,SAAA;QACb,KAAI,CAAC,QAAQ,GAAG,KAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QAC3C,KAAI,CAAC,MAAM,GAAG,KAAI,CAAC,eAAe,CAAC,KAAI,CAAC,QAAQ,CAAC,CAAA;QACjD,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,KAAI,CAAC,YAAY,GAAG,KAAI,CAAC,cAAc,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YAC3D,KAAI,CAAC,UAAU,GAAG,KAAI,CAAC,eAAe,CAAC,KAAI,CAAC,YAAY,CAAC,CAAA;QAC3D,CAAC;;IACH,CAAC;IAED;;;OAGG;IACmB,oCAAW,GAAjC;;;gBACE,sBAAO,yCAAqB,CAAC,cAAc,CAAW,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,EAAA;;;KAC1F;IACD;;;;OAIG;IACK,uCAAc,GAAtB,UAAuB,MAAoB;QACzC,OAAO,IAAI,cAAc,CAAC,gBAAgB,CAAC;YACzC,IAAI,EAAE,IAAI,cAAc,CAAC,UAAU,CAAC;gBAClC,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,GAAG,EAAE,MAAM,CAAC,cAAc;aAC3B,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;IACD;;;;OAIG;IACK,wCAAe,GAAvB,UAAwB,OAAwB;QAC9C,OAAO,IAAI,cAAc,CAAC,cAAc,CAAW;YACjD,OAAO,SAAA;YACP,OAAO,EAAE,CAAC,IAAI,wBAAe,EAAE,CAAC;SACjC,CAAC,CAAA;IACJ,CAAC;IAnFD;;;OAGG;IACY,+BAAgB,GAAG,wBAAe,CAAA;IACjD;;;OAGG;IACY,6BAAc,GAAG,eAAM,CAAA;IACtC;;;OAGG;IACY,yBAAU,GAAG,SAAI,CAAA;IAsElC,qBAAC;CAAA,AArFD,CAAsD,mBAAQ,GAqF7D;AArFY,wCAAc"}
|
|
@@ -11,7 +11,7 @@ export declare class PostgresDatabase extends Database<PostgresTransaction> {
|
|
|
11
11
|
* A public static property that represents a connection pool for a PostgreSQL database.
|
|
12
12
|
* This property is used to manage and provide connections to the PostgreSQL database.
|
|
13
13
|
*/
|
|
14
|
-
static pgProvider
|
|
14
|
+
private static pgProvider;
|
|
15
15
|
/**
|
|
16
16
|
* Represents a connection pool to manage multiple client connections to the database.
|
|
17
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgresDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/pgsql/PostgresDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAyB;AAEzB,6DAAoF;AACpF,2CAAyC;AAGzC;;;GAGG;AACH;IAAsC,oCAA6B;IAgBjE;;;;OAIG;IACH,0BAAmB,MAAsB;QACvC,YAAA,MAAK,YAAC,MAAM,CAAC,SAAA;QACb,KAAI,CAAC,MAAM,GAAG,KAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;QAC1C,IAAI,MAAM,CAAC,WAAW;YAAE,KAAI,CAAC,UAAU,GAAG,KAAI,CAAC,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;;IACpF,CAAC;IAED;;;OAGG;IACmB,sCAAW,GAAjC;;;gBACE,sBAAO,6CAAuB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,EAAA;;;KAClF;IACO,0CAAe,GAAvB,UAAwB,MAAoB;QAC1C,OAAO,IAAI,gBAAgB,CAAC,UAAU,CAAC;YACrC,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,GAAG,EAAE,MAAM,CAAC,cAAc;SAC3B,CAAC,CAAA;IACJ,CAAC;IA1CD;;;OAGG;
|
|
1
|
+
{"version":3,"file":"PostgresDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/pgsql/PostgresDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAyB;AAEzB,6DAAoF;AACpF,2CAAyC;AAGzC;;;GAGG;AACH;IAAsC,oCAA6B;IAgBjE;;;;OAIG;IACH,0BAAmB,MAAsB;QACvC,YAAA,MAAK,YAAC,MAAM,CAAC,SAAA;QACb,KAAI,CAAC,MAAM,GAAG,KAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;QAC1C,IAAI,MAAM,CAAC,WAAW;YAAE,KAAI,CAAC,UAAU,GAAG,KAAI,CAAC,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;;IACpF,CAAC;IAED;;;OAGG;IACmB,sCAAW,GAAjC;;;gBACE,sBAAO,6CAAuB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,EAAA;;;KAClF;IACO,0CAAe,GAAvB,UAAwB,MAAoB;QAC1C,OAAO,IAAI,gBAAgB,CAAC,UAAU,CAAC;YACrC,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,GAAG,EAAE,MAAM,CAAC,cAAc;SAC3B,CAAC,CAAA;IACJ,CAAC;IA1CD;;;OAGG;IACY,2BAAU,GAAG,SAAI,CAAA;IAuClC,uBAAC;CAAA,AA5CD,CAAsC,mBAAQ,GA4C7C;AA5CY,4CAAgB"}
|
|
@@ -99,7 +99,6 @@ var Server = /** @class */ (function () {
|
|
|
99
99
|
this.parsePathParams(request, route.path);
|
|
100
100
|
// Validate path
|
|
101
101
|
if (route.pathSchema) {
|
|
102
|
-
console.log('VVVV', request.getPathParams());
|
|
103
102
|
validationResp = Validator_1.default.validateSchema(request.getPathParams(), route.pathSchema);
|
|
104
103
|
if (validationResp && validationResp instanceof Response_1.default)
|
|
105
104
|
return [2 /*return*/, validationResp];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../../../src/Server/lib/Server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA6C;AAG7C,+CAAyC;AACzC,2DAAqD;AACrD,wDAAkD;AAElD,kDAA4C;AAE5C;;GAEG;AACH;IAcE;;;;OAIG;IACH,gBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,aAAa,GAAG,IAAI,uBAAa,CAAC,MAAM,CAAC,CAAA;IAChD,CAAC;IAED;;;OAGG;IACI,0BAAS,GAAhB;QACE,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC;IAED;;;;;OAKG;IACU,sCAAqB,GAAlC,UAAmC,KAA2B,EAAE,OAAgB;;;;;;oBAC9E,mBAAmB;oBACnB,qBAAM,IAAI,qBAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAM,WAAW;;;;;wCACpE,OAAO,GAAG,WAAW,CAAC,OAAO,CAAA;wCAC7B,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;6CACjF,KAAK,EAAL,wBAAK;wCACP,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;wCAC5D,iBAAiB;wCACjB,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;4CAChB,cAAc,GAAG,mBAAS,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,WAAW,CAAC,CAAA;4CACrF,IAAI,cAAc,IAAI,cAAc,YAAY,kBAAQ;gDAAE,sBAAO,cAAc,EAAA;wCACjF,CAAC;wCAED,iBAAiB;wCACjB,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;4CAChB,cAAc,GAAG,mBAAS,CAAC,cAAc,CAC7C,OAAO,CAAC,cAAc,EAAE,EACxB,KAAK,CAAC,WAAW,CAClB,CAAA;4CACD,IAAI,cAAc,IAAI,cAAc,YAAY,kBAAQ;gDAAE,sBAAO,cAAc,EAAA;wCACjF,CAAC;wCAED,0BAA0B;wCAC1B,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;wCACzC,gBAAgB;wCAChB,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../../../src/Server/lib/Server.ts"],"names":[],"mappings":"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"}
|
package/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import Utils from './src/API/Utils'
|
|
|
4
4
|
import EventProcessor from './src/BaseEvent/EventProcessor'
|
|
5
5
|
import Process from './src/BaseEvent/Process'
|
|
6
6
|
import Transaction from './src/BaseEvent/Transaction'
|
|
7
|
+
import Redis from './src/Cache/Redis'
|
|
7
8
|
import Configuration from './src/Config/Configuration'
|
|
8
9
|
import Crypto from './src/Crypto/Crypto'
|
|
9
10
|
import JWT from './src/Crypto/JWT'
|
|
@@ -12,19 +13,26 @@ import Mailer from './src/Mailer/Mailer'
|
|
|
12
13
|
import Router, { Route } from './src/Server/Router'
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
16
|
+
* This module exports various classes and utilities for handling transactions, processes, events, routing,
|
|
17
|
+
* mailing, cryptography, JWT, configuration, Redis, responses, utilities, routes, response error types,
|
|
18
|
+
* HTTP methods, and databases.
|
|
19
|
+
* @exports {
|
|
20
|
+
* Transaction,
|
|
21
|
+
* Process,
|
|
22
|
+
* EventProcessor,
|
|
23
|
+
* Router,
|
|
24
|
+
* Mailer,
|
|
25
|
+
* Crypto,
|
|
26
|
+
* JWT,
|
|
27
|
+
* Configuration,
|
|
28
|
+
* Redis,
|
|
29
|
+
* Response,
|
|
30
|
+
* Utils,
|
|
31
|
+
* Route,
|
|
32
|
+
* ResponseErrorType,
|
|
33
|
+
* HttpMethod,
|
|
34
|
+
* Database,
|
|
35
|
+
* }
|
|
28
36
|
*/
|
|
29
37
|
export {
|
|
30
38
|
// Base Events
|
|
@@ -37,6 +45,7 @@ export {
|
|
|
37
45
|
Crypto,
|
|
38
46
|
JWT,
|
|
39
47
|
Configuration,
|
|
48
|
+
Redis,
|
|
40
49
|
// API
|
|
41
50
|
Response,
|
|
42
51
|
// Helpers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creator.co/wapi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"parse-duration": "^1.1.0",
|
|
42
42
|
"path-to-regexp": "^6.2.1",
|
|
43
43
|
"pg": "^8.11.3",
|
|
44
|
+
"redis": "^4.6.13",
|
|
44
45
|
"sha1": "^1.1.1",
|
|
45
46
|
"stack-trace": "0.0.10",
|
|
46
47
|
"zod": "^3.22.4"
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { RedisClientType, createClient } from 'redis'
|
|
2
|
+
|
|
3
|
+
import { CacheConfig } from './types'
|
|
4
|
+
/**
|
|
5
|
+
* Represents a Redis cache connection class.
|
|
6
|
+
*/
|
|
7
|
+
export default class Redis {
|
|
8
|
+
/**
|
|
9
|
+
* Private static property that holds the connection to a Redis client.
|
|
10
|
+
* @type {RedisClientType}
|
|
11
|
+
*/
|
|
12
|
+
private static _connection: RedisClientType
|
|
13
|
+
/**
|
|
14
|
+
* A private static property that holds a reference to the redis.createClient function.
|
|
15
|
+
* This property is used to create client.
|
|
16
|
+
*/
|
|
17
|
+
private static ClientFactory = createClient
|
|
18
|
+
private static awaitingConnectionQueue: any
|
|
19
|
+
/**
|
|
20
|
+
* Establishes a connection to a Redis cache based on the provided configuration.
|
|
21
|
+
* If a connection is already established, it returns the existing connection.
|
|
22
|
+
* If a connection is pending, it waits for the connection to be established and then returns it.
|
|
23
|
+
* @param {CacheConfig<'redis'>} config - The configuration object for connecting to Redis cache.
|
|
24
|
+
* @returns {Promise<RedisClientType>} A promise that resolves to the Redis client once the connection is established.
|
|
25
|
+
*/
|
|
26
|
+
public static async connection(config: CacheConfig<'redis'>): Promise<RedisClientType> {
|
|
27
|
+
// No connection, but waiting connection queue is valid? wait until other promise
|
|
28
|
+
// fulfill this promise
|
|
29
|
+
if (!Redis._connection && Redis.awaitingConnectionQueue) {
|
|
30
|
+
return new Promise(resolve => Redis.awaitingConnectionQueue.push(resolve))
|
|
31
|
+
} else if (Redis._connection) return Redis._connection //already connected
|
|
32
|
+
// Connect
|
|
33
|
+
Redis.awaitingConnectionQueue = []
|
|
34
|
+
const con = await Redis.redisConnection(config)
|
|
35
|
+
if (Redis.awaitingConnectionQueue) {
|
|
36
|
+
Redis.awaitingConnectionQueue.forEach(resolve => resolve(con))
|
|
37
|
+
}
|
|
38
|
+
Redis.awaitingConnectionQueue = null
|
|
39
|
+
return con
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Establishes a connection to a Redis client based on the provided configuration
|
|
43
|
+
* and holds it for reusability. If connection is detected closed, new connection is
|
|
44
|
+
* initialized and established.
|
|
45
|
+
* @param {CacheConfig<'redis'>} config - The configuration object for connecting to the Redis client.
|
|
46
|
+
* @returns {Promise<RedisClientType>} A promise that resolves to the Redis client connection.
|
|
47
|
+
*/
|
|
48
|
+
private static async redisConnection(config: CacheConfig<'redis'>): Promise<RedisClientType> {
|
|
49
|
+
if (Redis._connection && Redis._connection.isOpen) return Redis._connection
|
|
50
|
+
console.debug('Starting remote cache connection')
|
|
51
|
+
const connection = Redis.ClientFactory({
|
|
52
|
+
username: config.username,
|
|
53
|
+
...(config.password ? { password: config.password } : {}),
|
|
54
|
+
disableOfflineQueue: true,
|
|
55
|
+
socket: {
|
|
56
|
+
host: config.hostname,
|
|
57
|
+
...(config.enableTLS ? { tls: true } : {}),
|
|
58
|
+
connectTimeout: 10000,
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
await connection.connect()
|
|
62
|
+
Redis._connection = connection as any
|
|
63
|
+
return Redis._connection
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Redis from './Redis'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defines a type alias for specifying the cache type as 'redis'.
|
|
5
|
+
*/
|
|
6
|
+
export type CacheType = 'redis'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Defines a CacheClass type that has a 'redis' property which is a constructor function
|
|
10
|
+
* that takes in any number of arguments and returns an instance of Redis.
|
|
11
|
+
*/
|
|
12
|
+
export type CacheClass = {
|
|
13
|
+
redis: new (...args: any[]) => Redis
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents the base configuration for a cache, including host, username, password, and TLS settings.
|
|
18
|
+
*/
|
|
19
|
+
export type CacheBaseConfig = {
|
|
20
|
+
hostname: string
|
|
21
|
+
username: string
|
|
22
|
+
password?: string
|
|
23
|
+
enableTLS: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Defines a CacheConfig type that extends CacheBaseConfig and includes a specific cache type.
|
|
28
|
+
* @template S - The specific cache type to be included in the CacheConfig.
|
|
29
|
+
* @extends CacheBaseConfig
|
|
30
|
+
* @property {S} type - The specific cache type included in the CacheConfig.
|
|
31
|
+
*/
|
|
32
|
+
export type CacheConfig<S extends CacheType> = CacheBaseConfig & { type: S }
|
|
@@ -14,7 +14,7 @@ export class KnexDatabase extends Database<KnexTransaction> {
|
|
|
14
14
|
* @param {knex.Knex.Config<any>} config - The configuration object for Knex.
|
|
15
15
|
* @returns {knex.Knex<any, unknown[]>} A Knex instance based on the provided configuration.
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
private static knexProvider: (config: knex.Knex.Config<any>) => knex.Knex<any, unknown[]> = knex
|
|
18
18
|
/**
|
|
19
19
|
* Represents a Knex client for interacting with a database.
|
|
20
20
|
* @type {Knex}
|
|
@@ -9,22 +9,22 @@ import type { DbBaseConfig, DbConfig } from '../../types'
|
|
|
9
9
|
* Represents a database connection using the Kysely library with support for transactions.
|
|
10
10
|
* @template DBSchema - The schema type for the database.
|
|
11
11
|
*/
|
|
12
|
-
export class KyselyDatabase<DBSchema> extends Database<KyselyTransaction<DBSchema>> {
|
|
12
|
+
export class KyselyDatabase<DBSchema = never> extends Database<KyselyTransaction<DBSchema>> {
|
|
13
13
|
/**
|
|
14
14
|
* Represents a PostgreSQL provider for querying data using the PostgresDialect.
|
|
15
15
|
* @type {PostgresDialect}
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
private static kyselyPgProvider = PostgresDialect
|
|
18
18
|
/**
|
|
19
19
|
* A public static property that provides access to the Kysely class.
|
|
20
20
|
* This property can be accessed without creating an instance of the class.
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
private static kyselyProvider = Kysely
|
|
23
23
|
/**
|
|
24
24
|
* A static property that represents a connection pool for PostgreSQL database connections.
|
|
25
25
|
* @type {Pool}
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
private static pgProvider = Pool
|
|
28
28
|
/**
|
|
29
29
|
* Represents a PostgreSQL client using the PostgresDialect.
|
|
30
30
|
*/
|
|
@@ -13,7 +13,7 @@ export class PostgresDatabase extends Database<PostgresTransaction> {
|
|
|
13
13
|
* A public static property that represents a connection pool for a PostgreSQL database.
|
|
14
14
|
* This property is used to manage and provide connections to the PostgreSQL database.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
private static pgProvider = Pool
|
|
17
17
|
/**
|
|
18
18
|
* Represents a connection pool to manage multiple client connections to the database.
|
|
19
19
|
*/
|
package/src/Server/lib/Server.ts
CHANGED
|
@@ -75,7 +75,6 @@ export default class Server {
|
|
|
75
75
|
this.parsePathParams(request, route.path)
|
|
76
76
|
// Validate path
|
|
77
77
|
if (route.pathSchema) {
|
|
78
|
-
console.log('VVVV', request.getPathParams())
|
|
79
78
|
const validationResp = Validator.validateSchema(request.getPathParams(), route.pathSchema)
|
|
80
79
|
if (validationResp && validationResp instanceof Response) return validationResp
|
|
81
80
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import Redis from '../../src/Cache/Redis'
|
|
2
|
+
|
|
3
|
+
let _connectionId = 1
|
|
4
|
+
async function simpleRedisTest(config: any, concurrent?: boolean) {
|
|
5
|
+
const RedisMock = jest.fn(() => {
|
|
6
|
+
let opened = false
|
|
7
|
+
const connectionId = _connectionId++
|
|
8
|
+
return {
|
|
9
|
+
connectionId,
|
|
10
|
+
isOpen: () => opened,
|
|
11
|
+
close: () => (opened = false),
|
|
12
|
+
connect: jest.fn(() => {
|
|
13
|
+
opened = true
|
|
14
|
+
return {
|
|
15
|
+
mget: jest.fn(() => {
|
|
16
|
+
return true
|
|
17
|
+
}),
|
|
18
|
+
}
|
|
19
|
+
}),
|
|
20
|
+
} as any
|
|
21
|
+
})
|
|
22
|
+
Redis['ClientFactory'] = RedisMock
|
|
23
|
+
// Cleanup previous connection
|
|
24
|
+
if (Redis['_connection']) (await Redis.connection({} as any))?.['close']()
|
|
25
|
+
// Double call is intentional
|
|
26
|
+
let provider, provider2
|
|
27
|
+
if (concurrent) {
|
|
28
|
+
const ps = await Promise.all([Redis.connection(config as any), Redis.connection(config as any)])
|
|
29
|
+
provider = ps[0]
|
|
30
|
+
provider2 = ps[1]
|
|
31
|
+
} else {
|
|
32
|
+
provider = await Redis.connection(config as any)
|
|
33
|
+
provider2 = await Redis.connection(config as any)
|
|
34
|
+
}
|
|
35
|
+
// client checks
|
|
36
|
+
expect(RedisMock).toHaveBeenNthCalledWith(1, {
|
|
37
|
+
username: config.username,
|
|
38
|
+
...(config.password ? { password: config.password } : {}),
|
|
39
|
+
disableOfflineQueue: true,
|
|
40
|
+
socket: {
|
|
41
|
+
host: config.hostname,
|
|
42
|
+
...(config.enableTLS ? { tls: true } : {}),
|
|
43
|
+
connectTimeout: 10000,
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
// Does not have double connection
|
|
47
|
+
expect(provider.connectionId).toEqual(provider2.connectionId)
|
|
48
|
+
expect(provider.connect).toHaveBeenCalledTimes(1)
|
|
49
|
+
expect(provider2.connect).toHaveBeenCalledTimes(1)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe('Redis', () => {
|
|
53
|
+
beforeEach(async () => {
|
|
54
|
+
// hack to close singleton connection
|
|
55
|
+
if (Redis['_connection']) (await Redis.connection({} as any))?.['close']()
|
|
56
|
+
})
|
|
57
|
+
test('Simple redis - do not connect twice', async () => {
|
|
58
|
+
Redis['_connection'] = null as any
|
|
59
|
+
await simpleRedisTest({
|
|
60
|
+
hostname: 'redis://localhost',
|
|
61
|
+
username: 'gabe',
|
|
62
|
+
password: 'mypassword',
|
|
63
|
+
enableTLS: true,
|
|
64
|
+
type: 'redis',
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
test('Simple redis (no SSL) - do not connect twice', async () => {
|
|
68
|
+
Redis['_connection'] = null as any
|
|
69
|
+
await simpleRedisTest({
|
|
70
|
+
hostname: 'redis://localhost',
|
|
71
|
+
username: 'gabe',
|
|
72
|
+
password: 'mypassword',
|
|
73
|
+
enableTLS: false,
|
|
74
|
+
type: 'redis',
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
test('Simple redis (passwordless) - do not connect twice', async () => {
|
|
78
|
+
Redis['_connection'] = null as any
|
|
79
|
+
await simpleRedisTest({
|
|
80
|
+
hostname: 'redis://localhost',
|
|
81
|
+
username: 'gabe',
|
|
82
|
+
enableTLS: false,
|
|
83
|
+
type: 'redis',
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
test('Concurrent redis - do not connect twice', async () => {
|
|
87
|
+
Redis['_connection'] = null as any
|
|
88
|
+
await simpleRedisTest(
|
|
89
|
+
{
|
|
90
|
+
hostname: 'redis://localhost',
|
|
91
|
+
username: 'gabe',
|
|
92
|
+
enableTLS: false,
|
|
93
|
+
type: 'redis',
|
|
94
|
+
},
|
|
95
|
+
true
|
|
96
|
+
)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { expect as c_expect } from 'chai'
|
|
2
1
|
import { PostgresDialect } from 'kysely'
|
|
3
2
|
import { PoolClient } from 'pg'
|
|
4
3
|
|
|
@@ -78,8 +77,9 @@ describe('KyselyDatabase', () => {
|
|
|
78
77
|
const underTest = new KyselyDatabase(config)
|
|
79
78
|
expect(mockPgClient).toHaveBeenNthCalledWith(1, expectedImplConfig)
|
|
80
79
|
expect(mockDialect).toHaveBeenCalledTimes(1)
|
|
81
|
-
expect(mockClient).
|
|
82
|
-
|
|
80
|
+
expect(mockClient).toHaveBeenCalledTimes(1)
|
|
81
|
+
expect(mockClient.mock.calls[0][0].dialect).toEqual(underTest['pgClient'])
|
|
82
|
+
expect(mockClient.mock.calls[0][0].plugins).toBeInstanceOf(Array)
|
|
83
83
|
const trans = await underTest.transaction()
|
|
84
84
|
|
|
85
85
|
expect(mockTrans.execute).toHaveBeenCalledTimes(1)
|
|
@@ -94,8 +94,11 @@ describe('KyselyDatabase', () => {
|
|
|
94
94
|
const underTest = new KyselyDatabase(config2)
|
|
95
95
|
expect(mockPgClient).toHaveBeenNthCalledWith(2, expectedImplConfig)
|
|
96
96
|
expect(mockDialect).toHaveBeenCalledTimes(2)
|
|
97
|
-
expect(mockClient).
|
|
98
|
-
expect(mockClient).
|
|
97
|
+
expect(mockClient).toHaveBeenCalledTimes(2)
|
|
98
|
+
expect(mockClient.mock.calls[0][0].dialect).toEqual(underTest['pgClient'])
|
|
99
|
+
expect(mockClient.mock.calls[0][0].plugins).toBeInstanceOf(Array)
|
|
100
|
+
expect(mockClient.mock.calls[1][0].dialect).toEqual(underTest['pgReadClient'])
|
|
101
|
+
expect(mockClient.mock.calls[1][0].plugins).toBeInstanceOf(Array)
|
|
99
102
|
|
|
100
103
|
const trans = await underTest.transaction()
|
|
101
104
|
|