@seayoo-web/kms 2.0.0 → 2.0.1
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/README.md +1 -0
- package/dist/index.js +24 -27
- package/package.json +1 -1
- package/types/src/dsi.d.ts +16 -15
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
import { NetRequest as
|
|
2
|
-
const { get:
|
|
3
|
-
function
|
|
4
|
-
const r = {}, { group: i, filter:
|
|
5
|
-
if (
|
|
6
|
-
const D =
|
|
7
|
-
r.filter =
|
|
8
|
-
const u =
|
|
1
|
+
import { NetRequest as L, jsonp as k, jsonx as q } from "@seayoo-web/request";
|
|
2
|
+
const { get: z } = L({ timeout: 15e3 });
|
|
3
|
+
function y(t) {
|
|
4
|
+
const r = {}, { group: i, filter: a, filterLogic: n, range: l, created: d, updated: m, size: A, page: $, sort: s } = t, { sn: g, fields: o, dataFields: e, multi: h, combo: v, pure: b = "items", label: f, value: c, option: w } = t;
|
|
5
|
+
if (g && (r.sn = g), i && (r.g = Array.isArray(i) ? i.join(",") : i), a) {
|
|
6
|
+
const D = n === "or" ? "|" : "+", x = Object.keys(a);
|
|
7
|
+
r.filter = x.map((p) => {
|
|
8
|
+
const u = a[p];
|
|
9
9
|
return Array.isArray(u) ? `${p}:${u.join(",")}` : `${p}:${u}`;
|
|
10
10
|
}).join(D);
|
|
11
11
|
}
|
|
12
|
-
return
|
|
12
|
+
return l && (r.r = l), d && (r.created = d.join("-")), m && (r.updated = m.join("-")), s && (r.sort = Array.isArray(s) ? s.join(",") : s), h === !1 && (r.m = "n"), A && (r.s = `${A}`), $ && (r.p = `${$}`), o && (r.f = Array.isArray(o) ? o.join(",") : o), e && (r.df = Array.isArray(e) ? e.join(",") : e), v === !0 && (o ? r.c = "y" : console.warn("设置 combo:true 必须要同步设置 fields")), b && (r.pure = b === "items" ? "items" : "y"), f && (r.label = Array.isArray(f) ? f.join(",") : f), c && (r.value = Array.isArray(c) ? c.join(",") : c), w && (r.option = w), r;
|
|
13
13
|
}
|
|
14
|
-
async function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
query: i,
|
|
18
|
-
guard: t
|
|
19
|
-
}) {
|
|
20
|
-
const { data: s } = await x(`https://${a}/${r}`, t, { params: b(i) });
|
|
21
|
-
return s;
|
|
14
|
+
async function E({ endpoint: t, key: r, query: i, guard: a }) {
|
|
15
|
+
const { data: n } = await z(`https://${j(t)}/${r}`, a, { params: y(i) });
|
|
16
|
+
return n;
|
|
22
17
|
}
|
|
23
|
-
async function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
18
|
+
async function F({ endpoint: t, key: r, query: i, guard: a }) {
|
|
19
|
+
return await k(`https://${j(t)}/${r}/jsonp`, a, y(i));
|
|
20
|
+
}
|
|
21
|
+
async function N({ endpoint: t, key: r, query: i, guard: a }) {
|
|
22
|
+
return await q(`https://${j(t)}/${r}/script`, a, y(i));
|
|
23
|
+
}
|
|
24
|
+
function j(t) {
|
|
25
|
+
return t.replace(/(?:^https?:\/\/|\/*$)/gi, "").toLowerCase();
|
|
30
26
|
}
|
|
31
27
|
export {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
y as convertDsiParam,
|
|
29
|
+
F as jsonpDsi,
|
|
30
|
+
N as jsonxDsi,
|
|
31
|
+
E as queryDsi
|
|
35
32
|
};
|
package/package.json
CHANGED
package/types/src/dsi.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
type DsiProdEndpoint = `${string}.dsi.seayoo.com` | "dsi.seayoo.com" | `${string}.dsi.seayoo.io` | "dsi.seayoo.io";
|
|
2
|
-
type DsiDevEndpoint = `${string}.dsi.dev.seayoo.com` | "dsi.dev.seayoo.com" | `${string}.dsi.dev.seayoo.io` | "dsi.dev.seayoo.io";
|
|
3
|
-
export type DsiEndpoint = DsiProdEndpoint | DsiDevEndpoint;
|
|
4
1
|
type BaseFieldType = string | number | null;
|
|
5
2
|
type QuerySortBaseField = "start" | "end" | "created" | "order" | "updated" | `data.${string}`;
|
|
6
3
|
type QuerySortField = QuerySortBaseField | `-${QuerySortBaseField}`;
|
|
@@ -143,22 +140,26 @@ export interface DsiQueryParam {
|
|
|
143
140
|
* 将查询配置转成 dsi 查询参数
|
|
144
141
|
*/
|
|
145
142
|
export declare function convertDsiParam(query: DsiQueryParam): Record<string, string>;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
endpoint: DsiEndpoint;
|
|
143
|
+
interface DsiQueryOption<T> {
|
|
144
|
+
/** dsi 服务器地址,比如 xxx.dsi.seayoo.com */
|
|
145
|
+
endpoint: string;
|
|
146
|
+
/** dsi key / alias */
|
|
151
147
|
key: string;
|
|
148
|
+
/** 查询参数 */
|
|
152
149
|
query: DsiQueryParam;
|
|
150
|
+
/** 响应数据守卫函数 */
|
|
153
151
|
guard: (data: unknown) => data is T;
|
|
154
|
-
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 查询 Dsi 数据接口并返回接口响应
|
|
155
|
+
*/
|
|
156
|
+
export declare function queryDsi<T = unknown>({ endpoint, key, query, guard }: DsiQueryOption<T>): Promise<T | null>;
|
|
155
157
|
/**
|
|
156
158
|
* 通过 jsonp 方式加载 dsi 数据
|
|
157
159
|
*/
|
|
158
|
-
export declare function jsonpDsi<T = unknown>({ endpoint, key, query, guard
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}): Promise<T | null>;
|
|
160
|
+
export declare function jsonpDsi<T = unknown>({ endpoint, key, query, guard }: DsiQueryOption<T>): Promise<T | null>;
|
|
161
|
+
/**
|
|
162
|
+
* 通过 jsonx(script) 方式加载 dsi 数据
|
|
163
|
+
*/
|
|
164
|
+
export declare function jsonxDsi<T = unknown>({ endpoint, key, query, guard }: DsiQueryOption<T>): Promise<T | null>;
|
|
164
165
|
export {};
|