@zenweb/cache 5.0.1 → 5.0.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/dist/utils.d.ts CHANGED
@@ -16,7 +16,6 @@ export declare function sleep(ms: number): Promise<void>;
16
16
  * @returns 执行结果
17
17
  */
18
18
  export declare function runRedisScript(redis: Redis, hash: string, script: string, keys: RedisKey[], values?: RedisValue[]): Promise<unknown>;
19
- export declare function isPlainObject(obj: unknown): boolean;
20
19
  /**
21
20
  * 生成一个参数缓存key
22
21
  * - 多个元素用 : 连接
package/dist/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { zenwebDebug } from '@zenweb/core';
2
- import * as crypto from 'node:crypto';
2
+ import crypto from 'node:crypto';
3
3
  export const debug = zenwebDebug('cache');
4
4
  /**
5
5
  * Promise 等待
@@ -35,11 +35,6 @@ export async function runRedisScript(redis, hash, script, keys, values = []) {
35
35
  throw err;
36
36
  }
37
37
  }
38
- export function isPlainObject(obj) {
39
- return typeof obj === 'object'
40
- && obj !== null
41
- && Object.getPrototypeOf(obj) === Object.prototype;
42
- }
43
38
  /**
44
39
  * 将一个嵌套对象转换为平面字符串结构
45
40
  */
@@ -50,7 +45,10 @@ function plainify(obj) {
50
45
  if (obj instanceof Date) {
51
46
  return obj.toJSON();
52
47
  }
53
- if (isPlainObject(obj)) {
48
+ if (Buffer.isBuffer(obj)) {
49
+ return obj.toString('utf-8');
50
+ }
51
+ if (obj && typeof obj === 'object') {
54
52
  return Object.keys(obj).sort().map(k => `${k}=${plainify(obj[k])}`).join('&');
55
53
  }
56
54
  return String(obj);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zenweb/cache",
3
3
  "type": "module",
4
- "version": "5.0.1",
4
+ "version": "5.0.2",
5
5
  "description": "Zenweb Cache module",
6
6
  "exports": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",