@kevisual/query 0.0.49 → 0.0.50
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/query-api.d.ts +7 -2
- package/dist/query-api.js +14 -7
- package/package.json +3 -3
- package/src/create-query/index.ts +18 -6
- package/src/query-api.ts +11 -10
package/dist/query-api.d.ts
CHANGED
|
@@ -229,7 +229,12 @@ type RouteInfo = {
|
|
|
229
229
|
};
|
|
230
230
|
};
|
|
231
231
|
};
|
|
232
|
-
|
|
232
|
+
type CreateQueryOptions = {
|
|
233
|
+
removeViewItem?: boolean;
|
|
234
|
+
before?: string;
|
|
235
|
+
after?: string;
|
|
236
|
+
};
|
|
237
|
+
declare const createQueryByRoutes: (list: RouteInfo[], options?: CreateQueryOptions) => string;
|
|
233
238
|
|
|
234
239
|
type Pos = {
|
|
235
240
|
path?: string;
|
|
@@ -311,7 +316,7 @@ type ApiMethods<P extends {
|
|
|
311
316
|
};
|
|
312
317
|
}> = {
|
|
313
318
|
[Path in keyof P]: {
|
|
314
|
-
[Key in keyof P[Path]]: (data?: ExtractArgsFromMetadata<P[Path][Key]>, opts?: DataOpts) =>
|
|
319
|
+
[Key in keyof P[Path]]: <T = any>(data?: ExtractArgsFromMetadata<P[Path][Key]>, opts?: DataOpts) => Promise<Result<T>>;
|
|
315
320
|
};
|
|
316
321
|
};
|
|
317
322
|
type QueryApiOpts<P extends {
|
package/dist/query-api.js
CHANGED
|
@@ -288,7 +288,7 @@ class Query {
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
// node_modules/@kevisual/router/dist/router-browser.js
|
|
291
|
+
// node_modules/.pnpm/@kevisual+router@0.0.84/node_modules/@kevisual/router/dist/router-browser.js
|
|
292
292
|
var __create = Object.create;
|
|
293
293
|
var __getProtoOf = Object.getPrototypeOf;
|
|
294
294
|
var __defProp = Object.defineProperty;
|
|
@@ -14039,8 +14039,14 @@ var toJSONSchema3 = toJSONSchema2;
|
|
|
14039
14039
|
var fromJSONSchema3 = fromJSONSchema2;
|
|
14040
14040
|
|
|
14041
14041
|
// src/create-query/index.ts
|
|
14042
|
-
var
|
|
14042
|
+
var removeViewItemCotnextFromRoutes = (list, options) => {
|
|
14043
14043
|
for (const route of list) {
|
|
14044
|
+
if (options?.removeViewItem) {
|
|
14045
|
+
if (route.metadata?.viewItem) {
|
|
14046
|
+
delete route.metadata.viewItem;
|
|
14047
|
+
}
|
|
14048
|
+
continue;
|
|
14049
|
+
}
|
|
14044
14050
|
if (route.metadata?.viewItem) {
|
|
14045
14051
|
if (route.metadata.viewItem?.api?.query) {
|
|
14046
14052
|
delete route.metadata.viewItem.api.query;
|
|
@@ -14055,9 +14061,9 @@ var removeViewItemFromRoutes = (list) => {
|
|
|
14055
14061
|
}
|
|
14056
14062
|
return list;
|
|
14057
14063
|
};
|
|
14058
|
-
var createQueryByRoutes = (list) => {
|
|
14064
|
+
var createQueryByRoutes = (list, options) => {
|
|
14059
14065
|
const obj = {};
|
|
14060
|
-
list =
|
|
14066
|
+
list = removeViewItemCotnextFromRoutes(list, options);
|
|
14061
14067
|
for (const route of list) {
|
|
14062
14068
|
if (!obj[route.path]) {
|
|
14063
14069
|
obj[route.path] = {};
|
|
@@ -14071,11 +14077,12 @@ var createQueryByRoutes = (list) => {
|
|
|
14071
14077
|
}
|
|
14072
14078
|
obj[route.path][route.key] = route;
|
|
14073
14079
|
}
|
|
14074
|
-
const
|
|
14075
|
-
|
|
14080
|
+
const before = options?.before || `import { createQueryApi } from '@kevisual/query/api';`;
|
|
14081
|
+
const after = options?.after || `export { queryApi };`;
|
|
14082
|
+
const code = `${before}
|
|
14076
14083
|
const api = ${generateApiCode(obj)} as const;
|
|
14077
14084
|
const queryApi = createQueryApi({ api });
|
|
14078
|
-
|
|
14085
|
+
${after}
|
|
14079
14086
|
`;
|
|
14080
14087
|
return code;
|
|
14081
14088
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/query",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm run clean && bun run bun.config.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"description": "",
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@kevisual/code-builder": "^0.0.6",
|
|
22
|
-
"@kevisual/router": "^0.0.
|
|
23
|
-
"@types/node": "^25.
|
|
22
|
+
"@kevisual/router": "^0.0.84",
|
|
23
|
+
"@types/node": "^25.3.0",
|
|
24
24
|
"typescript": "^5.9.3",
|
|
25
25
|
"es-toolkit": "^1.44.0",
|
|
26
26
|
"zod": "^4.3.6",
|
|
@@ -22,8 +22,14 @@ type RouteInfo = {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
const
|
|
25
|
+
const removeViewItemCotnextFromRoutes = (list: RouteInfo[], options?: CreateQueryOptions) => {
|
|
26
26
|
for (const route of list) {
|
|
27
|
+
if (options?.removeViewItem) {
|
|
28
|
+
if (route.metadata?.viewItem) {
|
|
29
|
+
delete route.metadata.viewItem;
|
|
30
|
+
}
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
27
33
|
if (route.metadata?.viewItem) {
|
|
28
34
|
if (route.metadata.viewItem?.api?.query) {
|
|
29
35
|
delete route.metadata.viewItem.api.query;
|
|
@@ -38,9 +44,14 @@ const removeViewItemFromRoutes = (list: RouteInfo[]) => {
|
|
|
38
44
|
}
|
|
39
45
|
return list;
|
|
40
46
|
}
|
|
41
|
-
|
|
47
|
+
type CreateQueryOptions = {
|
|
48
|
+
removeViewItem?: boolean,
|
|
49
|
+
before?: string,
|
|
50
|
+
after?: string,
|
|
51
|
+
}
|
|
52
|
+
export const createQueryByRoutes = (list: RouteInfo[], options?: CreateQueryOptions) => {
|
|
42
53
|
const obj: any = {};
|
|
43
|
-
list =
|
|
54
|
+
list = removeViewItemCotnextFromRoutes(list, options);
|
|
44
55
|
for (const route of list) {
|
|
45
56
|
if (!obj[route.path]) {
|
|
46
57
|
obj[route.path] = {};
|
|
@@ -55,11 +66,12 @@ export const createQueryByRoutes = (list: RouteInfo[]) => {
|
|
|
55
66
|
}
|
|
56
67
|
obj[route.path][route.key] = route;
|
|
57
68
|
}
|
|
58
|
-
const
|
|
59
|
-
|
|
69
|
+
const before = options?.before || `import { createQueryApi } from '@kevisual/query/api';`;
|
|
70
|
+
const after = options?.after || `export { queryApi };`;
|
|
71
|
+
const code = `${before}
|
|
60
72
|
const api = ${generateApiCode(obj)} as const;
|
|
61
73
|
const queryApi = createQueryApi({ api });
|
|
62
|
-
|
|
74
|
+
${after}
|
|
63
75
|
`
|
|
64
76
|
return code;
|
|
65
77
|
}
|
package/src/query-api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataOpts, Query } from "./query.ts";
|
|
1
|
+
import { DataOpts, Query, Result } from "./query.ts";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { createQueryByRoutes } from "./create-query/index.ts";
|
|
4
4
|
import { pick } from 'es-toolkit'
|
|
@@ -71,22 +71,23 @@ type IsOptional<T> = T extends { optional: true } ? true : false;
|
|
|
71
71
|
// 根据 optional 字段分离必需字段和可选字段
|
|
72
72
|
type ExtractArgsFromMetadata<T> = T extends { metadata?: { args?: infer A } }
|
|
73
73
|
? A extends Record<string, any>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
? (
|
|
75
|
+
// 必需字段(没有 optional: true)
|
|
76
|
+
{ [K in keyof A as IsOptional<A[K]> extends true ? never : K]: InferType<A[K]> } &
|
|
77
|
+
// 可选字段(有 optional: true)
|
|
78
|
+
{ [K in keyof A as IsOptional<A[K]> extends true ? K : never]?: InferType<A[K]> }
|
|
79
|
+
)
|
|
80
|
+
: never
|
|
81
81
|
: never;
|
|
82
82
|
|
|
83
|
+
|
|
83
84
|
// 类型映射:将 API 配置转换为方法签名
|
|
84
85
|
type ApiMethods<P extends { [path: string]: { [key: string]: Pos } }> = {
|
|
85
86
|
[Path in keyof P]: {
|
|
86
|
-
[Key in keyof P[Path]]: (
|
|
87
|
+
[Key in keyof P[Path]]: <T = any>(
|
|
87
88
|
data?: ExtractArgsFromMetadata<P[Path][Key]>,
|
|
88
89
|
opts?: DataOpts
|
|
89
|
-
) =>
|
|
90
|
+
) => Promise<Result<T>>
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
type QueryApiOpts<P extends { [path: string]: { [key: string]: Pos } } = {}> = {
|