@kevisual/project-search 0.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/dist/app.d.ts +239 -0
- package/dist/app.js +41898 -0
- package/package.json +35 -0
- package/readme.md +10 -0
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { MeiliSearch } from 'meilisearch';
|
|
2
|
+
import ParcelWatcher from '@parcel/watcher';
|
|
3
|
+
import { EventEmitter } from 'eventemitter3';
|
|
4
|
+
|
|
5
|
+
declare const app: any;
|
|
6
|
+
declare const manager: any;
|
|
7
|
+
|
|
8
|
+
interface ProjectManagerInterface {
|
|
9
|
+
removeProject(path: string): void;
|
|
10
|
+
getProject(path: string): any;
|
|
11
|
+
listProjects(): any[];
|
|
12
|
+
addProject(project: any): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare class Scheduler {
|
|
16
|
+
private queue;
|
|
17
|
+
private running;
|
|
18
|
+
/** 当前在队列中等待执行的任务 key 集合(不含正在执行的) */
|
|
19
|
+
private pendingKeys;
|
|
20
|
+
/**
|
|
21
|
+
* 添加任务
|
|
22
|
+
* @param key 任务唯一标识(如文件路径)
|
|
23
|
+
* @param execute 任务执行函数
|
|
24
|
+
* @returns true 表示已加入队列;false 表示该 key 已存在,跳过
|
|
25
|
+
*/
|
|
26
|
+
add(key: string, execute: () => Promise<void>): boolean;
|
|
27
|
+
private _run;
|
|
28
|
+
/** 队列中等待执行的任务数量(不含正在执行的) */
|
|
29
|
+
get pendingCount(): number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type FileProjectData = {
|
|
33
|
+
/**
|
|
34
|
+
* meilisearch 文档 ID(文件绝对路径的 base64url 编码,无碰撞且唯一)
|
|
35
|
+
*/
|
|
36
|
+
id: string;
|
|
37
|
+
/**
|
|
38
|
+
* 文件路径的 md5 hash,用于快速索引/查找
|
|
39
|
+
*/
|
|
40
|
+
hash: string;
|
|
41
|
+
/**
|
|
42
|
+
* 文件对应相关信息
|
|
43
|
+
*
|
|
44
|
+
* 具体文件路径
|
|
45
|
+
*/
|
|
46
|
+
filepath: string;
|
|
47
|
+
content?: string;
|
|
48
|
+
lastModified: number;
|
|
49
|
+
size: number;
|
|
50
|
+
/**
|
|
51
|
+
* 项目路径,文件所在的项目路径,方便搜索结果展示和过滤
|
|
52
|
+
*/
|
|
53
|
+
projectPath: string;
|
|
54
|
+
repo: string;
|
|
55
|
+
/**
|
|
56
|
+
* 人工编辑的字段,方便搜索结果展示和过滤
|
|
57
|
+
*/
|
|
58
|
+
title?: string;
|
|
59
|
+
tags?: string[];
|
|
60
|
+
summary?: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
link?: string;
|
|
63
|
+
};
|
|
64
|
+
declare class ProjectSearch {
|
|
65
|
+
meiliSearch: MeiliSearch;
|
|
66
|
+
scheduler: Scheduler;
|
|
67
|
+
constructor({ apiHost, apiKey }?: {
|
|
68
|
+
apiHost?: string;
|
|
69
|
+
apiKey?: string;
|
|
70
|
+
});
|
|
71
|
+
private get index();
|
|
72
|
+
/** 全文搜索 */
|
|
73
|
+
searchFiles(query?: string, options?: {
|
|
74
|
+
projectPath?: string;
|
|
75
|
+
repo?: string;
|
|
76
|
+
title?: string;
|
|
77
|
+
tags?: string | string[];
|
|
78
|
+
summary?: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
link?: string;
|
|
81
|
+
/**
|
|
82
|
+
* ['projectPath:asc']
|
|
83
|
+
*/
|
|
84
|
+
sort?: string[];
|
|
85
|
+
limit?: number;
|
|
86
|
+
getContent?: boolean;
|
|
87
|
+
}): Promise<FileProjectData[]>;
|
|
88
|
+
/** 初始化索引(设置可过滤字段) */
|
|
89
|
+
ensureIndex(): Promise<void>;
|
|
90
|
+
/** 添加或完整覆盖一个文件文档 */
|
|
91
|
+
private _upsertFile;
|
|
92
|
+
/** 更新文档的人工编辑字段(title/tags/summary/description/link),不影响文件内容等其他字段 */
|
|
93
|
+
updateDocument(filePath: string, opts: {
|
|
94
|
+
title?: string;
|
|
95
|
+
tags?: string[];
|
|
96
|
+
summary?: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
link?: string;
|
|
99
|
+
}): Promise<void>;
|
|
100
|
+
/** 删除某个项目下所有已索引的文件文档 */
|
|
101
|
+
removeProjectFiles(projectPath: string): Promise<void>;
|
|
102
|
+
/** 将文件变更通过 scheduler 安全入队 */
|
|
103
|
+
syncFileChange({ type, path: filePath, projectPath, repo }: {
|
|
104
|
+
type: 'create' | 'update' | 'delete';
|
|
105
|
+
path: string;
|
|
106
|
+
projectPath: string;
|
|
107
|
+
repo: string;
|
|
108
|
+
}): void;
|
|
109
|
+
/**
|
|
110
|
+
* 全量同步整个项目目录到 meilisearch
|
|
111
|
+
* 1. 扫描本地文件,逐一 upsert
|
|
112
|
+
* 2. 对比 meilisearch 中已有文档,删除本地已不存在的文件记录
|
|
113
|
+
*/
|
|
114
|
+
initialSync(projectPath: string, repo: string): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type ProjectDoc = {
|
|
118
|
+
/**
|
|
119
|
+
* 文档 ID,使用 path 的 base64url 编码
|
|
120
|
+
*/
|
|
121
|
+
id: string;
|
|
122
|
+
name?: string;
|
|
123
|
+
path: string;
|
|
124
|
+
/**
|
|
125
|
+
* 用 git remote url 唯一标识项目
|
|
126
|
+
*/
|
|
127
|
+
repo: string;
|
|
128
|
+
/**
|
|
129
|
+
* 人工编辑的字段,方便搜索结果展示和过滤
|
|
130
|
+
*/
|
|
131
|
+
title?: string;
|
|
132
|
+
tags?: string[];
|
|
133
|
+
summary?: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
link?: string;
|
|
136
|
+
/**
|
|
137
|
+
* 项目状态:active 活动中 | inactive 非活动
|
|
138
|
+
*/
|
|
139
|
+
status?: 'active' | 'inactive';
|
|
140
|
+
};
|
|
141
|
+
declare class ProjectStore {
|
|
142
|
+
meiliSearch: MeiliSearch;
|
|
143
|
+
constructor({ apiHost, apiKey }?: {
|
|
144
|
+
apiHost?: string;
|
|
145
|
+
apiKey?: string;
|
|
146
|
+
});
|
|
147
|
+
private get index();
|
|
148
|
+
ensureIndex(): Promise<void>;
|
|
149
|
+
init(): Promise<void>;
|
|
150
|
+
addProject(input: {
|
|
151
|
+
name?: string;
|
|
152
|
+
path: string;
|
|
153
|
+
repo: string;
|
|
154
|
+
status?: 'active' | 'inactive';
|
|
155
|
+
}): Promise<void>;
|
|
156
|
+
removeProject(projectPath: string): Promise<void>;
|
|
157
|
+
listProjects(): Promise<ProjectDoc[]>;
|
|
158
|
+
getProject(projectPath: string): Promise<ProjectDoc | null>;
|
|
159
|
+
updateProject(projectPath: string, opts: {
|
|
160
|
+
name?: string;
|
|
161
|
+
repo?: string;
|
|
162
|
+
title?: string;
|
|
163
|
+
tags?: string[];
|
|
164
|
+
summary?: string;
|
|
165
|
+
description?: string;
|
|
166
|
+
link?: string;
|
|
167
|
+
status?: 'active' | 'inactive';
|
|
168
|
+
}): Promise<void>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
declare class ProjectListener {
|
|
172
|
+
projectPath: string;
|
|
173
|
+
subscribe: ParcelWatcher.AsyncSubscription | null;
|
|
174
|
+
isWatching: boolean;
|
|
175
|
+
emitter: EventEmitter;
|
|
176
|
+
private updateDebounceMap;
|
|
177
|
+
constructor(options: {
|
|
178
|
+
projectPath: string;
|
|
179
|
+
emitter: EventEmitter;
|
|
180
|
+
});
|
|
181
|
+
startListening(): Promise<void>;
|
|
182
|
+
stopListening(): Promise<void>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
type Project = {
|
|
186
|
+
name?: string;
|
|
187
|
+
path: string;
|
|
188
|
+
/**
|
|
189
|
+
* 用 git remote url 唯一标识项目,方便搜索结果展示和过滤
|
|
190
|
+
*/
|
|
191
|
+
repo: string;
|
|
192
|
+
listener: ProjectListener;
|
|
193
|
+
};
|
|
194
|
+
type ProjectInput = Omit<Project, "listener">;
|
|
195
|
+
type ProjectInfo = Omit<Project, "listener"> & {
|
|
196
|
+
status: "active" | "inactive";
|
|
197
|
+
};
|
|
198
|
+
type ProjectManagerOpt = {
|
|
199
|
+
meiliSearchOptions?: {
|
|
200
|
+
apiHost?: string;
|
|
201
|
+
apiKey?: string;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
declare class ProjectManager implements ProjectManagerInterface {
|
|
205
|
+
projects: Map<string, Project>;
|
|
206
|
+
projectSearch: ProjectSearch;
|
|
207
|
+
projectStore: ProjectStore;
|
|
208
|
+
emitter: EventEmitter;
|
|
209
|
+
constructor(options?: ProjectManagerOpt);
|
|
210
|
+
/**
|
|
211
|
+
* 初始化:从 store 加载已持久化的项目,检查本地目录存在后启动监听
|
|
212
|
+
*/
|
|
213
|
+
init(): Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* 添加项目:创建监听器、启动监听、触发全量初始同步
|
|
216
|
+
*/
|
|
217
|
+
addProject(input: ProjectInput): Promise<ProjectInfo>;
|
|
218
|
+
removeProject(projectPath: string): Promise<void>;
|
|
219
|
+
getProject(projectPath: string): Project;
|
|
220
|
+
/** 停止项目文件监听,但不删除索引数据 */
|
|
221
|
+
stopProject(projectPath: string): Promise<void>;
|
|
222
|
+
getProjectInfo(project: Project): ProjectInfo;
|
|
223
|
+
listProjects(): ProjectInfo[];
|
|
224
|
+
getFile(filepath: string): Promise<{
|
|
225
|
+
filepath: string;
|
|
226
|
+
content: string;
|
|
227
|
+
type: string;
|
|
228
|
+
} | null>;
|
|
229
|
+
deleteFile(filepath: string): Promise<boolean>;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
declare class FileSearch {
|
|
233
|
+
searchFiles(options?: {
|
|
234
|
+
cwd?: string;
|
|
235
|
+
ignore?: string[];
|
|
236
|
+
}): Promise<any>;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export { FileSearch, ProjectListener, ProjectManager, ProjectSearch, Scheduler, app, manager };
|