@pi-r/redis 0.6.4 → 0.6.5

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
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
@@ -1,7 +1,10 @@
1
- ### @pi-r/redis
1
+ # @pi-r/redis
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/db/redis.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/db/redis.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
package/client/index.js CHANGED
@@ -56,7 +56,7 @@ async function setCredential(item) {
56
56
  client.database = database;
57
57
  }
58
58
  if (credential) {
59
- const auth = (0, util_1.parseServerAuth)(credential, 6379 /* VALUES.PORT */);
59
+ const auth = (0, util_1.parseServerAuth)(credential, 6379);
60
60
  if (!client.database) {
61
61
  if ('database' in credential) {
62
62
  const value = credential.database;
@@ -69,7 +69,7 @@ async function setCredential(item) {
69
69
  client.database = database;
70
70
  }
71
71
  }
72
- uri || (uri = (auth.protocol || 'redis:') + '//' + (auth.server || 'localhost:' + (auth.port ? auth.port : 6379 /* VALUES.PORT */)));
72
+ uri || (uri = (auth.protocol || 'redis:') + '//' + (auth.server || 'localhost:' + (auth.port ? auth.port : 6379)));
73
73
  username || (username = auth.username);
74
74
  password || (password = auth.password);
75
75
  }
@@ -77,7 +77,7 @@ async function setCredential(item) {
77
77
  delete item.credential;
78
78
  }
79
79
  if (!uri) {
80
- throw (0, types_1.errorMessage)("redis" /* STRINGS.MODULE_NAME */, 'Not defined - uri');
80
+ throw (0, types_1.errorMessage)("redis", 'Not defined - uri');
81
81
  }
82
82
  if (client.socket?.tls) {
83
83
  this.readTLSConfig(client.socket);
@@ -109,7 +109,7 @@ async function setCredential(item) {
109
109
  return;
110
110
  }
111
111
  }
112
- const config = this.getPoolConfig("redis" /* STRINGS.MODULE_NAME */, password);
112
+ const config = this.getPoolConfig("redis", password);
113
113
  const poolOptions = client.isolationPoolOptions || (client.isolationPoolOptions = {});
114
114
  if (config) {
115
115
  const { min, max, idle, queue_max, queue_idle, timeout } = config;
@@ -177,12 +177,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
177
177
  if (!parallel) {
178
178
  outResult || (outResult = new Array(length));
179
179
  }
180
- const caching = this.hasCache("redis" /* STRINGS.MODULE_NAME */, sessionKey);
180
+ const caching = this.hasCache("redis", sessionKey);
181
181
  const tasks = new Array(length);
182
182
  const clients = [];
183
183
  let redisClient, redisCredential, redisCache = 0, onceCredential = connectOnce ? batch[0].options?.client : undefined;
184
184
  const getConnection = async (item, credential) => {
185
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
185
+ item.transactionState = 64;
186
186
  let client;
187
187
  if (item.usePool) {
188
188
  const pool = DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -205,7 +205,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
205
205
  redisClient = client;
206
206
  redisCredential = credential;
207
207
  }
208
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
208
+ item.transactionState &= ~64;
209
209
  return client;
210
210
  };
211
211
  if (this.host?.username) {
@@ -215,7 +215,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
215
215
  const item = batch[i];
216
216
  const { source, uri, key, format = 'HASH', search, aggregate, update, options: clientOptions = {}, cacheObjectKey, ignoreCache } = item;
217
217
  let credential = (redisCredential || onceCredential), error;
218
- if (!credential && !(0, types_1.isPlainObject)(credential = clientOptions.client) && (error = (0, types_1.errorMessage)(source, "Invalid credentials" /* ERR_DB.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" /* ERR_DB.QUERY */, uri))) {
218
+ 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))) {
219
219
  ++redisCache;
220
220
  if (this.handleFail(error, item, { errorQuery })) {
221
221
  if (!parallel) {
@@ -232,10 +232,10 @@ async function executeBatchQuery(batch, options = '', outResult) {
232
232
  }
233
233
  continue;
234
234
  }
235
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
235
+ item.transactionState = 1;
236
236
  const command = (0, types_1.isPlainObject)(clientOptions.command) ? redis.commandOptions(clientOptions.command) : null;
237
237
  const uuidKey = (credential.uuidKey || (credential.uuidKey = (onceCredential ? batch[0] : item).credential?.uuidKey));
238
- const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis" /* STRINGS.MODULE_NAME */, 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
238
+ const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
239
239
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
240
240
  let queryString = '', rows;
241
241
  if (caching && ignoreCache !== true) {
@@ -263,7 +263,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
263
263
  else {
264
264
  outResult[i] = rows;
265
265
  }
266
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
266
+ this.add(item, 4 | 128);
267
267
  continue;
268
268
  }
269
269
  if (!ignoreCache && outCacheMiss) {
@@ -298,8 +298,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
298
298
  return;
299
299
  }
300
300
  const has = (n) => typeof n === 'number' && n > 0;
301
- const failKey = () => failed((0, types_1.errorMessage)(f, "Invalid key" /* ERR_DB.KEY */, Db.asString(k) || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
302
- const failValue = () => failed((0, types_1.errorMessage)(f, "Invalid value" /* ERR_DB.VALUE */, Db.asString(v) || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
301
+ const failKey = () => failed((0, types_1.errorMessage)(f, "Invalid key", Db.asString(k) || "Unknown"));
302
+ const failValue = () => failed((0, types_1.errorMessage)(f, "Invalid value", Db.asString(v) || "Unknown"));
303
303
  const commandSet = (0, types_1.isPlainObject)(setOptions.command) && redis.commandOptions(setOptions.command);
304
304
  let pending, codeMin = 0, EX, PX, EXAT, PXAT, KEEPTTL;
305
305
  if (f === 'JSON') {
@@ -307,7 +307,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
307
307
  failKey();
308
308
  return;
309
309
  }
310
- if (this.hasCoerce("redis" /* STRINGS.MODULE_NAME */, 'options', uuidKey)) {
310
+ if (this.hasCoerce("redis", 'options', uuidKey)) {
311
311
  if ((0, types_1.isString)(v) && v.startsWith('new')) {
312
312
  ({ outV: v } = (0, types_1.coerceObject)({ outV: v }));
313
313
  }
@@ -491,7 +491,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
491
491
  success(target);
492
492
  }
493
493
  else {
494
- failed((0, types_1.errorMessage)(f, "Invalid value" /* ERR_DB.VALUE */, has(EX) ? 'EX: ' + EX : has(PX) ? 'PX: ' + PX : has(EXAT) ? 'EXAT: ' + EX : 'PXAT: ' + PXAT));
494
+ failed((0, types_1.errorMessage)(f, "Invalid value", has(EX) ? 'EX: ' + EX : has(PX) ? 'PX: ' + PX : has(EXAT) ? 'EXAT: ' + EX : 'PXAT: ' + PXAT));
495
495
  }
496
496
  })
497
497
  .catch(err => failed(err));
@@ -547,7 +547,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
547
547
  }
548
548
  finally {
549
549
  if (idx && idx !== index) {
550
- client.ft.dropIndex(idx).catch(err => this.writeFail([`Unable to drop ${target === search ? 'search' : 'aggregate'} index`, idx], err, { type: 65536 /* LOG_TYPE.DB */, fatal: false }));
550
+ client.ft.dropIndex(idx).catch(err => this.writeFail([`Unable to drop ${target === search ? 'search' : 'aggregate'} index`, idx], err, { type: 65536, fatal: false }));
551
551
  }
552
552
  }
553
553
  }
@@ -593,16 +593,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
593
593
  rows = (targetObject ? targetObject(item, data) : data);
594
594
  }
595
595
  if (rows === undefined) {
596
- throw (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */);
596
+ throw (0, types_1.errorMessage)(source, "Missing database query");
597
597
  }
598
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
598
+ this.add(item, 4);
599
599
  resolve(this.setQueryResult(source, removePoolProperties(redisCredential || credential), queryString, rows, cacheValue));
600
600
  }
601
601
  catch (err) {
602
602
  if (err instanceof Error) {
603
603
  switch (err.message) {
604
- case "The client is closed" /* STRINGS.ERR_CLIENT_CLOSE */:
605
- case "Disconnects client" /* STRINGS.ERR_CLIENT_DISCONNECT */: {
604
+ case "The client is closed":
605
+ case "Disconnects client": {
606
606
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential));
607
607
  if (pool) {
608
608
  await pool.detach(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/redis",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
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.4",
25
- "@e-mc/types": "^0.8.4",
24
+ "@e-mc/db": "^0.8.6",
25
+ "@e-mc/types": "^0.8.6",
26
26
  "redis": "^4.6.13"
27
27
  }
28
28
  }