@jayfong/x-server 2.21.8 → 2.21.10

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.
@@ -148,7 +148,7 @@ class EnvUtil {
148
148
  ${env.comment.split(/[\r\n]+/g).map(line => `* ${line.trim()}`).join('\n*\n')}
149
149
  */
150
150
  ` : ''}
151
- ${env.key}: ${Array.isArray(env.value) ? `Array<${env.value[0] ? typeof env.value[0] : 'any'}>` : typeof env.value};
151
+ ${env.key}: ${EnvUtil.getTypesFromValue(env.value)};
152
152
  `).join('\n')}
153
153
  }
154
154
  }
@@ -160,6 +160,9 @@ class EnvUtil {
160
160
  const types = EnvUtil.makeTypes(envs);
161
161
  await _fsExtra.default.outputFile(outFile, types);
162
162
  }
163
+ static getTypesFromValue(value) {
164
+ return Array.isArray(value) ? `Array<${value[0] ? EnvUtil.getTypesFromValue(value[0]) : 'any'}>` : (0, _vtils.isPlainObject)(value) ? Object.keys(value).length ? `Record<any, ${EnvUtil.getTypesFromValue(value[Object.keys(value)[0]])}>` : `Record<any, any>` : typeof value;
165
+ }
163
166
  }
164
167
  exports.EnvUtil = EnvUtil;
165
168
  EnvUtil.NEWLINE = '\n';
@@ -31,13 +31,17 @@ class CacheService {
31
31
  const ttl = ttlOrOptions == null ? this.options.ttl : typeof ttlOrOptions === 'object' ? ttlOrOptions.ttl : ttlOrOptions;
32
32
  const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
33
33
  if (redisTtl) {
34
- const redisKey = this.toRedisKey(key);
35
- const redisValue = JSON.stringify(value);
36
- await _x.x.redis.set(redisKey, redisValue,
37
- // 毫秒
38
- 'PX', (0, _vtils.ms)(redisTtl));
39
- if (this.options.memory) {
40
- this.memoryCache.set(redisKey, value);
34
+ const redisTtlMs = (0, _vtils.ms)(redisTtl);
35
+ // Redis TTL 不能小于等于 0
36
+ if (redisTtlMs > 0) {
37
+ const redisKey = this.toRedisKey(key);
38
+ const redisValue = JSON.stringify(value);
39
+ await _x.x.redis.set(redisKey, redisValue,
40
+ // 毫秒
41
+ 'PX', redisTtlMs);
42
+ if (this.options.memory) {
43
+ this.memoryCache.set(redisKey, value);
44
+ }
41
45
  }
42
46
  }
43
47
  return value;
@@ -29,4 +29,5 @@ export declare class EnvUtil {
29
29
  file: string;
30
30
  outFile: string;
31
31
  }): Promise<void>;
32
+ private static getTypesFromValue;
32
33
  }
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'node:path';
3
- import { dedent, devOrProd, escapeRegExp, isNumeric } from 'vtils';
3
+ import { dedent, devOrProd, escapeRegExp, isNumeric, isPlainObject } from 'vtils';
4
4
  import { parse as yamlParse } from 'yaml';
5
5
  export class EnvUtil {
6
6
  static normalizeValue(value) {
@@ -143,7 +143,7 @@ export class EnvUtil {
143
143
  ${env.comment.split(/[\r\n]+/g).map(line => `* ${line.trim()}`).join('\n*\n')}
144
144
  */
145
145
  ` : ''}
146
- ${env.key}: ${Array.isArray(env.value) ? `Array<${env.value[0] ? typeof env.value[0] : 'any'}>` : typeof env.value};
146
+ ${env.key}: ${EnvUtil.getTypesFromValue(env.value)};
147
147
  `).join('\n')}
148
148
  }
149
149
  }
@@ -155,6 +155,9 @@ export class EnvUtil {
155
155
  const types = EnvUtil.makeTypes(envs);
156
156
  await fs.outputFile(outFile, types);
157
157
  }
158
+ static getTypesFromValue(value) {
159
+ return Array.isArray(value) ? `Array<${value[0] ? EnvUtil.getTypesFromValue(value[0]) : 'any'}>` : isPlainObject(value) ? Object.keys(value).length ? `Record<any, ${EnvUtil.getTypesFromValue(value[Object.keys(value)[0]])}>` : `Record<any, any>` : typeof value;
160
+ }
158
161
  }
159
162
  EnvUtil.NEWLINE = '\n';
160
163
  EnvUtil.RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/;
@@ -26,13 +26,17 @@ export class CacheService {
26
26
  const ttl = ttlOrOptions == null ? this.options.ttl : typeof ttlOrOptions === 'object' ? ttlOrOptions.ttl : ttlOrOptions;
27
27
  const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
28
28
  if (redisTtl) {
29
- const redisKey = this.toRedisKey(key);
30
- const redisValue = JSON.stringify(value);
31
- await x.redis.set(redisKey, redisValue,
32
- // 毫秒
33
- 'PX', ms(redisTtl));
34
- if (this.options.memory) {
35
- this.memoryCache.set(redisKey, value);
29
+ const redisTtlMs = ms(redisTtl);
30
+ // Redis TTL 不能小于等于 0
31
+ if (redisTtlMs > 0) {
32
+ const redisKey = this.toRedisKey(key);
33
+ const redisValue = JSON.stringify(value);
34
+ await x.redis.set(redisKey, redisValue,
35
+ // 毫秒
36
+ 'PX', redisTtlMs);
37
+ if (this.options.memory) {
38
+ this.memoryCache.set(redisKey, value);
39
+ }
36
40
  }
37
41
  }
38
42
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.21.8",
3
+ "version": "2.21.10",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -67,7 +67,7 @@
67
67
  "tsx": "^3.12.7",
68
68
  "utf-8-validate": "^5.0.9",
69
69
  "vscode-generate-index-standalone": "^1.7.1",
70
- "vtils": "^4.92.0",
70
+ "vtils": "^4.95.0",
71
71
  "yaml": "^2.3.1",
72
72
  "yargs": "^17.4.1"
73
73
  },