@pi-r/redis 0.8.3 → 0.9.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/LICENSE +7 -7
- package/README.md +1 -1
- package/client/index.js +10 -7
- package/client/pool.d.ts +8 -8
- package/package.json +4 -5
- package/types/index.d.ts +6 -5
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -5,10 +5,10 @@ exports.executeQuery = executeQuery;
|
|
|
5
5
|
exports.executeBatchQuery = executeBatchQuery;
|
|
6
6
|
exports.checkTimeout = checkTimeout;
|
|
7
7
|
const redis = require("redis");
|
|
8
|
-
const
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
9
9
|
const Db = require("@e-mc/db");
|
|
10
|
-
const util_1 = require("@e-mc/db/util");
|
|
11
10
|
const types_1 = require("@e-mc/types");
|
|
11
|
+
const util_1 = require("@e-mc/db/util");
|
|
12
12
|
const DbPool = require("@pi-r/redis/client/pool");
|
|
13
13
|
const POOL_STATE = {};
|
|
14
14
|
async function doScan(client, key, index, cursor = [0], iterations = [Infinity], options) {
|
|
@@ -41,9 +41,11 @@ async function getClient(db, options, poolKey) {
|
|
|
41
41
|
delete POOL_STATE[poolKey];
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
client.connect()
|
|
44
|
+
client.connect()
|
|
45
|
+
.then(() => {
|
|
45
46
|
resolve(client);
|
|
46
|
-
})
|
|
47
|
+
})
|
|
48
|
+
.catch((err) => {
|
|
47
49
|
reject(err);
|
|
48
50
|
});
|
|
49
51
|
});
|
|
@@ -223,7 +225,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
223
225
|
}
|
|
224
226
|
item.transactionState = 1;
|
|
225
227
|
const command = (0, types_1.isPlainObject)(clientOptions.command) ? redis.commandOptions(clientOptions.command) : null;
|
|
226
|
-
const uuidKey =
|
|
228
|
+
const uuidKey = credential.uuidKey ||= (onceCredential ? batch[0] : item).credential?.uuidKey;
|
|
227
229
|
const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
|
|
228
230
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
229
231
|
let queryString = '', rows;
|
|
@@ -523,7 +525,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
523
525
|
const { query = '', schema, index } = target;
|
|
524
526
|
let idx = '';
|
|
525
527
|
if ((0, types_1.isObject)(schema)) {
|
|
526
|
-
idx = index || (0,
|
|
528
|
+
idx = index || (0, node_crypto_1.randomUUID)();
|
|
527
529
|
await (command ? client.ft.create(command, idx, schema, target.options) : client.ft.create(idx, schema, target.options));
|
|
528
530
|
}
|
|
529
531
|
try {
|
|
@@ -536,6 +538,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
536
538
|
}
|
|
537
539
|
}
|
|
538
540
|
catch (err) {
|
|
541
|
+
this.addLog(this.statusType.WARN, err, this.moduleName, target === search ? 'FT.SEARCH' : 'FT.AGGREGATE');
|
|
539
542
|
if (err instanceof Error) {
|
|
540
543
|
throw err;
|
|
541
544
|
}
|
|
@@ -585,7 +588,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
585
588
|
break;
|
|
586
589
|
default:
|
|
587
590
|
if (item.field) {
|
|
588
|
-
data = client.hGet(...command ? [command, key, item.field] : [key, item.field]);
|
|
591
|
+
data = await client.hGet(...command ? [command, key, item.field] : [key, item.field]);
|
|
589
592
|
}
|
|
590
593
|
else {
|
|
591
594
|
data = await client.hGetAll(...command ? [command, key] : [key]);
|
package/client/pool.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { DbPoolConstructor } from '@e-mc/types/lib/db';
|
|
2
|
-
|
|
3
|
-
import type { DbPoolCredential, RedisDataSource } from '../types';
|
|
4
|
-
|
|
5
|
-
import type { RedisClientType } from 'redis';
|
|
6
|
-
|
|
7
|
-
declare const RedisPool: DbPoolConstructor<RedisDataSource, RedisClientType, RedisClientType, DbPoolCredential>;
|
|
8
|
-
|
|
1
|
+
import type { DbPoolConstructor } from '@e-mc/types/lib/db';
|
|
2
|
+
|
|
3
|
+
import type { DbPoolCredential, RedisDataSource } from '../types';
|
|
4
|
+
|
|
5
|
+
import type { RedisClientType } from 'redis';
|
|
6
|
+
|
|
7
|
+
declare const RedisPool: DbPoolConstructor<RedisDataSource, RedisClientType, RedisClientType, DbPoolCredential>;
|
|
8
|
+
|
|
9
9
|
export = RedisPool;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Redis client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -14,15 +14,14 @@
|
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"squared",
|
|
17
|
-
"e-mc"
|
|
18
|
-
"squared-functions"
|
|
17
|
+
"e-mc"
|
|
19
18
|
],
|
|
20
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
21
20
|
"license": "MIT",
|
|
22
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
22
|
"dependencies": {
|
|
24
|
-
"@e-mc/db": "^0.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/db": "^0.11.0",
|
|
24
|
+
"@e-mc/types": "^0.11.0",
|
|
26
25
|
"redis": "^4.7.0"
|
|
27
26
|
}
|
|
28
27
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
|
2
2
|
|
|
3
3
|
import type { IdentifierAction } from '@e-mc/types/lib/core';
|
|
4
4
|
import type { CascadeAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
5
|
+
import type { AuthValue } from '@e-mc/types/lib/http';
|
|
5
6
|
|
|
6
7
|
import type { ClientCommandOptions } from '@redis/client/dist/lib/client';
|
|
7
8
|
import type { RedisCommandArgument } from '@redis/client/dist/lib/commands';
|
|
@@ -13,16 +14,16 @@ import type { HScanTuple } from '@redis//client/dist/lib/commands/HSCAN';
|
|
|
13
14
|
import type { ScanOptions } from '@redis/client/dist/lib/commands/generic-transformers';
|
|
14
15
|
import type { RediSearchSchema, SearchOptions, SetOptions } from 'redis';
|
|
15
16
|
|
|
16
|
-
export interface RedisDataSource extends DbDataSource<string, PlainObject,
|
|
17
|
+
export interface RedisDataSource extends DbDataSource<string, PlainObject, RedisSetValue | RedisSetValue[] | RedisJSONValue | RedisJSONValue[], RedisCredential, string>, CascadeAction, AuthValue {
|
|
17
18
|
source: "redis";
|
|
18
|
-
key?:
|
|
19
|
+
key?: RedisCommandArgument | RedisCommandArgument[];
|
|
19
20
|
field?: RedisCommandArgument;
|
|
20
21
|
path?: string;
|
|
21
22
|
format?: RedisFormat | "HKEYS" | "HVALS" | "HSCAN";
|
|
22
23
|
search?: RedisQuery;
|
|
23
24
|
aggregate?: RedisQuery;
|
|
24
|
-
cursor?:
|
|
25
|
-
iterations?:
|
|
25
|
+
cursor?: number | number[];
|
|
26
|
+
iterations?: number | number[];
|
|
26
27
|
options?: {
|
|
27
28
|
client?: RedisClientOptions;
|
|
28
29
|
command?: RedisCommandOptions;
|
|
@@ -59,7 +60,7 @@ export interface RedisSetValue extends RedisCommand<"HASH", RedisCommandArgument
|
|
|
59
60
|
KEEPTTL?: boolean;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
export interface RedisJSONValue extends RedisCommand<"JSON", string,
|
|
63
|
+
export interface RedisJSONValue extends RedisCommand<"JSON", string, RedisJSON | RedisJSON[]> {
|
|
63
64
|
command?: RedisCommandJSON;
|
|
64
65
|
path?: string;
|
|
65
66
|
start?: number | string;
|