@seayoo-web/kms 3.1.3 → 3.3.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 +52 -24
- package/package.json +7 -3
- package/types/src/dsi.d.ts +10 -3
package/dist/index.js
CHANGED
|
@@ -1,35 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const g = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")();
|
|
2
|
+
function v(r) {
|
|
3
|
+
return typeof r == "function";
|
|
4
|
+
}
|
|
5
|
+
function C(r) {
|
|
6
|
+
return typeof r == "object" && r !== null;
|
|
7
|
+
}
|
|
8
|
+
function I() {
|
|
9
|
+
return "localStorage" in g && C(g.localStorage) && "getItem" in g.localStorage && v(g.localStorage.getItem);
|
|
10
|
+
}
|
|
11
|
+
function P(r, e) {
|
|
12
|
+
try {
|
|
13
|
+
const t = JSON.parse(r);
|
|
14
|
+
return e ? e(t) ? t : null : t;
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function D(r) {
|
|
20
|
+
const e = {}, { group: t, filter: n, filterLogic: a, range: o, created: s, updated: u, size: f, page: c, sort: i } = r, { sn: b, fields: l, dataFields: y, multi: S, combo: $, pure: d = "items", label: h, value: p, option: j } = r;
|
|
21
|
+
if (b && (e.sn = b), t && (e.g = Array.isArray(t) ? t.join(",") : t), n) {
|
|
22
|
+
const w = a === "or" ? "|" : "+", x = Object.keys(n);
|
|
23
|
+
e.filter = x.map((m) => {
|
|
24
|
+
const A = n[m];
|
|
25
|
+
return Array.isArray(A) ? `${m}:${A.join(",")}` : `${m}:${A}`;
|
|
26
|
+
}).join(w);
|
|
9
27
|
}
|
|
10
|
-
return
|
|
28
|
+
return o && (e.r = o), s && (e.created = s.join("-")), u && (e.updated = u.join("-")), i && (e.sort = Array.isArray(i) ? i.join(",") : i), S === !1 && (e.m = "n"), f && (e.s = `${f}`), c && (e.p = `${c}`), l && (e.f = Array.isArray(l) ? l.join(",") : l), y && (e.df = Array.isArray(y) ? y.join(",") : y), $ === !0 && (l ? e.c = "y" : console.warn("设置 combo:true 必须要同步设置 fields")), d && (e.pure = d === "items" ? "items" : "y"), h && (e.label = Array.isArray(h) ? h.join(",") : h), p && (e.value = Array.isArray(p) ? p.join(",") : p), j && (e.option = j), e._ = Math.random().toString(16).slice(-8), e;
|
|
11
29
|
}
|
|
12
|
-
function
|
|
13
|
-
return
|
|
30
|
+
function q(r) {
|
|
31
|
+
return r.replace(/(?:^https?:\/\/|\/*$)/gi, "").toLowerCase();
|
|
14
32
|
}
|
|
15
|
-
class
|
|
33
|
+
class L {
|
|
16
34
|
req;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
retryInterval: 150
|
|
23
|
-
});
|
|
35
|
+
enabledCache;
|
|
36
|
+
cachePrefix;
|
|
37
|
+
constructor(e, t, n = !1) {
|
|
38
|
+
const a = `https://${q(e)}`;
|
|
39
|
+
this.enabledCache = n, this.cachePrefix = a.replace(/^https:\/\//i, "").replace(/[./]/g, "-") + ":", this.req = t({ baseURL: a, timeout: 6e3, maxRetry: 2, retryInterval: 150 });
|
|
24
40
|
}
|
|
25
41
|
/**
|
|
26
|
-
* 查询 Dsi
|
|
42
|
+
* 查询 Dsi 数据接口并返回接口响应,可设置是否启用本地缓存以应对网络错误的情况
|
|
27
43
|
*/
|
|
28
|
-
async query({ key:
|
|
29
|
-
const { data:
|
|
30
|
-
|
|
44
|
+
async query({ key: e, query: t, guard: n, option: a }) {
|
|
45
|
+
const { data: o } = await this.req.get(e, n, { params: D(t) }), s = (a?.cache ?? this.enabledCache) && I(), u = this.cachePrefix + e;
|
|
46
|
+
if (o !== null)
|
|
47
|
+
return s && localStorage.setItem(u, JSON.stringify([Date.now(), o])), o;
|
|
48
|
+
if (!s)
|
|
49
|
+
return o;
|
|
50
|
+
const f = localStorage.getItem(`${this.cachePrefix}${e}`);
|
|
51
|
+
if (f) {
|
|
52
|
+
const c = P(f, function(i) {
|
|
53
|
+
return Array.isArray(i) && i.length === 2 && typeof i[0] == "number" && n(i[1]);
|
|
54
|
+
});
|
|
55
|
+
if (c && c[0] + 24 * 3600 * 1e3 > Date.now())
|
|
56
|
+
return c[1];
|
|
57
|
+
}
|
|
58
|
+
return o;
|
|
31
59
|
}
|
|
32
60
|
}
|
|
33
61
|
export {
|
|
34
|
-
|
|
62
|
+
L as KMSDsi
|
|
35
63
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seayoo-web/kms",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "agent for seayoo.kms",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "index.ts",
|
|
@@ -19,10 +19,14 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@seayoo-web/request": "^3.
|
|
23
|
-
"@seayoo-web/scripts": "^
|
|
22
|
+
"@seayoo-web/request": "^3.4.0",
|
|
23
|
+
"@seayoo-web/scripts": "^3.1.2",
|
|
24
|
+
"@seayoo-web/utils": "4.1.3",
|
|
24
25
|
"@seayoo-web/tsconfig": "^1.0.5"
|
|
25
26
|
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@seayoo-web/request": "^3.4.0"
|
|
29
|
+
},
|
|
26
30
|
"scripts": {
|
|
27
31
|
"prebuild": "pnpm --F request build",
|
|
28
32
|
"build": "vite build && tsc --emitDeclarationOnly",
|
package/types/src/dsi.d.ts
CHANGED
|
@@ -149,13 +149,20 @@ export interface DsiQueryOption<T> {
|
|
|
149
149
|
query: DsiQueryParam;
|
|
150
150
|
/** 响应数据守卫函数 */
|
|
151
151
|
guard: (data: unknown) => data is T;
|
|
152
|
+
/** 可选更多配置 */
|
|
153
|
+
option?: {
|
|
154
|
+
/** 开启自动缓存配置,开启后将缓存 dsi 数据,并在 dsi 接口错误时以缓存数据作为返回 */
|
|
155
|
+
cache?: boolean;
|
|
156
|
+
};
|
|
152
157
|
}
|
|
153
158
|
export declare class KMSDsi {
|
|
154
159
|
req: ReturnType<NetRequestFactory>;
|
|
155
|
-
|
|
160
|
+
private enabledCache;
|
|
161
|
+
private cachePrefix;
|
|
162
|
+
constructor(endpoint: string, request: NetRequestFactory, enabledCache?: boolean);
|
|
156
163
|
/**
|
|
157
|
-
* 查询 Dsi
|
|
164
|
+
* 查询 Dsi 数据接口并返回接口响应,可设置是否启用本地缓存以应对网络错误的情况
|
|
158
165
|
*/
|
|
159
|
-
query<T = unknown>({ key, query, guard }: DsiQueryOption<T>): Promise<T | null>;
|
|
166
|
+
query<T = unknown>({ key, query, guard, option }: DsiQueryOption<T>): Promise<T | null>;
|
|
160
167
|
}
|
|
161
168
|
export {};
|