@kevisual/api 0.0.47 → 0.0.48

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/utils.js CHANGED
@@ -1,44 +1,22 @@
1
- // node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
2
- import { webcrypto as crypto } from "node:crypto";
3
- var POOL_SIZE_MULTIPLIER = 128;
4
- var pool;
5
- var poolOffset;
6
- function fillPool(bytes) {
7
- if (!pool || pool.length < bytes) {
8
- pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
9
- crypto.getRandomValues(pool);
10
- poolOffset = 0;
11
- } else if (poolOffset + bytes > pool.length) {
12
- crypto.getRandomValues(pool);
13
- poolOffset = 0;
14
- }
15
- poolOffset += bytes;
16
- }
17
- function random(bytes) {
18
- fillPool(bytes |= 0);
19
- return pool.subarray(poolOffset - bytes, poolOffset);
20
- }
21
- function customRandom(alphabet, defaultSize, getRandom) {
22
- let mask = (2 << 31 - Math.clz32(alphabet.length - 1 | 1)) - 1;
23
- let step = Math.ceil(1.6 * mask * defaultSize / alphabet.length);
1
+ // node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.browser.js
2
+ var random = (bytes) => crypto.getRandomValues(new Uint8Array(bytes));
3
+ var customRandom = (alphabet, defaultSize, getRandom) => {
4
+ let mask = (2 << Math.log2(alphabet.length - 1)) - 1;
5
+ let step = -~(1.6 * mask * defaultSize / alphabet.length);
24
6
  return (size = defaultSize) => {
25
- if (!size)
26
- return "";
27
7
  let id = "";
28
8
  while (true) {
29
9
  let bytes = getRandom(step);
30
- let i = step;
31
- while (i--) {
32
- id += alphabet[bytes[i] & mask] || "";
10
+ let j = step | 0;
11
+ while (j--) {
12
+ id += alphabet[bytes[j] & mask] || "";
33
13
  if (id.length >= size)
34
14
  return id;
35
15
  }
36
16
  }
37
17
  };
38
- }
39
- function customAlphabet(alphabet, size = 21) {
40
- return customRandom(alphabet, size, random);
41
- }
18
+ };
19
+ var customAlphabet = (alphabet, size = 21) => customRandom(alphabet, size | 0, random);
42
20
 
43
21
  // query/utils/random.ts
44
22
  var letter = "abcdefghijklmnopqrstuvwxyz";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/api",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
4
4
  "description": "",
5
5
  "main": "mod.ts",
6
6
  "scripts": {
@@ -17,22 +17,22 @@
17
17
  "keywords": [],
18
18
  "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
19
19
  "license": "MIT",
20
- "packageManager": "pnpm@10.28.2",
20
+ "packageManager": "pnpm@10.29.3",
21
21
  "type": "module",
22
22
  "devDependencies": {
23
23
  "@kevisual/cache": "^0.0.5",
24
24
  "@kevisual/code-builder": "^0.0.6",
25
- "@kevisual/query": "^0.0.39",
25
+ "@kevisual/query": "^0.0.40",
26
26
  "@kevisual/remote-app": "^0.0.4",
27
27
  "@kevisual/router": "^0.0.70",
28
28
  "@kevisual/types": "^0.0.12",
29
29
  "@kevisual/use-config": "^1.0.30",
30
- "@types/bun": "^1.3.8",
30
+ "@types/bun": "^1.3.9",
31
31
  "@types/crypto-js": "^4.2.2",
32
- "@types/node": "^25.2.0",
32
+ "@types/node": "^25.2.3",
33
33
  "@types/spark-md5": "^3.0.5",
34
34
  "crypto-js": "^4.2.0",
35
- "dotenv": "^17.2.3",
35
+ "dotenv": "^17.3.1",
36
36
  "fast-glob": "^3.3.3",
37
37
  "ws": "npm:@kevisual/ws"
38
38
  },
@@ -55,6 +55,7 @@
55
55
  "./secret": "./query/query-secret/index.ts",
56
56
  "./resources": "./query/query-resources/index.ts",
57
57
  "./query-secret": "./dist/query-secret.js",
58
+ "./query-mark": "./dist/query-mark.js",
58
59
  "./utils": "./dist/utils.js",
59
60
  "./query-upload": "./dist/query-upload.js",
60
61
  "./query-app": "./dist/query-app.js",
@@ -63,6 +64,8 @@
63
64
  "./query-config": "./dist/query-config.js",
64
65
  "./query-login": "./dist/query-login.js",
65
66
  "./query-ai": "./dist/query-ai.js",
66
- "./query-resources": "./dist/query-resources.js"
67
+ "./query-resources": "./dist/query-resources.js",
68
+ "./src/*": "./src/*",
69
+ "./query/*": "./query/*"
67
70
  }
68
71
  }
@@ -0,0 +1,154 @@
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
+ }
@@ -1,13 +1,12 @@
1
- import MD5 from 'crypto-js/md5';
2
1
  import SparkMD5 from 'spark-md5';
3
2
 
4
3
  export const hashContent = (str: string | Blob | Buffer): Promise<string> | string => {
5
4
  if (typeof str === 'string') {
6
- return MD5(str).toString();
5
+ return SparkMD5.hash(str);
7
6
  } else if (str instanceof Blob) {
8
7
  return hashBlob(str);
9
8
  } else if (Buffer.isBuffer(str)) {
10
- return MD5(str.toString()).toString();
9
+ return SparkMD5.hash(str.toString());
11
10
  }
12
11
  console.error('hashContent error: input must be a string, Blob, or Buffer');
13
12
  return '';