@pi-r/redis 0.10.4 → 0.10.6

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.
Files changed (2) hide show
  1. package/client/index.js +15 -16
  2. package/package.json +3 -3
package/client/index.js CHANGED
@@ -134,9 +134,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
134
134
  if (length === 0) {
135
135
  return [];
136
136
  }
137
- let parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss;
137
+ let parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss;
138
138
  if ((0, types_1.isPlainObject)(options)) {
139
- ({ parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
139
+ ({ parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss } = options);
140
140
  }
141
141
  else {
142
142
  if (typeof options === 'string') {
@@ -189,7 +189,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
189
189
  }
190
190
  for (let i = 0; i < length; ++i) {
191
191
  const item = batch[i];
192
- const { source, key, format = 'HASH', search, aggregate, options: clientOptions = {}, ignoreCache } = item;
192
+ const { source, key, search, aggregate, options: clientOptions = {}, ignoreCache } = item;
193
193
  let credential = (redisCredential || onceCredential), error;
194
194
  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", item.uri))) {
195
195
  ++redisCache;
@@ -213,6 +213,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
213
213
  const uuidKey = credential.uuidKey ||= (onceCredential ? batch[0] : item).credential?.uuidKey;
214
214
  const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
215
215
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
216
+ const format = (key ? item.format?.toUpperCase() || 'HASH' : undefined);
216
217
  if (command) {
217
218
  command.signal ||= this.signal;
218
219
  }
@@ -224,17 +225,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
224
225
  else if ((0, types_1.isObject)(aggregate)) {
225
226
  queryString = Db.asString(aggregate, true);
226
227
  }
227
- else if (!targetObject) {
228
- queryString = Db.asString(key, true);
229
- }
230
- else if (item.cacheObjectKey) {
231
- queryString = Db.asString(key, true) + '_' + targetObject.toString() + item.cacheObjectKey;
232
- }
233
- if (queryString) {
234
- queryString += '_' + format;
228
+ else if (key) {
229
+ queryString = Db.asString(key, true) + '_' + format;
230
+ if (targetObject && typeof item.cacheObjectKey === 'string') {
231
+ queryString += '_' + targetObject.toString() + item.cacheObjectKey;
232
+ }
235
233
  }
236
- if (ignoreCache !== 1) {
237
- rows = this.getQueryResult(source, DbPool.sanitize(credential), queryString, cacheValue);
234
+ if (ignoreCache !== 1 && !item.update) {
235
+ rows = this.getQueryResult(source, DbPool.sanitize(redisCredential || credential), queryString, cacheValue);
238
236
  if (rows) {
239
237
  ++redisCache;
240
238
  if (parallel) {
@@ -435,7 +433,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
435
433
  }
436
434
  if (pending) {
437
435
  pending.then(async (code) => {
438
- if (code === undefined || code === null || code !== -Infinity && (0, types_1.isString)(code) && code !== 'OK' || typeof code === 'number' && code <= codeMin || Array.isArray(code) && code.every(resp => resp === null || typeof resp === 'number' && resp <= codeMin)) {
436
+ if (code === undefined || code === null || (0, types_1.isString)(code) && code !== 'OK' && codeMin !== -Infinity || typeof code === 'number' && code <= codeMin || Array.isArray(code) && code.every(resp => resp === null || typeof resp === 'number' && resp <= codeMin)) {
439
437
  failValue();
440
438
  return;
441
439
  }
@@ -539,7 +537,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
539
537
  else if (key) {
540
538
  let data;
541
539
  if (Array.isArray(key)) {
542
- switch (format.toUpperCase()) {
540
+ switch (format) {
543
541
  case 'HKEYS':
544
542
  data = await Promise.all(key.map(async (k) => client.hKeys(...command ? [command, k] : [k])));
545
543
  break;
@@ -558,7 +556,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
558
556
  }
559
557
  }
560
558
  else {
561
- switch (format.toUpperCase()) {
559
+ switch (format) {
562
560
  case 'HKEYS':
563
561
  data = await client.hKeys(...command ? [command, key] : [key]);
564
562
  break;
@@ -625,6 +623,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
625
623
  }
626
624
  return this.processRows(batch, tasks, clients.length === 0 ? parallel : {
627
625
  parallel,
626
+ errorAsEmpty,
628
627
  disconnect() {
629
628
  for (const item of clients) {
630
629
  void item.disconnect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/redis",
3
- "version": "0.10.4",
3
+ "version": "0.10.6",
4
4
  "description": "Redis client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/db": "^0.12.16",
24
- "@e-mc/types": "^0.12.16",
23
+ "@e-mc/db": "^0.12.18",
24
+ "@e-mc/types": "^0.12.18",
25
25
  "redis": "^4.7.1"
26
26
  }
27
27
  }