@pi-r/redis 0.5.0 → 0.5.2

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 2023 Wit Studio
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,5 +1,7 @@
1
- ### @pi-r/redis
1
+ # @pi-r/redis
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Vivy
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
package/client/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { RedisDataSource } from '@e-mc/types/lib/db';
2
-
3
1
  import type { IDbSourceClient } from '@e-mc/db/types';
4
2
 
3
+ import type { RedisDataSource } from '../types';
4
+
5
5
  declare const Redis: IDbSourceClient<RedisDataSource>;
6
6
 
7
7
  export = Redis;
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" /* STRINGS.MODULE_NAME */, 4);
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" /* ERR_DB.UPGRADE */, "redis" /* STRINGS.MODULE_NAME */ + '@' + Db.getPackageVersion("redis" /* STRINGS.MODULE_NAME */));
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 /* VALUES.PORT */);
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 /* VALUES.PORT */)));
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" /* STRINGS.MODULE_NAME */, 'Not defined - uri');
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" /* STRINGS.MODULE_NAME */, password);
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, timeout } = config;
@@ -174,12 +174,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
174
174
  if (!parallel) {
175
175
  outResult || (outResult = new Array(length));
176
176
  }
177
- const caching = this.hasCache("redis" /* STRINGS.MODULE_NAME */, sessionKey);
177
+ const caching = this.hasCache("redis", sessionKey);
178
178
  const tasks = new Array(length);
179
179
  const clients = [];
180
180
  let redisClient, redisCredential, redisCache = 0, onceCredential = connectOnce ? batch[0].options?.client : undefined;
181
181
  const getConnection = async (item, credential) => {
182
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
182
+ item.transactionState = 64;
183
183
  let client;
184
184
  if (item.usePool) {
185
185
  const pool = DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -201,14 +201,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
201
201
  redisClient = client;
202
202
  redisCredential = credential;
203
203
  }
204
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
204
+ item.transactionState &= ~64;
205
205
  return client;
206
206
  };
207
207
  for (let i = 0; i < length; ++i) {
208
208
  const item = batch[i];
209
209
  const { source, uri, key, format = 'HASH', search, aggregate, update, options: clientOptions = {}, cacheObjectKey, ignoreCache } = item;
210
210
  let credential = (redisCredential || onceCredential), error;
211
- 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))) {
211
+ 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))) {
212
212
  ++redisCache;
213
213
  if (this.handleFail(error, item, { errorQuery })) {
214
214
  if (!parallel) {
@@ -225,9 +225,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
225
225
  }
226
226
  continue;
227
227
  }
228
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
228
+ item.transactionState = 1;
229
229
  const uuidKey = (credential.uuidKey || (credential.uuidKey = (onceCredential ? batch[0] : item).credential?.uuidKey));
230
- const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis" /* STRINGS.MODULE_NAME */, 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
230
+ const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
231
231
  const renewCache = ignoreCache === 0;
232
232
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
233
233
  const command = (0, types_1.isPlainObject)(clientOptions.command) ? redis.commandOptions(clientOptions.command) : null;
@@ -257,7 +257,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
257
257
  else {
258
258
  outResult[i] = rows;
259
259
  }
260
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
260
+ this.add(item, 4 | 128);
261
261
  continue;
262
262
  }
263
263
  if (!ignoreCache && outCacheMiss) {
@@ -290,8 +290,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
290
290
  success(target);
291
291
  return;
292
292
  }
293
- const failKey = () => failed((0, types_1.errorMessage)(f, "Invalid key" /* ERR_DB.KEY */, Db.asString(k) || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
294
- const failValue = () => failed((0, types_1.errorMessage)(f, "Invalid value" /* ERR_DB.VALUE */, Db.asString(v) || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
293
+ const failKey = () => failed((0, types_1.errorMessage)(f, "Invalid key", Db.asString(k) || "Unknown"));
294
+ const failValue = () => failed((0, types_1.errorMessage)(f, "Invalid value", Db.asString(v) || "Unknown"));
295
295
  const commandSet = (0, types_1.isPlainObject)(setOptions.command) && redis.commandOptions(setOptions.command);
296
296
  let pending;
297
297
  if ((f = f.toUpperCase()) === 'JSON') {
@@ -300,7 +300,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
300
300
  return;
301
301
  }
302
302
  const path = target.path || '$';
303
- if (this.hasCoerce("redis" /* STRINGS.MODULE_NAME */, 'options', uuidKey)) {
303
+ if (this.hasCoerce("redis", 'options', uuidKey)) {
304
304
  if ((0, types_1.isString)(v) && v.startsWith('new')) {
305
305
  ({ outV: v } = (0, types_1.coerceObject)({ outV: v }));
306
306
  }
@@ -406,7 +406,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
406
406
  success(target);
407
407
  }
408
408
  else {
409
- failed((0, types_1.errorMessage)(f, "Invalid value" /* ERR_DB.VALUE */, has(EX) ? 'EX: ' + EX : has(PX) ? 'PX: ' + PX : EXAT > 0 ? 'EXAT: ' + EX : 'PXAT: ' + PXAT));
409
+ failed((0, types_1.errorMessage)(f, "Invalid value", has(EX) ? 'EX: ' + EX : has(PX) ? 'PX: ' + PX : EXAT > 0 ? 'EXAT: ' + EX : 'PXAT: ' + PXAT));
410
410
  }
411
411
  })
412
412
  .catch(err => failed(err));
@@ -463,7 +463,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
463
463
  error = err;
464
464
  }
465
465
  if (idx && idx !== index) {
466
- 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 }));
466
+ client.ft.dropIndex(idx).catch(err => this.writeFail([`Unable to drop ${target === search ? 'search' : 'aggregate'} index`, idx], err, { type: 65536, fatal: false }));
467
467
  }
468
468
  if (error instanceof Error) {
469
469
  throw error;
@@ -511,16 +511,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
511
511
  rows = (targetObject ? targetObject(item, data) : data);
512
512
  }
513
513
  if (rows === undefined) {
514
- throw (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */);
514
+ throw (0, types_1.errorMessage)(source, "Missing database query");
515
515
  }
516
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
516
+ this.add(item, 4);
517
517
  resolve(this.setQueryResult(source, removePoolProperties(redisCredential || credential), queryString, rows, cacheValue));
518
518
  }
519
519
  catch (err) {
520
520
  if (err instanceof Error) {
521
521
  switch (err.message) {
522
- case "The client is closed" /* STRINGS.ERR_CLIENT_CLOSE */:
523
- case "Disconnects client" /* STRINGS.ERR_CLIENT_DISCONNECT */: {
522
+ case "The client is closed":
523
+ case "Disconnects client": {
524
524
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential));
525
525
  if (pool) {
526
526
  await pool.detach(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/redis",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
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.7.0",
25
- "@e-mc/types": "^0.7.0",
26
- "redis": "^4.6.11"
24
+ "@e-mc/db": "^0.7.2",
25
+ "@e-mc/types": "^0.7.2",
26
+ "redis": "^4.6.13"
27
27
  }
28
28
  }