chore: bump version to 0.0.50, update dependencies, and enhance createQueryByRoutes with options
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/query",
|
"name": "@kevisual/query",
|
||||||
"version": "0.0.49",
|
"version": "0.0.50",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run clean && bun run bun.config.ts",
|
"build": "npm run clean && bun run bun.config.ts",
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@kevisual/code-builder": "^0.0.6",
|
"@kevisual/code-builder": "^0.0.6",
|
||||||
"@kevisual/router": "^0.0.80",
|
"@kevisual/router": "^0.0.84",
|
||||||
"@types/node": "^25.2.3",
|
"@types/node": "^25.3.0",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"es-toolkit": "^1.44.0",
|
"es-toolkit": "^1.44.0",
|
||||||
"zod": "^4.3.6",
|
"zod": "^4.3.6",
|
||||||
|
|||||||
97
pnpm-lock.yaml
generated
Normal file
97
pnpm-lock.yaml
generated
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
lockfileVersion: '9.0'
|
||||||
|
|
||||||
|
settings:
|
||||||
|
autoInstallPeers: true
|
||||||
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
|
importers:
|
||||||
|
|
||||||
|
.:
|
||||||
|
devDependencies:
|
||||||
|
'@kevisual/code-builder':
|
||||||
|
specifier: ^0.0.6
|
||||||
|
version: 0.0.6
|
||||||
|
'@kevisual/router':
|
||||||
|
specifier: ^0.0.84
|
||||||
|
version: 0.0.84
|
||||||
|
'@types/node':
|
||||||
|
specifier: ^25.3.0
|
||||||
|
version: 25.3.0
|
||||||
|
es-toolkit:
|
||||||
|
specifier: ^1.44.0
|
||||||
|
version: 1.44.0
|
||||||
|
typescript:
|
||||||
|
specifier: ^5.9.3
|
||||||
|
version: 5.9.3
|
||||||
|
zod:
|
||||||
|
specifier: ^4.3.6
|
||||||
|
version: 4.3.6
|
||||||
|
zustand:
|
||||||
|
specifier: ^5.0.11
|
||||||
|
version: 5.0.11
|
||||||
|
|
||||||
|
packages:
|
||||||
|
|
||||||
|
'@kevisual/code-builder@0.0.6':
|
||||||
|
resolution: {integrity: sha512-0aqATB31/yw4k4s5/xKnfr4DKbUnx8e3Z3BmKbiXTrc+CqWiWTdlGe9bKI9dZ2Df+xNp6g11W4xM2NICNyyCCw==}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
|
'@kevisual/router@0.0.84':
|
||||||
|
resolution: {integrity: sha512-l/TUFuqTJegB/S3FZQRBMUoz0Spvg8EzV3C/kBi/VO9KKCzjqZDVvhZJJbTQh9879CBY6vUy1ajo9WcLYnwbNA==}
|
||||||
|
|
||||||
|
'@types/node@25.3.0':
|
||||||
|
resolution: {integrity: sha512-4K3bqJpXpqfg2XKGK9bpDTc6xO/xoUP/RBWS7AtRMug6zZFaRekiLzjVtAoZMquxoAbzBvy5nxQ7veS5eYzf8A==}
|
||||||
|
|
||||||
|
es-toolkit@1.44.0:
|
||||||
|
resolution: {integrity: sha512-6penXeZalaV88MM3cGkFZZfOoLGWshWWfdy0tWw/RlVVyhvMaWSBTOvXNeiW3e5FwdS5ePW0LGEu17zT139ktg==}
|
||||||
|
|
||||||
|
typescript@5.9.3:
|
||||||
|
resolution: {integrity: sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==}
|
||||||
|
engines: {node: '>=14.17'}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
|
undici-types@7.18.2:
|
||||||
|
resolution: {integrity: sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==}
|
||||||
|
|
||||||
|
zod@4.3.6:
|
||||||
|
resolution: {integrity: sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==}
|
||||||
|
|
||||||
|
zustand@5.0.11:
|
||||||
|
resolution: {integrity: sha512-fdZY+dk7zn/vbWNCYmzZULHRrss0jx5pPFiOuMZ/5HJN6Yv3u+1Wswy/4MpZEkEGhtNH+pwxZB8OKgUBPzYAGg==}
|
||||||
|
engines: {node: '>=12.20.0'}
|
||||||
|
peerDependencies:
|
||||||
|
'@types/react': '>=18.0.0'
|
||||||
|
immer: '>=9.0.6'
|
||||||
|
react: '>=18.0.0'
|
||||||
|
use-sync-external-store: '>=1.2.0'
|
||||||
|
peerDependenciesMeta:
|
||||||
|
'@types/react':
|
||||||
|
optional: true
|
||||||
|
immer:
|
||||||
|
optional: true
|
||||||
|
react:
|
||||||
|
optional: true
|
||||||
|
use-sync-external-store:
|
||||||
|
optional: true
|
||||||
|
|
||||||
|
snapshots:
|
||||||
|
|
||||||
|
'@kevisual/code-builder@0.0.6': {}
|
||||||
|
|
||||||
|
'@kevisual/router@0.0.84':
|
||||||
|
dependencies:
|
||||||
|
es-toolkit: 1.44.0
|
||||||
|
|
||||||
|
'@types/node@25.3.0':
|
||||||
|
dependencies:
|
||||||
|
undici-types: 7.18.2
|
||||||
|
|
||||||
|
es-toolkit@1.44.0: {}
|
||||||
|
|
||||||
|
typescript@5.9.3: {}
|
||||||
|
|
||||||
|
undici-types@7.18.2: {}
|
||||||
|
|
||||||
|
zod@4.3.6: {}
|
||||||
|
|
||||||
|
zustand@5.0.11: {}
|
||||||
@@ -22,8 +22,14 @@ type RouteInfo = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const removeViewItemFromRoutes = (list: RouteInfo[]) => {
|
const removeViewItemCotnextFromRoutes = (list: RouteInfo[], options?: CreateQueryOptions) => {
|
||||||
for (const route of list) {
|
for (const route of list) {
|
||||||
|
if (options?.removeViewItem) {
|
||||||
|
if (route.metadata?.viewItem) {
|
||||||
|
delete route.metadata.viewItem;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (route.metadata?.viewItem) {
|
if (route.metadata?.viewItem) {
|
||||||
if (route.metadata.viewItem?.api?.query) {
|
if (route.metadata.viewItem?.api?.query) {
|
||||||
delete route.metadata.viewItem.api.query;
|
delete route.metadata.viewItem.api.query;
|
||||||
@@ -38,9 +44,14 @@ const removeViewItemFromRoutes = (list: RouteInfo[]) => {
|
|||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
export const createQueryByRoutes = (list: RouteInfo[]) => {
|
type CreateQueryOptions = {
|
||||||
|
removeViewItem?: boolean,
|
||||||
|
before?: string,
|
||||||
|
after?: string,
|
||||||
|
}
|
||||||
|
export const createQueryByRoutes = (list: RouteInfo[], options?: CreateQueryOptions) => {
|
||||||
const obj: any = {};
|
const obj: any = {};
|
||||||
list = removeViewItemFromRoutes(list);
|
list = removeViewItemCotnextFromRoutes(list, options);
|
||||||
for (const route of list) {
|
for (const route of list) {
|
||||||
if (!obj[route.path]) {
|
if (!obj[route.path]) {
|
||||||
obj[route.path] = {};
|
obj[route.path] = {};
|
||||||
@@ -55,11 +66,12 @@ export const createQueryByRoutes = (list: RouteInfo[]) => {
|
|||||||
}
|
}
|
||||||
obj[route.path][route.key] = route;
|
obj[route.path][route.key] = route;
|
||||||
}
|
}
|
||||||
const code = `
|
const before = options?.before || `import { createQueryApi } from '@kevisual/query/api';`;
|
||||||
import { createQueryApi } from '@kevisual/query/api';
|
const after = options?.after || `export { queryApi };`;
|
||||||
|
const code = `${before}
|
||||||
const api = ${generateApiCode(obj)} as const;
|
const api = ${generateApiCode(obj)} as const;
|
||||||
const queryApi = createQueryApi({ api });
|
const queryApi = createQueryApi({ api });
|
||||||
export { queryApi };
|
${after}
|
||||||
`
|
`
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { DataOpts, Query } from "./query.ts";
|
import { DataOpts, Query, Result } from "./query.ts";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { createQueryByRoutes } from "./create-query/index.ts";
|
import { createQueryByRoutes } from "./create-query/index.ts";
|
||||||
import { pick } from 'es-toolkit'
|
import { pick } from 'es-toolkit'
|
||||||
@@ -80,13 +80,14 @@ type ExtractArgsFromMetadata<T> = T extends { metadata?: { args?: infer A } }
|
|||||||
: never
|
: never
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
|
|
||||||
// 类型映射:将 API 配置转换为方法签名
|
// 类型映射:将 API 配置转换为方法签名
|
||||||
type ApiMethods<P extends { [path: string]: { [key: string]: Pos } }> = {
|
type ApiMethods<P extends { [path: string]: { [key: string]: Pos } }> = {
|
||||||
[Path in keyof P]: {
|
[Path in keyof P]: {
|
||||||
[Key in keyof P[Path]]: (
|
[Key in keyof P[Path]]: <T = any>(
|
||||||
data?: ExtractArgsFromMetadata<P[Path][Key]>,
|
data?: ExtractArgsFromMetadata<P[Path][Key]>,
|
||||||
opts?: DataOpts
|
opts?: DataOpts
|
||||||
) => ReturnType<Query['post']>
|
) => Promise<Result<T>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type QueryApiOpts<P extends { [path: string]: { [key: string]: Pos } } = {}> = {
|
type QueryApiOpts<P extends { [path: string]: { [key: string]: Pos } } = {}> = {
|
||||||
|
|||||||
@@ -45,9 +45,11 @@ const api = {
|
|||||||
const queryApi = createQueryApi({ api });
|
const queryApi = createQueryApi({ api });
|
||||||
export { queryApi };
|
export { queryApi };
|
||||||
|
|
||||||
queryApi.app_domain_manager.get({
|
const result = await queryApi.app_domain_manager.get<{ id: number }>({
|
||||||
data: {
|
data: {
|
||||||
id: '123',
|
id: '123',
|
||||||
domain: 'example.com'
|
domain: 'example.com'
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
|
result.data.id; // TypeScript 正确推断为 number
|
||||||
Reference in New Issue
Block a user