@seayoo-web/kms 3.3.1 → 3.4.0
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/index.js +79 -41
- package/package.json +5 -5
- package/types/src/dsi.d.ts +3 -0
package/dist/index.js
CHANGED
|
@@ -1,39 +1,77 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
return typeof
|
|
1
|
+
const c = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")();
|
|
2
|
+
function j(t) {
|
|
3
|
+
return typeof t == "function";
|
|
4
4
|
}
|
|
5
|
-
function x(
|
|
6
|
-
return typeof
|
|
5
|
+
function x(t) {
|
|
6
|
+
return typeof t == "object" && t !== null;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
return "
|
|
8
|
+
function S() {
|
|
9
|
+
return "wx" in c && x(c.wx) && "getSystemInfo" in c.wx && j(c.wx.getSystemInfo);
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function D() {
|
|
12
|
+
return "localStorage" in c && x(c.localStorage) && "getItem" in c.localStorage && j(c.localStorage.getItem);
|
|
13
|
+
}
|
|
14
|
+
function C(t, e) {
|
|
12
15
|
try {
|
|
13
|
-
const
|
|
14
|
-
return
|
|
16
|
+
const r = JSON.parse(t);
|
|
17
|
+
return e ? e(r) ? r : null : r;
|
|
15
18
|
} catch {
|
|
16
19
|
return null;
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const P = {
|
|
23
|
+
get(t) {
|
|
24
|
+
return localStorage.getItem(t) || "";
|
|
25
|
+
},
|
|
26
|
+
set(t, e) {
|
|
27
|
+
localStorage.setItem(t, e);
|
|
28
|
+
},
|
|
29
|
+
remove(t) {
|
|
30
|
+
localStorage.removeItem(t);
|
|
31
|
+
}
|
|
32
|
+
}, E = {
|
|
33
|
+
get(t) {
|
|
34
|
+
try {
|
|
35
|
+
if (S()) return wx.getStorageSync(t) || "";
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.error("getStorageSyncError", e);
|
|
38
|
+
}
|
|
39
|
+
return "";
|
|
40
|
+
},
|
|
41
|
+
set(t, e) {
|
|
42
|
+
try {
|
|
43
|
+
S() && wx.setStorageSync(t, e);
|
|
44
|
+
} catch (r) {
|
|
45
|
+
console.error("setStorageSyncError", r);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
remove(t) {
|
|
49
|
+
try {
|
|
50
|
+
S() && wx.removeStorageSync(t);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error("removeStorageSync", e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
function J(t) {
|
|
57
|
+
const e = {}, { group: r, filter: n, filterLogic: i, range: o, created: s, updated: g, size: f, page: l, sort: a } = t, { sn: w, fields: u, dataFields: y, multi: v, combo: $, pure: A = "items", label: h, value: p, option: d } = t;
|
|
58
|
+
if (w && (e.sn = w), r && (e.g = Array.isArray(r) ? r.join(",") : r), n) {
|
|
59
|
+
const I = i === "or" ? "|" : "+", O = Object.keys(n);
|
|
60
|
+
e.filter = O.map((m) => {
|
|
24
61
|
const b = n[m];
|
|
25
62
|
return Array.isArray(b) ? `${m}:${b.join(",")}` : `${m}:${b}`;
|
|
26
|
-
}).join(
|
|
63
|
+
}).join(I);
|
|
27
64
|
}
|
|
28
|
-
return
|
|
65
|
+
return o && (e.r = o), s && (e.created = s.join("-")), g && (e.updated = g.join("-")), a && (e.sort = Array.isArray(a) ? a.join(",") : a), v === !1 && (e.m = "n"), f && (e.s = `${f}`), l && (e.p = `${l}`), u && (e.f = Array.isArray(u) ? u.join(",") : u), y && (e.df = Array.isArray(y) ? y.join(",") : y), $ === !0 && (u ? e.c = "y" : console.warn("设置 combo:true 必须要同步设置 fields")), A && (e.pure = A === "items" ? "items" : "y"), h && (e.label = Array.isArray(h) ? h.join(",") : h), p && (e.value = Array.isArray(p) ? p.join(",") : p), d && (e.option = d), e._ = Math.random().toString(16).slice(-8), e;
|
|
29
66
|
}
|
|
30
|
-
function
|
|
31
|
-
return
|
|
67
|
+
function N(t) {
|
|
68
|
+
return t.replace(/(?:^https?:\/\/|\/*$)/gi, "").toLowerCase();
|
|
32
69
|
}
|
|
33
|
-
class
|
|
70
|
+
class L {
|
|
34
71
|
req;
|
|
35
72
|
enabledCache;
|
|
36
73
|
cachePrefix;
|
|
74
|
+
storage;
|
|
37
75
|
/**
|
|
38
76
|
* 设置请求的 endpoint 和请求工具来初始化 KMS Dsi,第三个可选参数 enabledCache 来激活本地缓存数据
|
|
39
77
|
*
|
|
@@ -41,37 +79,37 @@ class N {
|
|
|
41
79
|
*
|
|
42
80
|
* 本地缓存有效期最长为 24 小时
|
|
43
81
|
*/
|
|
44
|
-
constructor(
|
|
45
|
-
const
|
|
46
|
-
this.enabledCache = n, this.cachePrefix =
|
|
82
|
+
constructor(e, r, n = !1) {
|
|
83
|
+
const i = `https://${N(e)}`;
|
|
84
|
+
this.storage = S() ? E : D() ? P : null, this.enabledCache = n, this.storage === null && n && console.warn("[KMSDsi] 缓存功能需要本地存储支持"), this.cachePrefix = i.replace(/^https:\/\//i, "").replace(/[./]/g, "-") + ":", this.req = r({ baseURL: i, timeout: 6e3, maxRetry: 2, retryInterval: 150 });
|
|
47
85
|
}
|
|
48
86
|
/**
|
|
49
87
|
* 查询 Dsi 数据接口并返回接口响应,可设置是否启用本地缓存以应对网络错误的情况
|
|
50
88
|
*/
|
|
51
|
-
async query({ key:
|
|
52
|
-
const { data:
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
55
|
-
if (!
|
|
56
|
-
return
|
|
57
|
-
const f =
|
|
89
|
+
async query({ key: e, query: r, guard: n, cache: i }) {
|
|
90
|
+
const { data: o } = await this.req.get(e, n, { params: J(r) }), s = i ?? this.enabledCache, g = this.cachePrefix + e + (r.page ? `:p${r.page}` : "");
|
|
91
|
+
if (o !== null)
|
|
92
|
+
return s && this.storage?.set(g, JSON.stringify([Date.now(), r, o])), o;
|
|
93
|
+
if (!s)
|
|
94
|
+
return o;
|
|
95
|
+
const f = this.storage?.get(`${this.cachePrefix}${e}`);
|
|
58
96
|
if (f) {
|
|
59
|
-
const
|
|
60
|
-
return Array.isArray(
|
|
97
|
+
const l = C(f, function(a) {
|
|
98
|
+
return Array.isArray(a) && a.length === 3 && typeof a[0] == "number" && n(a[1]);
|
|
61
99
|
});
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
100
|
+
if (l && K(r, l[1]) && l[0] + 24 * 3600 * 1e3 > Date.now())
|
|
101
|
+
return l[2];
|
|
64
102
|
}
|
|
65
|
-
return
|
|
103
|
+
return o;
|
|
66
104
|
}
|
|
67
105
|
}
|
|
68
|
-
function
|
|
69
|
-
const
|
|
70
|
-
return
|
|
71
|
-
const
|
|
72
|
-
return
|
|
106
|
+
function K(t, e) {
|
|
107
|
+
const r = Object.keys(t);
|
|
108
|
+
return r.length === Object.keys(e).length && r.every((n) => {
|
|
109
|
+
const i = t[n], o = e[n], s = typeof i;
|
|
110
|
+
return s === "string" || s === "number" || s === "boolean" || s === "bigint" ? i === o : JSON.stringify(i) === JSON.stringify(o);
|
|
73
111
|
});
|
|
74
112
|
}
|
|
75
113
|
export {
|
|
76
|
-
|
|
114
|
+
L as KMSDsi
|
|
77
115
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seayoo-web/kms",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "agent for seayoo.kms",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "index.ts",
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@seayoo-web/request": "^3.4.
|
|
23
|
-
"@seayoo-web/utils": "4.
|
|
24
|
-
"@seayoo-web/scripts": "^3.1.
|
|
22
|
+
"@seayoo-web/request": "^3.4.2",
|
|
23
|
+
"@seayoo-web/utils": "4.2.0",
|
|
24
|
+
"@seayoo-web/scripts": "^3.1.7",
|
|
25
25
|
"@seayoo-web/tsconfig": "^1.0.5"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@seayoo-web/request": "^3.4.
|
|
28
|
+
"@seayoo-web/request": "^3.4.2"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"prebuild": "pnpm --F request build",
|
package/types/src/dsi.d.ts
CHANGED
|
@@ -68,6 +68,8 @@ export interface DsiQueryParam {
|
|
|
68
68
|
sort?: QuerySortWithDefault | QuerySortWithDefault[];
|
|
69
69
|
/**
|
|
70
70
|
* 是否返回所有符合要求的数据记录合集,默认 true
|
|
71
|
+
*
|
|
72
|
+
* 设置为 false 时,仅仅返回第一个符合要求的记录,如果没有任何符合要求的记录响应为 null
|
|
71
73
|
*/
|
|
72
74
|
multi?: boolean;
|
|
73
75
|
/**
|
|
@@ -155,6 +157,7 @@ export declare class KMSDsi {
|
|
|
155
157
|
req: ReturnType<NetRequestFactory>;
|
|
156
158
|
private enabledCache;
|
|
157
159
|
private cachePrefix;
|
|
160
|
+
private storage;
|
|
158
161
|
/**
|
|
159
162
|
* 设置请求的 endpoint 和请求工具来初始化 KMS Dsi,第三个可选参数 enabledCache 来激活本地缓存数据
|
|
160
163
|
*
|