@pi-r/redis 0.3.0 → 0.3.3
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/LICENSE +1 -1
- package/README.md +4 -2
- package/client/index.d.ts +2 -2
- package/client/index.js +22 -22
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Lisa Mishima
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/client/index.d.ts
CHANGED
package/client/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const util_1 = require("@e-mc/db/util");
|
|
|
6
6
|
const types_1 = require("@e-mc/types");
|
|
7
7
|
const Db = require("@e-mc/db");
|
|
8
8
|
const DbPool = require('@e-mc/db/pool');
|
|
9
|
-
const REDIS_V4 = Db.checkSemVer("redis"
|
|
9
|
+
const REDIS_V4 = Db.checkSemVer("redis", 4);
|
|
10
10
|
class RedisPool extends DbPool {
|
|
11
11
|
getConnection() {
|
|
12
12
|
return Promise.resolve(this.client);
|
|
@@ -49,7 +49,7 @@ function removePoolProperties(options) {
|
|
|
49
49
|
const getPoolKey = (options) => options.url + '_' + (options.username || '') + '_' + (options.password || '') + '_' + (options.database ?? '') + '_' + (options.socket?.tls ? '1' : '0') + '_' + (options.legacyMode ? '1' : '0');
|
|
50
50
|
async function setCredential(item) {
|
|
51
51
|
if (!REDIS_V4) {
|
|
52
|
-
throw (0, types_1.errorValue)("Upgrade client to latest version"
|
|
52
|
+
throw (0, types_1.errorValue)("Upgrade client to latest version", "redis" + '@' + Db.getPackageVersion("redis"));
|
|
53
53
|
}
|
|
54
54
|
const credential = this.getCredential(item);
|
|
55
55
|
const options = item.options || (item.options = {});
|
|
@@ -59,7 +59,7 @@ async function setCredential(item) {
|
|
|
59
59
|
client.database = database;
|
|
60
60
|
}
|
|
61
61
|
if (credential) {
|
|
62
|
-
const auth = (0, util_1.parseServerAuth)(credential, 6379
|
|
62
|
+
const auth = (0, util_1.parseServerAuth)(credential, 6379);
|
|
63
63
|
if (!client.database) {
|
|
64
64
|
if ('database' in credential) {
|
|
65
65
|
const value = credential.database;
|
|
@@ -72,7 +72,7 @@ async function setCredential(item) {
|
|
|
72
72
|
client.database = database;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
uri || (uri = (auth.protocol || 'redis:') + '//' + (auth.server || 'localhost:' + (auth.port ? auth.port : 6379
|
|
75
|
+
uri || (uri = (auth.protocol || 'redis:') + '//' + (auth.server || 'localhost:' + (auth.port ? auth.port : 6379)));
|
|
76
76
|
username || (username = auth.username);
|
|
77
77
|
password || (password = auth.password);
|
|
78
78
|
}
|
|
@@ -80,7 +80,7 @@ async function setCredential(item) {
|
|
|
80
80
|
delete item.credential;
|
|
81
81
|
}
|
|
82
82
|
if (!uri) {
|
|
83
|
-
throw (0, types_1.errorMessage)("redis"
|
|
83
|
+
throw (0, types_1.errorMessage)("redis", 'Not defined - uri');
|
|
84
84
|
}
|
|
85
85
|
if (client.socket?.tls) {
|
|
86
86
|
this.readTLSConfig(client.socket);
|
|
@@ -106,7 +106,7 @@ async function setCredential(item) {
|
|
|
106
106
|
}
|
|
107
107
|
const poolKey = getPoolKey(client);
|
|
108
108
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
109
|
-
const config = this.getPoolConfig("redis"
|
|
109
|
+
const config = this.getPoolConfig("redis", password);
|
|
110
110
|
const poolOptions = client.isolationPoolOptions || (client.isolationPoolOptions = {});
|
|
111
111
|
if (config) {
|
|
112
112
|
const { min, max, idle, queue_max, queue_idle } = config;
|
|
@@ -171,12 +171,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
171
171
|
if (!parallel) {
|
|
172
172
|
outResult || (outResult = new Array(length));
|
|
173
173
|
}
|
|
174
|
-
const caching = this.hasCache("redis"
|
|
174
|
+
const caching = this.hasCache("redis", sessionKey);
|
|
175
175
|
const tasks = new Array(length);
|
|
176
176
|
const clients = [];
|
|
177
177
|
let redisClient, redisCredential, redisCache = 0, onceCredential = connectOnce ? batch[0].options?.client : undefined;
|
|
178
178
|
const getConnection = async (item, credential) => {
|
|
179
|
-
item.transactionState = 64
|
|
179
|
+
item.transactionState = 64;
|
|
180
180
|
let client;
|
|
181
181
|
if (item.usePool) {
|
|
182
182
|
const pool = DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
|
|
@@ -198,14 +198,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
198
198
|
redisClient = client;
|
|
199
199
|
redisCredential = credential;
|
|
200
200
|
}
|
|
201
|
-
item.transactionState &= ~64
|
|
201
|
+
item.transactionState &= ~64;
|
|
202
202
|
return client;
|
|
203
203
|
};
|
|
204
204
|
for (let i = 0; i < length; ++i) {
|
|
205
205
|
const item = batch[i];
|
|
206
206
|
const { source, uri, key, format = 'HASH', search, aggregate, update, options: clientOptions = {}, cacheObjectKey, ignoreCache } = item;
|
|
207
207
|
let credential = (redisCredential || onceCredential), error;
|
|
208
|
-
if (!credential && !(0, types_1.isPlainObject)(credential = clientOptions.client) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
208
|
+
if (!credential && !(0, types_1.isPlainObject)(credential = clientOptions.client) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !((0, types_1.isString)(key) || (0, types_1.isArray)(key) || (0, types_1.isPlainObject)(search) && ((0, types_1.isPlainObject)(search.schema) || (0, types_1.isString)(search.query)) || (0, types_1.isPlainObject)(aggregate) && ((0, types_1.isPlainObject)(aggregate.schema) || (0, types_1.isString)(aggregate.query))) && (error = (0, types_1.errorMessage)(source, "Missing database query", uri))) {
|
|
209
209
|
++redisCache;
|
|
210
210
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
211
211
|
if (!parallel) {
|
|
@@ -222,9 +222,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
222
222
|
}
|
|
223
223
|
continue;
|
|
224
224
|
}
|
|
225
|
-
item.transactionState = 1
|
|
225
|
+
item.transactionState = 1;
|
|
226
226
|
const uuidKey = (credential.uuidKey || (credential.uuidKey = (onceCredential ? batch[0] : item).credential?.uuidKey));
|
|
227
|
-
const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis"
|
|
227
|
+
const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
|
|
228
228
|
const renewCache = ignoreCache === 0;
|
|
229
229
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
230
230
|
const command = (0, types_1.isPlainObject)(clientOptions.command) ? redis.commandOptions(clientOptions.command) : null;
|
|
@@ -254,7 +254,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
254
254
|
else {
|
|
255
255
|
outResult[i] = rows;
|
|
256
256
|
}
|
|
257
|
-
this.add(item, 4
|
|
257
|
+
this.add(item, 4 | 128);
|
|
258
258
|
continue;
|
|
259
259
|
}
|
|
260
260
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -287,8 +287,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
287
287
|
success(target);
|
|
288
288
|
return;
|
|
289
289
|
}
|
|
290
|
-
const failKey = () => failed((0, types_1.errorMessage)(f, "Invalid key"
|
|
291
|
-
const failValue = () => failed((0, types_1.errorMessage)(f, "Invalid value"
|
|
290
|
+
const failKey = () => failed((0, types_1.errorMessage)(f, "Invalid key", Db.asString(k) || "Unknown"));
|
|
291
|
+
const failValue = () => failed((0, types_1.errorMessage)(f, "Invalid value", Db.asString(v) || "Unknown"));
|
|
292
292
|
const commandSet = (0, types_1.isPlainObject)(setOptions.command) && redis.commandOptions(setOptions.command);
|
|
293
293
|
let pending;
|
|
294
294
|
if ((f = f.toUpperCase()) === 'JSON') {
|
|
@@ -297,7 +297,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
297
297
|
return;
|
|
298
298
|
}
|
|
299
299
|
const path = target.path || '$';
|
|
300
|
-
if (this.hasCoerce("redis"
|
|
300
|
+
if (this.hasCoerce("redis", 'options', uuidKey)) {
|
|
301
301
|
if ((0, types_1.isString)(v) && v.startsWith('new')) {
|
|
302
302
|
({ outV: v } = (0, types_1.coerceObject)({ outV: v }));
|
|
303
303
|
}
|
|
@@ -403,7 +403,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
403
403
|
success(target);
|
|
404
404
|
}
|
|
405
405
|
else {
|
|
406
|
-
failed((0, types_1.errorMessage)(f, "Invalid value"
|
|
406
|
+
failed((0, types_1.errorMessage)(f, "Invalid value", has(EX) ? 'EX: ' + EX : has(PX) ? 'PX: ' + PX : EXAT > 0 ? 'EXAT: ' + EX : 'PXAT: ' + PXAT));
|
|
407
407
|
}
|
|
408
408
|
})
|
|
409
409
|
.catch(err => failed(err));
|
|
@@ -460,7 +460,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
460
460
|
error = err;
|
|
461
461
|
}
|
|
462
462
|
if (idx && idx !== index) {
|
|
463
|
-
client.ft.dropIndex(idx).catch(err => this.writeFail([`Unable to drop ${target === search ? 'search' : 'aggregate'} index`, idx], err, { type: 65536
|
|
463
|
+
client.ft.dropIndex(idx).catch(err => this.writeFail([`Unable to drop ${target === search ? 'search' : 'aggregate'} index`, idx], err, { type: 65536, fatal: false }));
|
|
464
464
|
}
|
|
465
465
|
if (error instanceof Error) {
|
|
466
466
|
throw error;
|
|
@@ -508,16 +508,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
508
508
|
rows = (targetObject ? targetObject(item, data) : data);
|
|
509
509
|
}
|
|
510
510
|
if (rows === undefined) {
|
|
511
|
-
throw (0, types_1.errorMessage)(source, "Missing database query"
|
|
511
|
+
throw (0, types_1.errorMessage)(source, "Missing database query");
|
|
512
512
|
}
|
|
513
|
-
this.add(item, 4
|
|
513
|
+
this.add(item, 4);
|
|
514
514
|
resolve(this.setQueryResult(source, removePoolProperties(redisCredential || credential), queryString, rows, cacheValue));
|
|
515
515
|
}
|
|
516
516
|
catch (err) {
|
|
517
517
|
if (err instanceof Error) {
|
|
518
518
|
switch (err.message) {
|
|
519
|
-
case "The client is closed"
|
|
520
|
-
case "Disconnects client"
|
|
519
|
+
case "The client is closed":
|
|
520
|
+
case "Disconnects client": {
|
|
521
521
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential));
|
|
522
522
|
if (pool) {
|
|
523
523
|
await pool.detach(true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/redis",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Redis client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/db/redis"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -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.6.
|
|
25
|
-
"@e-mc/types": "^0.6.
|
|
26
|
-
"redis": "^4.6.
|
|
24
|
+
"@e-mc/db": "^0.6.2",
|
|
25
|
+
"@e-mc/types": "^0.6.2",
|
|
26
|
+
"redis": "^4.6.13"
|
|
27
27
|
}
|
|
28
28
|
}
|