-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathprompt.ts
More file actions
45 lines (44 loc) · 2.05 KB
/
Copy pathprompt.ts
File metadata and controls
45 lines (44 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { ipcRenderer } from "electron";
import { IPC_CHANNELS } from "@prompthub/shared/constants/ipc-channels";
import type {
CreatePromptDTO,
Folder,
Prompt,
PromptVersion,
SearchQuery,
UpdatePromptDTO,
} from "@prompthub/shared/types";
export const promptApi = {
create: (data: CreatePromptDTO) =>
ipcRenderer.invoke(IPC_CHANNELS.PROMPT_CREATE, data),
get: (id: string) => ipcRenderer.invoke(IPC_CHANNELS.PROMPT_GET, id),
getAll: () => ipcRenderer.invoke(IPC_CHANNELS.PROMPT_GET_ALL),
getAllTags: () => ipcRenderer.invoke(IPC_CHANNELS.PROMPT_GET_ALL_TAGS),
renameTag: (oldTag: string, newTag: string) => ipcRenderer.invoke(IPC_CHANNELS.PROMPT_RENAME_TAG, oldTag, newTag),
deleteTag: (tag: string) => ipcRenderer.invoke(IPC_CHANNELS.PROMPT_DELETE_TAG, tag),
update: (id: string, data: UpdatePromptDTO) =>
ipcRenderer.invoke(IPC_CHANNELS.PROMPT_UPDATE, id, data),
delete: (id: string) => ipcRenderer.invoke(IPC_CHANNELS.PROMPT_DELETE, id),
search: (query: SearchQuery) =>
ipcRenderer.invoke(IPC_CHANNELS.PROMPT_SEARCH, query),
copy: (id: string, variables: Record<string, string>) =>
ipcRenderer.invoke(IPC_CHANNELS.PROMPT_COPY, id, variables),
insertDirect: (prompt: Prompt) =>
ipcRenderer.invoke(IPC_CHANNELS.PROMPT_INSERT_DIRECT, prompt),
syncWorkspace: () => ipcRenderer.invoke(IPC_CHANNELS.PROMPT_SYNC_WORKSPACE),
/**
* Atomically migrate legacy IndexedDB data into SQLite via a single
* main-process transaction. Safe to call multiple times — the handler
* returns { imported: false } when the target already has data.
*
* 原子批量迁移:通过单事务将 IndexedDB 数据写入 SQLite。
* 幂等:目标已有数据时返回 { imported: false }。
*/
migrateIdbBatch: (payload: {
folders: Folder[];
prompts: Prompt[];
versions: PromptVersion[];
}) => ipcRenderer.invoke(IPC_CHANNELS.PROMPT_MIGRATE_IDB_BATCH, payload),
move: (promptId: string, newParentId: string | null, newOrder: number) =>
ipcRenderer.invoke(IPC_CHANNELS.PROMPT_MOVE, promptId, newParentId, newOrder),
};