@kevisual/api 0.0.1 → 0.0.5

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/mod.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './query/query-proxy/index.ts';
package/package.json CHANGED
@@ -1,30 +1,37 @@
1
1
  {
2
2
  "name": "@kevisual/api",
3
- "version": "0.0.1",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "main": "mod.ts",
6
6
  "scripts": {
7
- "build": "bun bun.config.mjs"
7
+ "build": "bun run bun.config.ts",
8
+ "postbuild": "bun bun.copy.config.mjs"
8
9
  },
9
- "keywords": [],
10
- "files": [
11
- "src",
12
- "query",
13
- "dist"
14
- ],
15
10
  "publishConfig": {
16
11
  "access": "public"
17
12
  },
13
+ "files": [
14
+ "dist",
15
+ "query",
16
+ "mod.ts"
17
+ ],
18
+ "keywords": [],
18
19
  "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
19
20
  "license": "MIT",
20
- "packageManager": "pnpm@10.6.2",
21
+ "packageManager": "pnpm@10.26.1",
21
22
  "type": "module",
22
- "dependencies": {
23
- "@kevisual/query": "^0.0.18",
24
- "@kevisual/router": "^0.0.20"
25
- },
26
23
  "devDependencies": {
24
+ "@kevisual/query": "^0.0.33",
25
+ "@kevisual/router": "^0.0.41",
27
26
  "@kevisual/types": "^0.0.10",
28
- "@types/node": "^22.15.27"
27
+ "@kevisual/use-config": "^1.0.21",
28
+ "@types/bun": "^1.3.5",
29
+ "@types/node": "^25.0.3",
30
+ "dotenv": "^17.2.3",
31
+ "fast-glob": "^3.3.3"
32
+ },
33
+ "dependencies": {
34
+ "es-toolkit": "^1.43.0",
35
+ "nanoid": "^5.1.6"
29
36
  }
30
37
  }
@@ -5,21 +5,23 @@
5
5
  },
6
6
  "checkDir": {
7
7
  "src/query": {
8
- "url": "https://kevisual.xiongxiao.me/root/ai/code/registry/query",
8
+ "url": "https://kevisual.cn/root/ai/code/template/registry/query",
9
9
  "enabled": true
10
10
  }
11
11
  },
12
12
  "syncDirectory": [
13
13
  {
14
14
  "files": [
15
- "src/query/**/*"
15
+ "**/*"
16
16
  ],
17
17
  "ignore": [],
18
- "registry": "https://kevisual.xiongxiao.me/root/ai/code/registry",
19
- "replace": {
20
- "src/": ""
21
- }
18
+ "registry": "https://kevisual.cn/root/ai/code/template/registry/query"
22
19
  }
23
20
  ],
24
- "sync": {}
21
+ "sync": {
22
+ "kevisual.json": {
23
+ "url": "https://kevisual.cn/root/ai/code/template/registry/query/kevisual.json",
24
+ "type": "none"
25
+ }
26
+ }
25
27
  }
@@ -1,4 +1,4 @@
1
- import { QueryUtil } from '@/query/index.ts';
1
+ import { QueryUtil } from '../../../query/index.ts';
2
2
 
3
3
  type Message = {
4
4
  role?: 'user' | 'assistant' | 'system' | 'tool';
@@ -1,4 +1,4 @@
1
- import { QueryUtil } from '@/query/index.ts';
1
+ import { QueryUtil } from '../../../query/index.ts';
2
2
 
3
3
  export const appDefine = QueryUtil.create({
4
4
  getApp: {
@@ -1,4 +1,4 @@
1
- import { QueryUtil } from '@/query/index.ts';
1
+ import { QueryUtil } from '../../../query/index.ts';
2
2
 
3
3
  export const userAppDefine = QueryUtil.create({
4
4
  listUserApps: {
@@ -15,4 +15,18 @@ export class QueryApp extends BaseQuery {
15
15
  getList(data: any, opts?: DataOpts) {
16
16
  return this.appDefine.queryChain('listApps').post(data, opts);
17
17
  }
18
+ getPublicApp(data: any, opts?: DataOpts) {
19
+ return this.query.post({
20
+ path: 'app',
21
+ key: 'getApp',
22
+ data: data,
23
+ }, opts);
24
+ }
25
+ getApp(data: any, opts?: DataOpts) {
26
+ return this.query.post({
27
+ path: 'app',
28
+ key: 'get',
29
+ data: data,
30
+ }, opts);
31
+ }
18
32
  }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * 配置查询
3
+ * @updatedAt 2025-12-03 10:33:00
4
+ */
5
+ import { Query } from '@kevisual/query';
6
+ import type { Result } from '@kevisual/query/query';
7
+ type QueryConfigOpts = {
8
+ query?: Query;
9
+ };
10
+ export type Config<T = any> = {
11
+ id?: string;
12
+ title?: string;
13
+ key?: string;
14
+ description?: string;
15
+ data?: T;
16
+ createdAt?: string;
17
+ updatedAt?: string;
18
+ };
19
+ export type UploadConfig = {
20
+ key?: string;
21
+ version?: string;
22
+ };
23
+ type PostOpts = {
24
+ token?: string;
25
+ payload?: Record<string, any>;
26
+ };
27
+ export const defaultConfigKeys = ['upload.json', 'workspace.json', 'ai.json', 'user.json', 'life.json'] as const;
28
+ type DefaultConfigKey = (typeof defaultConfigKeys)[number];
29
+
30
+ export class QueryConfig {
31
+ query: Query;
32
+ constructor(opts?: QueryConfigOpts) {
33
+ this.query = opts?.query || new Query();
34
+ }
35
+ async post<T = Config>(data: any) {
36
+ return this.query.post<T>({ path: 'config', ...data });
37
+ }
38
+ async getConfig({ id, key }: { id?: string; key?: string }, opts?: PostOpts) {
39
+ return this.post({
40
+ key: 'get',
41
+ data: {
42
+ id,
43
+ key,
44
+ },
45
+ ...opts,
46
+ });
47
+ }
48
+ async updateConfig(data: Config, opts?: PostOpts) {
49
+ return this.post({
50
+ key: 'update',
51
+ data,
52
+ ...opts,
53
+ });
54
+ }
55
+ async deleteConfig(data: { id?: string, key?: string }, opts?: PostOpts) {
56
+ console.log('Delete Config Params:', data);
57
+ return this.post({
58
+ key: 'delete',
59
+ data,
60
+ });
61
+ }
62
+ async listConfig(opts?: PostOpts) {
63
+ return this.post<{ list: Config[] }>({
64
+ key: 'list',
65
+ ...opts,
66
+ });
67
+ }
68
+ /**
69
+ * 获取上传配置
70
+ * @returns
71
+ */
72
+ async getUploadConfig(opts?: PostOpts) {
73
+ return this.post<Result<Config<UploadConfig>>>({
74
+ key: 'getUploadConfig',
75
+ ...opts,
76
+ });
77
+ }
78
+ /**
79
+ * 更新上传配置
80
+ * @param data
81
+ * @returns
82
+ */
83
+ async updateUploadConfig(data: Config, opts?: PostOpts) {
84
+ return this.post<Result<Config<UploadConfig>>>({
85
+ key: 'updateUploadConfig',
86
+ data,
87
+ ...opts,
88
+ });
89
+ }
90
+
91
+ /**
92
+ * 检测配置是否存在
93
+ * @param id
94
+ * @returns
95
+ */
96
+ async detectConfig(opts?: PostOpts) {
97
+ return this.post<{ updateList: Config[] }>({
98
+ key: 'detect',
99
+ ...opts,
100
+ });
101
+ }
102
+ /**
103
+ * 获取配置, 获取默认的配置项
104
+ * @param key
105
+ * @returns
106
+ */
107
+ async getConfigByKey(key: DefaultConfigKey, opts?: PostOpts) {
108
+ return this.post<Result<Config>>({
109
+ key: 'defaultConfig',
110
+ configKey: key,
111
+ ...opts,
112
+ });
113
+ }
114
+ async getByKey<T = any>(key: string, opts?: PostOpts) {
115
+ return this.post<Result<Config<T>>>({
116
+ key: 'get',
117
+ ...opts,
118
+ data: { key },
119
+ });
120
+ }
121
+ }
@@ -0,0 +1,68 @@
1
+ import { Query } from '@kevisual/query/query';
2
+ import { QueryRouterServer, Route } from '@kevisual/router/src/route.ts';
3
+ export class QueryProxy {
4
+ query: Query;
5
+ router: QueryRouterServer;
6
+ token?: string;
7
+ constructor(opts?: { query: Query, router?: QueryRouterServer, token?: string }) {
8
+ this.query = opts?.query || new Query();
9
+ this.router = opts?.router || new QueryRouterServer();
10
+ this.token = opts?.token;
11
+ }
12
+ /**
13
+ * 初始化路由
14
+ * @returns
15
+ */
16
+ async init() {
17
+ const that = this;
18
+ const res = await this.query.post<{ list: RouterItem[] }>({ path: "router", key: 'list', token: this.token });
19
+ if (res.code !== 200) {
20
+ console.error('Failed to init query proxy router:', res.message);
21
+ return
22
+ }
23
+ const _list = res.data?.list || []
24
+ for (const item of _list) {
25
+ if (item.path && item.key) {
26
+ console.log(`Register route: [${item.path}] ${item.key}`);
27
+ this.router.route({
28
+ path: item.path,
29
+ key: item.key,
30
+ description: item.description,
31
+ metadata: item.metadata,
32
+ }).define(async (ctx) => {
33
+ const msg = { ...ctx.query };
34
+ if (msg.token === undefined && that.token !== undefined) {
35
+ msg.token = that.token;
36
+ }
37
+ const r = await that.query.post<any>({ path: item.path, key: item.key, ...msg });
38
+ ctx.forward(r)
39
+ }).addTo(that.router);
40
+ }
41
+ }
42
+ }
43
+ /**
44
+ * 列出路由
45
+ * @param filter
46
+ * @returns
47
+ */
48
+ async listRoutes(filter?: (item: Route) => boolean) {
49
+ return this.router.routes.filter(filter || (() => true));
50
+ }
51
+ /**
52
+ * 运行路由
53
+ * @param msg
54
+ * @returns
55
+ */
56
+ async run(msg: { id?: string, path?: string, key?: string }) {
57
+ return await this.router.run(msg);
58
+ }
59
+ }
60
+
61
+ type RouterItem = {
62
+ id?: string;
63
+ path?: string;
64
+ key?: string;
65
+ description?: string;
66
+ middleware?: string[];
67
+ metadata?: Record<string, any>;
68
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * 配置查询
3
+ * @updatedAt 2025-12-03 10:33:00
4
+ */
5
+ import { Query } from '@kevisual/query';
6
+ type QueryConfigOpts = {
7
+ query?: Query;
8
+ };
9
+ export type Config<T = any> = {
10
+ id?: string;
11
+ title?: string;
12
+ key?: string;
13
+ description?: string;
14
+ data?: T;
15
+ createdAt?: string;
16
+ updatedAt?: string;
17
+ };
18
+ export type UploadConfig = {
19
+ key?: string;
20
+ version?: string;
21
+ };
22
+ type PostOpts = {
23
+ token?: string;
24
+ payload?: Record<string, any>;
25
+ };
26
+
27
+ export class QueryConfig {
28
+ query: Query;
29
+ constructor(opts?: QueryConfigOpts) {
30
+ this.query = opts?.query || new Query();
31
+ }
32
+ async post<T = Config>(data: any) {
33
+ return this.query.post<T>({ path: 'secret', ...data });
34
+ }
35
+ async getItem({ id, key }: { id?: string; key?: string }, opts?: PostOpts) {
36
+ return this.post({
37
+ key: 'get',
38
+ data: {
39
+ id,
40
+ key,
41
+ },
42
+ ...opts,
43
+ });
44
+ }
45
+ async updateItem(data: Config, opts?: PostOpts) {
46
+ return this.post({
47
+ key: 'update',
48
+ data,
49
+ ...opts,
50
+ });
51
+ }
52
+ async deleteItem(data: { id?: string, key?: string }, opts?: PostOpts) {
53
+ return this.post({
54
+ key: 'delete',
55
+ data,
56
+ });
57
+ }
58
+ async listItems(opts?: PostOpts) {
59
+ return this.post<{ list: Config[] }>({
60
+ key: 'list',
61
+ ...opts,
62
+ });
63
+ }
64
+ }
@@ -1,4 +1,4 @@
1
- import { QueryUtil } from '@/query/index.ts';
1
+ import { QueryUtil } from '../../../query/index.ts';
2
2
 
3
3
  export const shopDefine = QueryUtil.create({
4
4
  getRegistry: {
@@ -4,14 +4,13 @@ import { BaseQuery, DataOpts, Query } from '@kevisual/query/query';
4
4
 
5
5
  export { shopDefine };
6
6
 
7
- export class QueryShop<T extends Query = Query> extends BaseQuery<T, typeof shopDefine> {
7
+ export class QueryShop<T extends Query = Query> extends BaseQuery<T> {
8
8
  constructor(opts?: { query: T }) {
9
9
  super({
10
10
  query: opts?.query!,
11
- queryDefine: shopDefine,
12
11
  });
13
12
  }
14
13
  getInstall(data: any, opts?: DataOpts) {
15
- return this.queryDefine.queryChain('install').post(data, opts);
14
+ return this.query.post(data, opts);
16
15
  }
17
16
  }
@@ -5,7 +5,8 @@ import { UploadProgress } from './core/upload-progress.ts';
5
5
 
6
6
  export { uploadFiles, uploadFileChunked, UploadProgress };
7
7
 
8
- export * from './utils/to-file.ts';
8
+ export { toTextFile, toFile, getDirectoryAndName } from './utils/to-file.ts';
9
+
9
10
  export { randomId } from './utils/random-id.ts';
10
11
 
11
12
  export { filterFiles } from './utils/filter-files.ts';
package/readme.md ADDED
@@ -0,0 +1,3 @@
1
+ # query-awesome
2
+
3
+ 对 kevisual 相关的query router 的模块整理
@@ -1,154 +0,0 @@
1
- import { Query } from '@kevisual/query';
2
- import type { Result, DataOpts } from '@kevisual/query/query';
3
-
4
- export type SimpleObject = Record<string, any>;
5
- export const markType = ['simple', 'md', 'mdx', 'wallnote', 'excalidraw', 'chat'] as const;
6
- export type MarkType = (typeof markType)[number];
7
- export type MarkData = {
8
- nodes?: any[];
9
- edges?: any[];
10
- elements?: any[];
11
- permission?: any;
12
-
13
- [key: string]: any;
14
- };
15
- export type Mark = {
16
- id: string;
17
- title: string;
18
- description: string;
19
- markType: MarkType;
20
- link: string;
21
- data?: MarkData;
22
- uid: string;
23
- puid: string;
24
- summary: string;
25
- thumbnail?: string;
26
- tags: string[];
27
- createdAt: string;
28
- updatedAt: string;
29
- version: number;
30
- };
31
- export type ShowMarkPick = Pick<Mark, 'id' | 'title' | 'description' | 'summary' | 'link' | 'tags' | 'thumbnail' | 'updatedAt'>;
32
-
33
- export type SearchOpts = {
34
- page?: number;
35
- pageSize?: number;
36
- search?: string;
37
- sort?: string; // DESC, ASC
38
- markType?: MarkType; // 类型
39
- [key: string]: any;
40
- };
41
-
42
- export type QueryMarkOpts<T extends SimpleObject = SimpleObject> = {
43
- query?: Query;
44
- isBrowser?: boolean;
45
- onLoad?: () => void;
46
- } & T;
47
-
48
- export type ResultMarkList = {
49
- list: Mark[];
50
- pagination: {
51
- pageSize: number;
52
- current: number;
53
- total: number;
54
- };
55
- };
56
- export type QueryMarkData = {
57
- id?: string;
58
- title?: string;
59
- description?: string;
60
- [key: string]: any;
61
- };
62
- export type QueryMarkResult = {
63
- accessToken: string;
64
- refreshToken: string;
65
- };
66
-
67
- export class QueryMarkBase<T extends SimpleObject = SimpleObject> {
68
- query: Query;
69
- isBrowser: boolean;
70
- load?: boolean;
71
- storage?: Storage;
72
- onLoad?: () => void;
73
-
74
- constructor(opts?: QueryMarkOpts<T>) {
75
- this.query = opts?.query || new Query();
76
- this.isBrowser = opts?.isBrowser ?? true;
77
- this.init();
78
- this.onLoad = opts?.onLoad;
79
- }
80
- setQuery(query: Query) {
81
- this.query = query;
82
- }
83
- private async init() {
84
- this.load = true;
85
- this.onLoad?.();
86
- }
87
-
88
- async post<T = Result<any>>(data: any, opts?: DataOpts): Promise<T> {
89
- try {
90
- return this.query.post({ path: 'mark', ...data }, opts) as Promise<T>;
91
- } catch (error) {
92
- console.log('error', error);
93
- return {
94
- code: 400,
95
- } as any;
96
- }
97
- }
98
-
99
- async getMarkList(search: SearchOpts, opts?: DataOpts) {
100
- return this.post<Result<ResultMarkList>>({ key: 'list', ...search }, opts);
101
- }
102
-
103
- async getMark(id: string, opts?: DataOpts) {
104
- return this.post<Result<Mark>>({ key: 'get', id }, opts);
105
- }
106
- async getVersion(id: string, opts?: DataOpts) {
107
- return this.post<Result<{ version: number; id: string }>>({ key: 'getVersion', id }, opts);
108
- }
109
- /**
110
- * 检查版本
111
- * 当需要更新时,返回true
112
- * @param id
113
- * @param version
114
- * @param opts
115
- * @returns
116
- */
117
- async checkVersion(id: string, version?: number, opts?: DataOpts) {
118
- if (!version) {
119
- return true;
120
- }
121
- const res = await this.getVersion(id, opts);
122
- if (res.code === 200) {
123
- if (res.data!.version > version) {
124
- return true;
125
- }
126
- return false;
127
- }
128
- return true;
129
- }
130
-
131
- async updateMark(data: any, opts?: DataOpts) {
132
- return this.post<Result<Mark>>({ key: 'update', data }, opts);
133
- }
134
-
135
- async deleteMark(id: string, opts?: DataOpts) {
136
- return this.post<Result<Mark>>({ key: 'delete', id }, opts);
137
- }
138
- }
139
- export class QueryMark extends QueryMarkBase<SimpleObject> {
140
- markType: string;
141
- constructor(opts?: QueryMarkOpts & { markType?: MarkType }) {
142
- super(opts);
143
- this.markType = opts?.markType || 'simple';
144
- }
145
- async getMarkList(search?: SearchOpts, opts?: DataOpts) {
146
- return this.post<Result<ResultMarkList>>({ key: 'list', ...search, markType: this.markType }, opts);
147
- }
148
- async updateMark(data: any, opts?: DataOpts) {
149
- if (!data.id) {
150
- data.markType = this.markType || 'simple';
151
- }
152
- return super.updateMark(data, opts);
153
- }
154
- }