@pi-r/redis 0.6.5 → 0.6.7
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/client/index.js +15 -13
- package/package.json +3 -3
package/client/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = void 0;
|
|
4
3
|
const redis = require("redis");
|
|
5
4
|
const util_1 = require("@e-mc/db/util");
|
|
@@ -41,13 +40,15 @@ async function getClient(db, options, poolKey) {
|
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
42
|
function removePoolProperties(options) {
|
|
43
|
+
var _a;
|
|
44
44
|
if (!options.uuidKey && ('socket' in options || 'isolationPoolOptions' in options) && POOL_ACTIVE.has(options)) {
|
|
45
|
-
return { ...options, socket: options.socket
|
|
45
|
+
return { ...options, socket: ((_a = options.socket) === null || _a === void 0 ? void 0 : _a.tls) ? { tls: true } : undefined, isolationPoolOptions: undefined };
|
|
46
46
|
}
|
|
47
47
|
return options;
|
|
48
48
|
}
|
|
49
49
|
const getPoolKey = (options) => options.url && JSON.stringify(options);
|
|
50
50
|
async function setCredential(item) {
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
51
52
|
const credential = this.getCredential(item);
|
|
52
53
|
const options = item.options || (item.options = {});
|
|
53
54
|
const client = (0, types_1.isPlainObject)(options.client) ? options.client : options.client = {};
|
|
@@ -79,7 +80,7 @@ async function setCredential(item) {
|
|
|
79
80
|
if (!uri) {
|
|
80
81
|
throw (0, types_1.errorMessage)("redis", 'Not defined - uri');
|
|
81
82
|
}
|
|
82
|
-
if (client.socket
|
|
83
|
+
if ((_a = client.socket) === null || _a === void 0 ? void 0 : _a.tls) {
|
|
83
84
|
this.readTLSConfig(client.socket);
|
|
84
85
|
}
|
|
85
86
|
client.url = uri;
|
|
@@ -97,7 +98,7 @@ async function setCredential(item) {
|
|
|
97
98
|
username = undefined;
|
|
98
99
|
password = undefined;
|
|
99
100
|
if ((0, types_1.isString)(usePool)) {
|
|
100
|
-
if (username = client.username || (0, util_1.parseConnectionString)(uri)
|
|
101
|
+
if (username = client.username || ((_b = (0, util_1.parseConnectionString)(uri)) === null || _b === void 0 ? void 0 : _b.username)) {
|
|
101
102
|
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
102
103
|
if (pool) {
|
|
103
104
|
pool.add(item, password);
|
|
@@ -114,22 +115,22 @@ async function setCredential(item) {
|
|
|
114
115
|
if (config) {
|
|
115
116
|
const { min, max, idle, queue_max, queue_idle, timeout } = config;
|
|
116
117
|
if (min >= 0) {
|
|
117
|
-
poolOptions.min
|
|
118
|
+
(_c = poolOptions.min) !== null && _c !== void 0 ? _c : (poolOptions.min = min);
|
|
118
119
|
}
|
|
119
120
|
if (max > 0) {
|
|
120
|
-
poolOptions.max
|
|
121
|
+
(_d = poolOptions.max) !== null && _d !== void 0 ? _d : (poolOptions.max = max);
|
|
121
122
|
}
|
|
122
123
|
if (idle > 0) {
|
|
123
|
-
poolOptions.idleTimeoutMillis
|
|
124
|
+
(_e = poolOptions.idleTimeoutMillis) !== null && _e !== void 0 ? _e : (poolOptions.idleTimeoutMillis = idle);
|
|
124
125
|
}
|
|
125
126
|
if (queue_max >= 0) {
|
|
126
|
-
poolOptions.maxWaitingClients
|
|
127
|
+
(_f = poolOptions.maxWaitingClients) !== null && _f !== void 0 ? _f : (poolOptions.maxWaitingClients = queue_max);
|
|
127
128
|
}
|
|
128
129
|
if (queue_idle > 0) {
|
|
129
|
-
poolOptions.softIdleTimeoutMillis
|
|
130
|
+
(_g = poolOptions.softIdleTimeoutMillis) !== null && _g !== void 0 ? _g : (poolOptions.softIdleTimeoutMillis = queue_idle);
|
|
130
131
|
}
|
|
131
132
|
if (timeout > 0) {
|
|
132
|
-
poolOptions.acquireTimeoutMillis
|
|
133
|
+
(_h = poolOptions.acquireTimeoutMillis) !== null && _h !== void 0 ? _h : (poolOptions.acquireTimeoutMillis = timeout);
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
const poolKey = getPoolKey(client);
|
|
@@ -153,6 +154,7 @@ async function executeQuery(item, options) {
|
|
|
153
154
|
}
|
|
154
155
|
exports.executeQuery = executeQuery;
|
|
155
156
|
async function executeBatchQuery(batch, options = '', outResult) {
|
|
157
|
+
var _a, _b, _c;
|
|
156
158
|
const length = batch.length;
|
|
157
159
|
if (length === 0) {
|
|
158
160
|
return [];
|
|
@@ -180,7 +182,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
180
182
|
const caching = this.hasCache("redis", sessionKey);
|
|
181
183
|
const tasks = new Array(length);
|
|
182
184
|
const clients = [];
|
|
183
|
-
let redisClient, redisCredential, redisCache = 0, onceCredential = connectOnce ? batch[0].options
|
|
185
|
+
let redisClient, redisCredential, redisCache = 0, onceCredential = connectOnce ? (_a = batch[0].options) === null || _a === void 0 ? void 0 : _a.client : undefined;
|
|
184
186
|
const getConnection = async (item, credential) => {
|
|
185
187
|
item.transactionState = 64;
|
|
186
188
|
let client;
|
|
@@ -208,7 +210,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
208
210
|
item.transactionState &= ~64;
|
|
209
211
|
return client;
|
|
210
212
|
};
|
|
211
|
-
if (this.host
|
|
213
|
+
if ((_b = this.host) === null || _b === void 0 ? void 0 : _b.username) {
|
|
212
214
|
this.applyCommand(...batch);
|
|
213
215
|
}
|
|
214
216
|
for (let i = 0; i < length; ++i) {
|
|
@@ -234,7 +236,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
234
236
|
}
|
|
235
237
|
item.transactionState = 1;
|
|
236
238
|
const command = (0, types_1.isPlainObject)(clientOptions.command) ? redis.commandOptions(clientOptions.command) : null;
|
|
237
|
-
const uuidKey = (credential.uuidKey || (credential.uuidKey = (onceCredential ? batch[0] : item).credential
|
|
239
|
+
const uuidKey = (credential.uuidKey || (credential.uuidKey = (_c = (onceCredential ? batch[0] : item).credential) === null || _c === void 0 ? void 0 : _c.uuidKey));
|
|
238
240
|
const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
|
|
239
241
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
240
242
|
let queryString = '', rows;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/redis",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "Redis client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@e-mc/db": "^0.8.
|
|
25
|
-
"@e-mc/types": "^0.8.
|
|
24
|
+
"@e-mc/db": "^0.8.8",
|
|
25
|
+
"@e-mc/types": "^0.8.8",
|
|
26
26
|
"redis": "^4.6.13"
|
|
27
27
|
}
|
|
28
28
|
}
|