@longzai-intelligence-electron/core 0.0.2
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/index.d.ts +1095 -0
- package/dist/index.js +1 -0
- package/dist/ipc.schema-CRktvhDm.js +1 -0
- package/dist/preload.d.ts +603 -0
- package/dist/preload.js +1 -0
- package/dist/rolldown-runtime-BqT_7tdF.js +1 -0
- package/dist/types-DKXNvkb9.d.ts +533 -0
- package/package.json +57 -0
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
//#region src/schemas/ipc.schema.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* IPC 错误码 Schema
|
|
5
|
+
*/
|
|
6
|
+
declare const IPCErrorCodeSchema: z.ZodEnum<{
|
|
7
|
+
CONFLICT: "CONFLICT";
|
|
8
|
+
INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
9
|
+
INVALID_INPUT: "INVALID_INPUT";
|
|
10
|
+
NETWORK_ERROR: "NETWORK_ERROR";
|
|
11
|
+
NOT_FOUND: "NOT_FOUND";
|
|
12
|
+
PERMISSION_DENIED: "PERMISSION_DENIED";
|
|
13
|
+
RESOURCE_EXHAUSTED: "RESOURCE_EXHAUSTED";
|
|
14
|
+
TIMEOUT: "TIMEOUT";
|
|
15
|
+
UNAUTHORIZED: "UNAUTHORIZED";
|
|
16
|
+
VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* IPC 错误码类型
|
|
20
|
+
*/
|
|
21
|
+
type IPCErrorCode$1 = z.infer<typeof IPCErrorCodeSchema>;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/ipc/base/result.utils.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* IPC 错误
|
|
26
|
+
*/
|
|
27
|
+
type IPCError$1 = {
|
|
28
|
+
/**
|
|
29
|
+
* 错误码,标识错误类别
|
|
30
|
+
*/
|
|
31
|
+
code: IPCErrorCode$1;
|
|
32
|
+
/**
|
|
33
|
+
* 人类可读的错误消息
|
|
34
|
+
*/
|
|
35
|
+
message: string;
|
|
36
|
+
/**
|
|
37
|
+
* 错误的附加详情信息
|
|
38
|
+
*/
|
|
39
|
+
details?: Record<string, unknown>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* IPC 结果
|
|
43
|
+
*
|
|
44
|
+
* @typeParam T - 数据类型
|
|
45
|
+
*/
|
|
46
|
+
type IPCResult$1<T = void> = {
|
|
47
|
+
/**
|
|
48
|
+
* 标识操作是否成功
|
|
49
|
+
*/
|
|
50
|
+
success: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 成功时返回的数据
|
|
53
|
+
*/
|
|
54
|
+
data?: T;
|
|
55
|
+
/**
|
|
56
|
+
* 失败时的错误信息
|
|
57
|
+
*/
|
|
58
|
+
error?: IPCError$1;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* 创建成功结果
|
|
62
|
+
*
|
|
63
|
+
* @typeParam T - 数据类型
|
|
64
|
+
* @param data - 可选,成功返回的数据。不传时返回无数据的成功结果
|
|
65
|
+
* @returns 成功结果
|
|
66
|
+
*/
|
|
67
|
+
declare function success<T>(data?: T): IPCResult$1<T>;
|
|
68
|
+
/**
|
|
69
|
+
* 创建失败结果
|
|
70
|
+
*
|
|
71
|
+
* @param code - 错误码
|
|
72
|
+
* @param message - 错误消息
|
|
73
|
+
* @param details - 可选的错误详情
|
|
74
|
+
* @returns 失败结果
|
|
75
|
+
*/
|
|
76
|
+
declare function failure(code: IPCErrorCode$1, message: string, details?: Record<string, unknown>): IPCResult$1<never>;
|
|
77
|
+
/**
|
|
78
|
+
* 成功结果类型守卫
|
|
79
|
+
*
|
|
80
|
+
* @typeParam T - 数据类型
|
|
81
|
+
* @param result - IPC 结果
|
|
82
|
+
* @returns 是否为成功结果
|
|
83
|
+
*/
|
|
84
|
+
declare function isSuccess<T>(result: IPCResult$1<T>): result is IPCResult$1<T> & {
|
|
85
|
+
/**
|
|
86
|
+
* 操作成功标识
|
|
87
|
+
*/
|
|
88
|
+
success: true;
|
|
89
|
+
/**
|
|
90
|
+
* 成功返回的数据
|
|
91
|
+
*/
|
|
92
|
+
data: T;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* 失败结果类型守卫
|
|
96
|
+
*
|
|
97
|
+
* @typeParam T - 数据类型
|
|
98
|
+
* @param result - IPC 结果
|
|
99
|
+
* @returns 是否为失败结果
|
|
100
|
+
*/
|
|
101
|
+
declare function isFailure<T>(result: IPCResult$1<T>): result is IPCResult$1<T> & {
|
|
102
|
+
/**
|
|
103
|
+
* 操作失败标识
|
|
104
|
+
*/
|
|
105
|
+
success: false;
|
|
106
|
+
/**
|
|
107
|
+
* 失败错误信息
|
|
108
|
+
*/
|
|
109
|
+
error: IPCError$1;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* 解包 IPCResult 并返回成功数据
|
|
113
|
+
*
|
|
114
|
+
* @typeParam T - 数据类型
|
|
115
|
+
* @param result - IPC 结果
|
|
116
|
+
* @param fallbackMessage - 兜底错误消息
|
|
117
|
+
* @returns 成功数据
|
|
118
|
+
* @throws {@link Error} 当结果为失败时抛出错误
|
|
119
|
+
*/
|
|
120
|
+
declare function unwrap<T>(result: IPCResult$1<T>, fallbackMessage: string): T;
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/ipc/typed/types.d.ts
|
|
123
|
+
/**
|
|
124
|
+
* Typed IPC 类型定义
|
|
125
|
+
*
|
|
126
|
+
* 提供基于 TypeScript 类型推断的强类型 IPC 类型
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* Null 类型别名
|
|
130
|
+
*
|
|
131
|
+
* 用于避免 ESLint 规则错误检测
|
|
132
|
+
*/
|
|
133
|
+
type Null = null;
|
|
134
|
+
/**
|
|
135
|
+
* Undefined 类型别名
|
|
136
|
+
*
|
|
137
|
+
* 用于避免 ESLint 规则错误检测
|
|
138
|
+
*/
|
|
139
|
+
type Undefined = undefined;
|
|
140
|
+
/**
|
|
141
|
+
* IPC 可序列化类型
|
|
142
|
+
*/
|
|
143
|
+
type IPCSerializable = string | number | boolean | Null | Undefined | Date | Buffer | ArrayBuffer | IPCSerializable[] | {
|
|
144
|
+
[key: string]: IPCSerializable;
|
|
145
|
+
} | Map<IPCSerializable, IPCSerializable> | Set<IPCSerializable>;
|
|
146
|
+
/**
|
|
147
|
+
* IPC 方法定义
|
|
148
|
+
*
|
|
149
|
+
* P 为参数类型(必须是只读数组),R 为返回类型
|
|
150
|
+
*
|
|
151
|
+
* @typeParam P - 参数类型
|
|
152
|
+
* @typeParam R - 返回类型
|
|
153
|
+
*/
|
|
154
|
+
type IPCMethodDefinition$1<P extends readonly unknown[] = readonly unknown[], R = unknown> = {
|
|
155
|
+
/**
|
|
156
|
+
* 方法参数类型的只读数组
|
|
157
|
+
*/
|
|
158
|
+
params: P;
|
|
159
|
+
/**
|
|
160
|
+
* 方法返回值类型
|
|
161
|
+
*/
|
|
162
|
+
return: R;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* 严格 IPC API 类型
|
|
166
|
+
*
|
|
167
|
+
* 所有 IPC 方法定义的集合,键为通道名,值为方法定义
|
|
168
|
+
*/
|
|
169
|
+
type StrictIPCAPI = {
|
|
170
|
+
[key: string]: IPCMethodDefinition$1;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* IPC 参数提取
|
|
174
|
+
*
|
|
175
|
+
* T 为 IPC 方法定义类型
|
|
176
|
+
*
|
|
177
|
+
* @typeParam T - IPC 方法定义类型
|
|
178
|
+
*/
|
|
179
|
+
type IPCParams<T extends IPCMethodDefinition$1> = T['params'];
|
|
180
|
+
/**
|
|
181
|
+
* IPC 参数数组提取
|
|
182
|
+
*
|
|
183
|
+
* T 为 IPC 方法定义类型
|
|
184
|
+
*
|
|
185
|
+
* @typeParam T - IPC 方法定义类型
|
|
186
|
+
*/
|
|
187
|
+
type IPCParamsArray<T extends IPCMethodDefinition$1> = [...T['params']];
|
|
188
|
+
/**
|
|
189
|
+
* IPC 返回值提取
|
|
190
|
+
*
|
|
191
|
+
* T 为 IPC 方法定义类型
|
|
192
|
+
*
|
|
193
|
+
* @typeParam T - IPC 方法定义类型
|
|
194
|
+
*/
|
|
195
|
+
type IPCReturn<T extends IPCMethodDefinition$1> = T['return'];
|
|
196
|
+
/**
|
|
197
|
+
* 从 IPC 通道名中提取简短方法名
|
|
198
|
+
*
|
|
199
|
+
* 支持多级通道名(如 'plugin:git:status' 转换为 'status')
|
|
200
|
+
* K 为通道名字符串
|
|
201
|
+
*
|
|
202
|
+
* @typeParam K - 通道名字符串
|
|
203
|
+
*/
|
|
204
|
+
type ExtractMethodName<K extends string> = K extends `${string}:${infer Method}` ? Method extends `${string}:${infer LastMethod}` ? LastMethod : Method : K;
|
|
205
|
+
/**
|
|
206
|
+
* IPC API 短方法名函数类型
|
|
207
|
+
*
|
|
208
|
+
* T 为 IPC 方法定义类型
|
|
209
|
+
*
|
|
210
|
+
* @typeParam T - IPC 方法定义类型
|
|
211
|
+
*/
|
|
212
|
+
type IPCShortFunction<T extends IPCMethodDefinition$1> = T extends IPCMethodDefinition$1<infer P, infer R> ? (...args: [...P]) => Promise<R> : never;
|
|
213
|
+
/**
|
|
214
|
+
* 将 IPC API 转换为短方法名 API
|
|
215
|
+
*
|
|
216
|
+
* 从通道名中提取方法名(如 'user:getAll' 转换为 'getAll')
|
|
217
|
+
* T 为 IPC API 类型
|
|
218
|
+
*
|
|
219
|
+
* @typeParam T - IPC API 类型
|
|
220
|
+
*/
|
|
221
|
+
type IPCAPIToShortAPI<T extends StrictIPCAPI> = { [K in keyof T as ExtractMethodName<K & string>]: IPCShortFunction<T[K]>; };
|
|
222
|
+
/**
|
|
223
|
+
* IPC API 函数类型
|
|
224
|
+
*
|
|
225
|
+
* T 为 IPC 方法定义类型
|
|
226
|
+
*
|
|
227
|
+
* @typeParam T - IPC 方法定义类型
|
|
228
|
+
*/
|
|
229
|
+
type IPCFunction<T extends IPCMethodDefinition$1> = T extends IPCMethodDefinition$1<infer P, infer R> ? (...args: [...P]) => Promise<R> : never;
|
|
230
|
+
/**
|
|
231
|
+
* 将 IPC API 定义转换为函数调用签名
|
|
232
|
+
*
|
|
233
|
+
* 保留原始通道名作为键名
|
|
234
|
+
* T 为 IPC API 类型
|
|
235
|
+
*
|
|
236
|
+
* @typeParam T - IPC API 类型
|
|
237
|
+
*/
|
|
238
|
+
type IPCAPIToFunctions<T extends StrictIPCAPI> = { [K in keyof T]: IPCFunction<T[K]>; };
|
|
239
|
+
/**
|
|
240
|
+
* IPC API 映射函数类型
|
|
241
|
+
*
|
|
242
|
+
* T 为 IPC API 类型,M 为键名
|
|
243
|
+
*
|
|
244
|
+
* @typeParam T - IPC API 类型
|
|
245
|
+
* @typeParam M - 键名
|
|
246
|
+
*/
|
|
247
|
+
type IPCMappingFunction<T extends StrictIPCAPI, M extends keyof T> = T[M] extends IPCMethodDefinition$1<infer P, infer R> ? (...args: [...P]) => Promise<R> : never;
|
|
248
|
+
/**
|
|
249
|
+
* 创建带有方法名映射的 API 类型
|
|
250
|
+
*
|
|
251
|
+
* T 为 IPC API 类型,M 为方法名映射
|
|
252
|
+
*
|
|
253
|
+
* @typeParam T - IPC API 类型
|
|
254
|
+
* @typeParam M - 方法名映射
|
|
255
|
+
*/
|
|
256
|
+
type IPCAPIWithMapping<T extends StrictIPCAPI, M extends Record<string, keyof T>> = { [K in keyof M]: IPCMappingFunction<T, M[K]>; };
|
|
257
|
+
/**
|
|
258
|
+
* Typed API 函数类型
|
|
259
|
+
*
|
|
260
|
+
* T 为 API 类型,M 为键名
|
|
261
|
+
*
|
|
262
|
+
* @typeParam T - API 类型
|
|
263
|
+
* @typeParam M - 键名
|
|
264
|
+
*/
|
|
265
|
+
type TypedAPIFunction<T extends Record<string, unknown>, M extends keyof T> = T[M] extends IPCMethodDefinition$1<infer P, infer R> ? (...args: [...P]) => Promise<R> : never;
|
|
266
|
+
/**
|
|
267
|
+
* 创建类型安全的 API 对象类型定义
|
|
268
|
+
*
|
|
269
|
+
* T 为 API 类型,M 为方法名映射
|
|
270
|
+
*
|
|
271
|
+
* @typeParam T - API 类型
|
|
272
|
+
* @typeParam M - 方法名映射
|
|
273
|
+
*/
|
|
274
|
+
type TypedAPI<T extends Record<string, unknown>, M extends Record<string, keyof T>> = { [K in keyof M]: TypedAPIFunction<T, M[K]>; };
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/ipc/zod/schemas.d.ts
|
|
277
|
+
/**
|
|
278
|
+
* IPC 错误 Schema
|
|
279
|
+
*/
|
|
280
|
+
declare const IPCErrorSchema: z.ZodObject<{
|
|
281
|
+
code: z.ZodEnum<{
|
|
282
|
+
CONFLICT: "CONFLICT";
|
|
283
|
+
INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
284
|
+
INVALID_INPUT: "INVALID_INPUT";
|
|
285
|
+
NETWORK_ERROR: "NETWORK_ERROR";
|
|
286
|
+
NOT_FOUND: "NOT_FOUND";
|
|
287
|
+
PERMISSION_DENIED: "PERMISSION_DENIED";
|
|
288
|
+
RESOURCE_EXHAUSTED: "RESOURCE_EXHAUSTED";
|
|
289
|
+
TIMEOUT: "TIMEOUT";
|
|
290
|
+
UNAUTHORIZED: "UNAUTHORIZED";
|
|
291
|
+
VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
292
|
+
}>;
|
|
293
|
+
message: z.ZodString;
|
|
294
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
295
|
+
}, z.core.$strip>;
|
|
296
|
+
/**
|
|
297
|
+
* IPC 结果 Schema 类型
|
|
298
|
+
*
|
|
299
|
+
* @typeParam T - 数据 Schema 类型
|
|
300
|
+
*/
|
|
301
|
+
type IPCResultSchemaType<T extends z.ZodTypeAny> = z.ZodObject<{
|
|
302
|
+
/**
|
|
303
|
+
* 操作是否成功
|
|
304
|
+
*/
|
|
305
|
+
success: z.ZodBoolean;
|
|
306
|
+
/**
|
|
307
|
+
* 成功时返回的数据
|
|
308
|
+
*/
|
|
309
|
+
data: z.ZodOptional<T>;
|
|
310
|
+
/**
|
|
311
|
+
* 失败时的错误信息
|
|
312
|
+
*/
|
|
313
|
+
error: z.ZodOptional<typeof IPCErrorSchema>;
|
|
314
|
+
}>;
|
|
315
|
+
/**
|
|
316
|
+
* 创建 IPC 结果 Schema 的工厂函数
|
|
317
|
+
*
|
|
318
|
+
* @typeParam T - 数据 Schema 类型
|
|
319
|
+
* @param dataSchema - 数据 Schema
|
|
320
|
+
* @returns IPC 结果 Schema
|
|
321
|
+
*/
|
|
322
|
+
declare function createIPCResultSchema<T extends z.ZodTypeAny>(dataSchema: T): IPCResultSchemaType<T>;
|
|
323
|
+
/**
|
|
324
|
+
* IPC 结果 Schema(无数据)
|
|
325
|
+
*/
|
|
326
|
+
declare const IPCResultSchema: IPCResultSchemaType<z.ZodVoid>;
|
|
327
|
+
/**
|
|
328
|
+
* IPC 方法定义 Schema 类型
|
|
329
|
+
*
|
|
330
|
+
* @typeParam P - 参数 Schema 类型
|
|
331
|
+
* @typeParam R - 返回值 Schema 类型
|
|
332
|
+
*/
|
|
333
|
+
type IPCMethodDefinitionSchemaType<P extends z.ZodTypeAny, R extends z.ZodTypeAny> = z.ZodObject<{
|
|
334
|
+
/**
|
|
335
|
+
* 方法参数 Schema
|
|
336
|
+
*/
|
|
337
|
+
params: P;
|
|
338
|
+
/**
|
|
339
|
+
* 方法返回值 Schema
|
|
340
|
+
*/
|
|
341
|
+
return: R;
|
|
342
|
+
}>;
|
|
343
|
+
/**
|
|
344
|
+
* IPC 方法定义 Schema 工厂
|
|
345
|
+
*
|
|
346
|
+
* @typeParam P - 参数 Schema 类型
|
|
347
|
+
* @typeParam R - 返回值 Schema 类型
|
|
348
|
+
* @param paramsSchema - 参数 Schema
|
|
349
|
+
* @param returnSchema - 返回值 Schema
|
|
350
|
+
* @returns IPC 方法定义 Schema
|
|
351
|
+
*/
|
|
352
|
+
declare function createIPCMethodDefinitionSchema<P extends z.ZodTypeAny, R extends z.ZodTypeAny>(paramsSchema: P, returnSchema: R): IPCMethodDefinitionSchemaType<P, R>;
|
|
353
|
+
/**
|
|
354
|
+
* IPC 方法定义类型
|
|
355
|
+
*
|
|
356
|
+
* @typeParam P - 参数类型
|
|
357
|
+
* @typeParam R - 返回类型
|
|
358
|
+
*/
|
|
359
|
+
type IPCMethodDefinition<P extends readonly unknown[] = readonly unknown[], R = unknown> = {
|
|
360
|
+
/**
|
|
361
|
+
* 方法参数类型的只读数组
|
|
362
|
+
*/
|
|
363
|
+
params: P;
|
|
364
|
+
/**
|
|
365
|
+
* 方法返回值类型
|
|
366
|
+
*/
|
|
367
|
+
return: R;
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* 创建 IPC API Schema 的工厂函数
|
|
371
|
+
*
|
|
372
|
+
* @typeParam T - API Schema 类型
|
|
373
|
+
* @param apiSchema - API Schema 定义
|
|
374
|
+
* @returns IPC API Schema
|
|
375
|
+
*/
|
|
376
|
+
declare function createIPCAPISchema<T extends z.ZodObject<Record<string, z.ZodTypeAny>>>(apiSchema: T): T;
|
|
377
|
+
/**
|
|
378
|
+
* 创建 IPC 函数 Schema(Zod v4 API)
|
|
379
|
+
*
|
|
380
|
+
* @typeParam I - 输入 Schema 类型
|
|
381
|
+
* @typeParam O - 输出 Schema 类型
|
|
382
|
+
* @param inputSchema - 输入 Schema(参数元组)
|
|
383
|
+
* @param outputSchema - 输出 Schema(返回值)
|
|
384
|
+
* @returns IPC 函数 Schema
|
|
385
|
+
*/
|
|
386
|
+
declare function createIPCFunctionSchema<I extends z.ZodTuple<[...z.ZodTypeAny[]], null>, O extends z.ZodTypeAny>(inputSchema: I, outputSchema: O): z.ZodFunction<I, O>;
|
|
387
|
+
/**
|
|
388
|
+
* Zod IPC 方法定义(声明式)
|
|
389
|
+
*
|
|
390
|
+
* input 为参数 Schema 数组,无参数可省略
|
|
391
|
+
* output 为返回值 Schema
|
|
392
|
+
*/
|
|
393
|
+
type ZodIPCMethodDecl = {
|
|
394
|
+
/**
|
|
395
|
+
* 参数 Schema 数组,无参数可省略
|
|
396
|
+
*/
|
|
397
|
+
input?: z.ZodTypeAny[];
|
|
398
|
+
/**
|
|
399
|
+
* 返回值 Schema
|
|
400
|
+
*/
|
|
401
|
+
output: z.ZodTypeAny;
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Zod IPC 方法定义集合
|
|
405
|
+
*
|
|
406
|
+
* 键为方法名,值为方法定义
|
|
407
|
+
*/
|
|
408
|
+
type ZodIPCMethodsDefinition = Record<string, ZodIPCMethodDecl>;
|
|
409
|
+
/**
|
|
410
|
+
* 从方法定义集合中提取方法名
|
|
411
|
+
*
|
|
412
|
+
* @typeParam T - 方法定义集合类型
|
|
413
|
+
*/
|
|
414
|
+
type MethodNames<T extends ZodIPCMethodsDefinition> = keyof T & string;
|
|
415
|
+
/**
|
|
416
|
+
* Zod IPC Schema 对象
|
|
417
|
+
*
|
|
418
|
+
* @typeParam T - 方法定义集合类型
|
|
419
|
+
*/
|
|
420
|
+
type ZodIPCSchema<T extends ZodIPCMethodsDefinition> = {
|
|
421
|
+
/**
|
|
422
|
+
* 通道名映射
|
|
423
|
+
*/
|
|
424
|
+
channels: Record<MethodNames<T>, string>;
|
|
425
|
+
/**
|
|
426
|
+
* 底层 Zod Schema
|
|
427
|
+
*
|
|
428
|
+
* 类型断言:z.object(schemaShape) 返回类型
|
|
429
|
+
*
|
|
430
|
+
* 断言原因:
|
|
431
|
+
*
|
|
432
|
+
* 1. SchemaShape 是运行时构建的 Record<string, z.ZodFunction>
|
|
433
|
+
* 2. TypeScript 无法在编译时推断运行时构建的对象类型
|
|
434
|
+
* 3. z.object() 返回 ZodObject,但具体形状在运行时确定
|
|
435
|
+
*
|
|
436
|
+
* 安全保障:
|
|
437
|
+
*
|
|
438
|
+
* - defineZodIPCSchema 函数确保 schemaShape 只包含 ZodFunction
|
|
439
|
+
* - 单元测试覆盖所有 schema 创建场景
|
|
440
|
+
*/
|
|
441
|
+
schema: z.ZodObject<{ [K in keyof T]: z.ZodFunction<T[K]['input'] extends z.ZodTypeAny[] ? z.ZodTuple<{ [I in keyof T[K]['input']]: T[K]['input'][I]; }, null> : z.ZodTuple<[]>, IPCResultSchemaType<T[K]['output']>>; }>;
|
|
442
|
+
/**
|
|
443
|
+
* API类型(用于类型推断,运行时为空对象)
|
|
444
|
+
*/
|
|
445
|
+
API?: { [K in MethodNames<T>]: (...args: unknown[]) => Promise<IPCResult$1<unknown>>; };
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* 从 ZodIPCSchema 推断 IPC API 类型
|
|
449
|
+
*
|
|
450
|
+
* @typeParam T - ZodIPCMethodsDefinition 类型
|
|
451
|
+
*/
|
|
452
|
+
type InferIPCAPI<T extends ZodIPCMethodsDefinition> = { [K in keyof T & string]: (...args: unknown[]) => Promise<IPCResult$1<z.infer<T[K]['output']>>>; };
|
|
453
|
+
/**
|
|
454
|
+
* 从 ZodIPCSchema 对象推断 IPC API 类型
|
|
455
|
+
*
|
|
456
|
+
* @typeParam S - ZodIPCSchema 类型
|
|
457
|
+
*/
|
|
458
|
+
type InferIPCAPIFromSchema<S> = S extends ZodIPCSchema<infer T> ? InferIPCAPI<T> : never;
|
|
459
|
+
/**
|
|
460
|
+
* 声明式定义 Zod IPC Schema
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```typescript
|
|
464
|
+
* const AgentIPCAPISchema = defineZodIPCSchema('agent', {
|
|
465
|
+
* getAll: { output: z.array(AgentSchema) },
|
|
466
|
+
* getById: { input: [z.string()], output: AgentSchema.nullable() },
|
|
467
|
+
* create: { input: [AgentCreateParamsSchema], output: AgentSchema },
|
|
468
|
+
* delete: { input: [z.string()], output: z.void() },
|
|
469
|
+
* });
|
|
470
|
+
*
|
|
471
|
+
* // 通道名自动推导
|
|
472
|
+
* AgentIPCAPISchema.channels.getAll; // 'agent:getAll'
|
|
473
|
+
*
|
|
474
|
+
* // Main 进程使用
|
|
475
|
+
* const handle = createZodHandle(AgentIPCAPISchema, AgentIPCAPISchema.channels);
|
|
476
|
+
* handle('getAll', async () => success(await repo.getAll()));
|
|
477
|
+
*
|
|
478
|
+
* // Preload 进程使用
|
|
479
|
+
* const agentAPI = createZodAPI(AgentIPCAPISchema, AgentIPCAPISchema.channels);
|
|
480
|
+
* ```;
|
|
481
|
+
*
|
|
482
|
+
* @typeParam T - 方法定义集合类型
|
|
483
|
+
* @param domain - 领域名称,用于推导通道名前缀
|
|
484
|
+
* @param methods - 方法定义对象
|
|
485
|
+
* @returns ZodIPCSchema 对象
|
|
486
|
+
*/
|
|
487
|
+
declare function defineZodIPCSchema<T extends ZodIPCMethodsDefinition>(domain: string, methods: T): ZodIPCSchema<T>;
|
|
488
|
+
//#endregion
|
|
489
|
+
//#region src/ipc/base/types.d.ts
|
|
490
|
+
/**
|
|
491
|
+
* IPC 错误码
|
|
492
|
+
*/
|
|
493
|
+
type IPCErrorCode = 'NOT_FOUND' | 'VALIDATION_ERROR' | 'PERMISSION_DENIED' | 'INTERNAL_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'CONFLICT' | 'INVALID_INPUT' | 'RESOURCE_EXHAUSTED' | 'UNAUTHORIZED';
|
|
494
|
+
/**
|
|
495
|
+
* IPC 错误
|
|
496
|
+
*/
|
|
497
|
+
type IPCError = {
|
|
498
|
+
/**
|
|
499
|
+
* 错误码,标识错误类别
|
|
500
|
+
*/
|
|
501
|
+
code: IPCErrorCode;
|
|
502
|
+
/**
|
|
503
|
+
* 人类可读的错误消息
|
|
504
|
+
*/
|
|
505
|
+
message: string;
|
|
506
|
+
/**
|
|
507
|
+
* 错误的附加详情信息
|
|
508
|
+
*/
|
|
509
|
+
details?: Record<string, unknown>;
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* IPC 结果
|
|
513
|
+
*
|
|
514
|
+
* T 为成功时的数据类型
|
|
515
|
+
*
|
|
516
|
+
* @typeParam T - 数据类型
|
|
517
|
+
*/
|
|
518
|
+
type IPCResult<T = void> = {
|
|
519
|
+
/**
|
|
520
|
+
* 标识操作是否成功
|
|
521
|
+
*/
|
|
522
|
+
success: boolean;
|
|
523
|
+
/**
|
|
524
|
+
* 成功时返回的数据
|
|
525
|
+
*/
|
|
526
|
+
data?: T;
|
|
527
|
+
/**
|
|
528
|
+
* 失败时的错误信息
|
|
529
|
+
*/
|
|
530
|
+
error?: IPCError;
|
|
531
|
+
};
|
|
532
|
+
//#endregion
|
|
533
|
+
export { isSuccess as A, IPCSerializable as C, IPCResult$1 as D, IPCError$1 as E, unwrap as M, IPCErrorCode$1 as N, failure as O, IPCErrorCodeSchema as P, IPCReturn as S, TypedAPI as T, IPCAPIToShortAPI as _, InferIPCAPI as a, IPCParams as b, ZodIPCMethodsDefinition as c, createIPCFunctionSchema as d, createIPCMethodDefinitionSchema as f, IPCAPIToFunctions as g, ExtractMethodName as h, IPCResultSchema as i, success as j, isFailure as k, ZodIPCSchema as l, defineZodIPCSchema as m, IPCErrorSchema as n, InferIPCAPIFromSchema as o, createIPCResultSchema as p, IPCMethodDefinition as r, ZodIPCMethodDecl as s, IPCResult as t, createIPCAPISchema as u, IPCAPIWithMapping as v, StrictIPCAPI as w, IPCParamsArray as x, IPCMethodDefinition$1 as y };
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-electron/core",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./preload": {
|
|
15
|
+
"types": "./dist/preload.d.ts",
|
|
16
|
+
"import": "./dist/preload.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "lzi-builder",
|
|
21
|
+
"build:prod": "NODE_ENV=production lzi-builder",
|
|
22
|
+
"prepublishOnly": "bun run build:prod",
|
|
23
|
+
"dev": "tsgo --build --watch tsconfig/build.json",
|
|
24
|
+
"clean": "lzi-dev-cli clean",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"test:coverage": "vitest run --coverage",
|
|
28
|
+
"lint": "oxlint && oxfmt --check",
|
|
29
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
30
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
31
|
+
"typecheck:app": "tsgo --noEmit -p tsconfig/app.json",
|
|
32
|
+
"typecheck:node": "tsgo --noEmit -p tsconfig/node.json",
|
|
33
|
+
"typecheck:test": "tsgo --noEmit -p tsconfig/test.json"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@longzai-intelligence-zod/utils": "^0.0.5",
|
|
37
|
+
"zod": "^4.4.3"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@longzai-intelligence-testing/utils": "^0.0.3",
|
|
41
|
+
"@longzai-intelligence-vitest/config": "^0.0.12",
|
|
42
|
+
"electron": "^43"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"electron": "^41",
|
|
46
|
+
"typeorm": "^1.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"electron": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"typeorm": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"packageManager": "bun@1.3.14"
|
|
57
|
+
}
|