imean-service-engine 1.5.0 → 1.7.0
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/README.md +298 -0
- package/dist/mod.cjs +395 -35
- package/dist/mod.d.cts +100 -11
- package/dist/mod.d.ts +100 -11
- package/dist/mod.js +390 -36
- package/package.json +1 -1
package/dist/mod.d.cts
CHANGED
@@ -6,6 +6,8 @@ import { Lease, Etcd3 } from 'etcd3';
|
|
6
6
|
import { Hono } from 'hono';
|
7
7
|
export { default as dayjs } from 'dayjs';
|
8
8
|
import winston from 'winston';
|
9
|
+
import * as hono_utils_html from 'hono/utils/html';
|
10
|
+
import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
|
9
11
|
|
10
12
|
declare abstract class CacheAdapter {
|
11
13
|
abstract get(key: string): Promise<any>;
|
@@ -39,6 +41,14 @@ interface ActionOptions {
|
|
39
41
|
stream?: boolean;
|
40
42
|
mcp?: McpOptions;
|
41
43
|
}
|
44
|
+
interface PageOptions {
|
45
|
+
method: "get" | "post" | "put" | "delete" | "patch" | "options";
|
46
|
+
path: string;
|
47
|
+
description?: string;
|
48
|
+
}
|
49
|
+
interface PageMetadata extends PageOptions {
|
50
|
+
name: string;
|
51
|
+
}
|
42
52
|
interface ActionMetadata extends ActionOptions {
|
43
53
|
name: string;
|
44
54
|
idempotence: boolean;
|
@@ -155,6 +165,32 @@ interface MicroserviceOptions {
|
|
155
165
|
};
|
156
166
|
cacheAdapter?: CacheAdapter;
|
157
167
|
plugins?: Plugin[];
|
168
|
+
gracefulShutdown?: {
|
169
|
+
/** 优雅停机超时时间(毫秒),默认 30 秒 */
|
170
|
+
timeout?: number;
|
171
|
+
/** 清理hook列表 */
|
172
|
+
cleanupHooks?: CleanupHook[];
|
173
|
+
};
|
174
|
+
}
|
175
|
+
interface CleanupHook {
|
176
|
+
/** hook名称 */
|
177
|
+
name: string;
|
178
|
+
/** 清理函数 */
|
179
|
+
cleanup: () => Promise<void> | void;
|
180
|
+
/** 超时时间(毫秒),默认 5 秒 */
|
181
|
+
timeout?: number;
|
182
|
+
}
|
183
|
+
interface RequestInfo {
|
184
|
+
/** 请求ID */
|
185
|
+
id: string;
|
186
|
+
/** 模块名称 */
|
187
|
+
moduleName: string;
|
188
|
+
/** 动作名称 */
|
189
|
+
actionName: string;
|
190
|
+
/** 开始时间 */
|
191
|
+
startTime: number;
|
192
|
+
/** 请求参数 */
|
193
|
+
params?: any;
|
158
194
|
}
|
159
195
|
interface ModuleInfo extends ModuleOptions {
|
160
196
|
actions: Record<string, ActionMetadata>;
|
@@ -197,10 +233,12 @@ declare class Microservice {
|
|
197
233
|
private lease?;
|
198
234
|
private scheduler?;
|
199
235
|
private abortController?;
|
200
|
-
private isShuttingDown;
|
201
236
|
private statisticsTimer?;
|
202
237
|
private wsHandler?;
|
203
238
|
private actionHandlers;
|
239
|
+
private pageHandlers;
|
240
|
+
private activeRequests;
|
241
|
+
private status;
|
204
242
|
modules: Map<string, ModuleInfo>;
|
205
243
|
readonly fetch: typeof fetch;
|
206
244
|
options: Required<MicroserviceOptions>;
|
@@ -236,7 +274,7 @@ declare class Microservice {
|
|
236
274
|
/**
|
237
275
|
* 停止服务
|
238
276
|
*/
|
239
|
-
stop
|
277
|
+
private stop;
|
240
278
|
/**
|
241
279
|
* 初始化停机处理
|
242
280
|
*/
|
@@ -244,22 +282,39 @@ declare class Microservice {
|
|
244
282
|
/**
|
245
283
|
* 优雅停机
|
246
284
|
*/
|
247
|
-
|
285
|
+
shutdown(): Promise<void>;
|
286
|
+
/**
|
287
|
+
* 等待所有活跃请求完成
|
288
|
+
*/
|
289
|
+
private waitForActiveRequests;
|
290
|
+
/**
|
291
|
+
* 执行清理hook
|
292
|
+
*/
|
293
|
+
private executeCleanupHooks;
|
248
294
|
private initStatsEventManager;
|
249
295
|
private updateStats;
|
250
296
|
getActionHandler(moduleName: string, actionName: string): ActionHandler;
|
297
|
+
/**
|
298
|
+
* 添加活跃请求跟踪
|
299
|
+
*/
|
300
|
+
private addActiveRequest;
|
301
|
+
/**
|
302
|
+
* 移除活跃请求跟踪
|
303
|
+
*/
|
304
|
+
private removeActiveRequest;
|
305
|
+
/**
|
306
|
+
* 获取当前活跃请求数量
|
307
|
+
*/
|
308
|
+
getActiveRequestCount(): number;
|
309
|
+
/**
|
310
|
+
* 获取当前活跃请求信息
|
311
|
+
*/
|
312
|
+
getActiveRequests(): RequestInfo[];
|
251
313
|
private handleRequest;
|
252
314
|
private initPlugins;
|
253
315
|
init(): Promise<void>;
|
254
316
|
}
|
255
317
|
|
256
|
-
interface PreStartChecker {
|
257
|
-
name: string;
|
258
|
-
check: () => Promise<void> | void;
|
259
|
-
skip?: boolean;
|
260
|
-
}
|
261
|
-
declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
|
262
|
-
|
263
318
|
declare class ModelContextProtocolPlugin extends Plugin {
|
264
319
|
private mcpServer;
|
265
320
|
private transports;
|
@@ -267,6 +322,35 @@ declare class ModelContextProtocolPlugin extends Plugin {
|
|
267
322
|
initialize: (engine: Microservice) => Promise<void>;
|
268
323
|
}
|
269
324
|
|
325
|
+
declare const BaseLayout: (props?: {
|
326
|
+
children?: any;
|
327
|
+
title?: string;
|
328
|
+
heads?: any;
|
329
|
+
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
330
|
+
declare const HtmxLayout: (props?: {
|
331
|
+
children?: any;
|
332
|
+
title: string;
|
333
|
+
favicon?: any;
|
334
|
+
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
335
|
+
|
336
|
+
declare const ServiceInfoCards: ({ serviceInfo, }: {
|
337
|
+
serviceInfo: ServiceInfo;
|
338
|
+
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
339
|
+
declare const ServiceStatusPage: ({ serviceInfo, }: {
|
340
|
+
serviceInfo: ServiceInfo;
|
341
|
+
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
342
|
+
|
343
|
+
declare class PageRenderPlugin extends Plugin {
|
344
|
+
initialize: (engine: Microservice) => Promise<void>;
|
345
|
+
}
|
346
|
+
|
347
|
+
interface PreStartChecker {
|
348
|
+
name: string;
|
349
|
+
check: () => Promise<void> | void;
|
350
|
+
skip?: boolean;
|
351
|
+
}
|
352
|
+
declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
|
353
|
+
|
270
354
|
/**
|
271
355
|
* 用于给微服务模块方法添加的注解
|
272
356
|
*/
|
@@ -279,6 +363,11 @@ declare function Action(options: ActionOptions): Function;
|
|
279
363
|
*/
|
280
364
|
declare function Module(name: string, options?: ModuleOptions): Function;
|
281
365
|
|
366
|
+
/**
|
367
|
+
* 用于给微服务模块方法添加的页面注解
|
368
|
+
*/
|
369
|
+
declare function Page(options: PageOptions): Function;
|
370
|
+
|
282
371
|
/**
|
283
372
|
* 用于给微服务模块方法添加的调度注解
|
284
373
|
*/
|
@@ -286,4 +375,4 @@ declare function Schedule(options: ScheduleOptions): Function;
|
|
286
375
|
|
287
376
|
declare const logger: winston.Logger;
|
288
377
|
|
289
|
-
export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, CacheAdapter, type CacheFn, type EtcdConfig, type EventServiceInfo, type McpOptions, MemoryCacheAdapter, Microservice, type MicroserviceOptions, ModelContextProtocolPlugin, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, Plugin, type PreStartChecker, RedisCacheAdapter, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, type ServiceStats, type StatisticsEvent, type StreamResponse, logger, startCheck };
|
378
|
+
export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, BaseLayout, CacheAdapter, type CacheFn, type CleanupHook, type EtcdConfig, type EventServiceInfo, HtmxLayout, type McpOptions, MemoryCacheAdapter, Microservice, type MicroserviceOptions, ModelContextProtocolPlugin, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, Page, type PageMetadata, type PageOptions, PageRenderPlugin, Plugin, type PreStartChecker, RedisCacheAdapter, type RequestInfo, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, ServiceInfoCards, type ServiceStats, ServiceStatusPage, type StatisticsEvent, type StreamResponse, logger, startCheck };
|
package/dist/mod.d.ts
CHANGED
@@ -6,6 +6,8 @@ import { Lease, Etcd3 } from 'etcd3';
|
|
6
6
|
import { Hono } from 'hono';
|
7
7
|
export { default as dayjs } from 'dayjs';
|
8
8
|
import winston from 'winston';
|
9
|
+
import * as hono_utils_html from 'hono/utils/html';
|
10
|
+
import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
|
9
11
|
|
10
12
|
declare abstract class CacheAdapter {
|
11
13
|
abstract get(key: string): Promise<any>;
|
@@ -39,6 +41,14 @@ interface ActionOptions {
|
|
39
41
|
stream?: boolean;
|
40
42
|
mcp?: McpOptions;
|
41
43
|
}
|
44
|
+
interface PageOptions {
|
45
|
+
method: "get" | "post" | "put" | "delete" | "patch" | "options";
|
46
|
+
path: string;
|
47
|
+
description?: string;
|
48
|
+
}
|
49
|
+
interface PageMetadata extends PageOptions {
|
50
|
+
name: string;
|
51
|
+
}
|
42
52
|
interface ActionMetadata extends ActionOptions {
|
43
53
|
name: string;
|
44
54
|
idempotence: boolean;
|
@@ -155,6 +165,32 @@ interface MicroserviceOptions {
|
|
155
165
|
};
|
156
166
|
cacheAdapter?: CacheAdapter;
|
157
167
|
plugins?: Plugin[];
|
168
|
+
gracefulShutdown?: {
|
169
|
+
/** 优雅停机超时时间(毫秒),默认 30 秒 */
|
170
|
+
timeout?: number;
|
171
|
+
/** 清理hook列表 */
|
172
|
+
cleanupHooks?: CleanupHook[];
|
173
|
+
};
|
174
|
+
}
|
175
|
+
interface CleanupHook {
|
176
|
+
/** hook名称 */
|
177
|
+
name: string;
|
178
|
+
/** 清理函数 */
|
179
|
+
cleanup: () => Promise<void> | void;
|
180
|
+
/** 超时时间(毫秒),默认 5 秒 */
|
181
|
+
timeout?: number;
|
182
|
+
}
|
183
|
+
interface RequestInfo {
|
184
|
+
/** 请求ID */
|
185
|
+
id: string;
|
186
|
+
/** 模块名称 */
|
187
|
+
moduleName: string;
|
188
|
+
/** 动作名称 */
|
189
|
+
actionName: string;
|
190
|
+
/** 开始时间 */
|
191
|
+
startTime: number;
|
192
|
+
/** 请求参数 */
|
193
|
+
params?: any;
|
158
194
|
}
|
159
195
|
interface ModuleInfo extends ModuleOptions {
|
160
196
|
actions: Record<string, ActionMetadata>;
|
@@ -197,10 +233,12 @@ declare class Microservice {
|
|
197
233
|
private lease?;
|
198
234
|
private scheduler?;
|
199
235
|
private abortController?;
|
200
|
-
private isShuttingDown;
|
201
236
|
private statisticsTimer?;
|
202
237
|
private wsHandler?;
|
203
238
|
private actionHandlers;
|
239
|
+
private pageHandlers;
|
240
|
+
private activeRequests;
|
241
|
+
private status;
|
204
242
|
modules: Map<string, ModuleInfo>;
|
205
243
|
readonly fetch: typeof fetch;
|
206
244
|
options: Required<MicroserviceOptions>;
|
@@ -236,7 +274,7 @@ declare class Microservice {
|
|
236
274
|
/**
|
237
275
|
* 停止服务
|
238
276
|
*/
|
239
|
-
stop
|
277
|
+
private stop;
|
240
278
|
/**
|
241
279
|
* 初始化停机处理
|
242
280
|
*/
|
@@ -244,22 +282,39 @@ declare class Microservice {
|
|
244
282
|
/**
|
245
283
|
* 优雅停机
|
246
284
|
*/
|
247
|
-
|
285
|
+
shutdown(): Promise<void>;
|
286
|
+
/**
|
287
|
+
* 等待所有活跃请求完成
|
288
|
+
*/
|
289
|
+
private waitForActiveRequests;
|
290
|
+
/**
|
291
|
+
* 执行清理hook
|
292
|
+
*/
|
293
|
+
private executeCleanupHooks;
|
248
294
|
private initStatsEventManager;
|
249
295
|
private updateStats;
|
250
296
|
getActionHandler(moduleName: string, actionName: string): ActionHandler;
|
297
|
+
/**
|
298
|
+
* 添加活跃请求跟踪
|
299
|
+
*/
|
300
|
+
private addActiveRequest;
|
301
|
+
/**
|
302
|
+
* 移除活跃请求跟踪
|
303
|
+
*/
|
304
|
+
private removeActiveRequest;
|
305
|
+
/**
|
306
|
+
* 获取当前活跃请求数量
|
307
|
+
*/
|
308
|
+
getActiveRequestCount(): number;
|
309
|
+
/**
|
310
|
+
* 获取当前活跃请求信息
|
311
|
+
*/
|
312
|
+
getActiveRequests(): RequestInfo[];
|
251
313
|
private handleRequest;
|
252
314
|
private initPlugins;
|
253
315
|
init(): Promise<void>;
|
254
316
|
}
|
255
317
|
|
256
|
-
interface PreStartChecker {
|
257
|
-
name: string;
|
258
|
-
check: () => Promise<void> | void;
|
259
|
-
skip?: boolean;
|
260
|
-
}
|
261
|
-
declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
|
262
|
-
|
263
318
|
declare class ModelContextProtocolPlugin extends Plugin {
|
264
319
|
private mcpServer;
|
265
320
|
private transports;
|
@@ -267,6 +322,35 @@ declare class ModelContextProtocolPlugin extends Plugin {
|
|
267
322
|
initialize: (engine: Microservice) => Promise<void>;
|
268
323
|
}
|
269
324
|
|
325
|
+
declare const BaseLayout: (props?: {
|
326
|
+
children?: any;
|
327
|
+
title?: string;
|
328
|
+
heads?: any;
|
329
|
+
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
330
|
+
declare const HtmxLayout: (props?: {
|
331
|
+
children?: any;
|
332
|
+
title: string;
|
333
|
+
favicon?: any;
|
334
|
+
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
335
|
+
|
336
|
+
declare const ServiceInfoCards: ({ serviceInfo, }: {
|
337
|
+
serviceInfo: ServiceInfo;
|
338
|
+
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
339
|
+
declare const ServiceStatusPage: ({ serviceInfo, }: {
|
340
|
+
serviceInfo: ServiceInfo;
|
341
|
+
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
342
|
+
|
343
|
+
declare class PageRenderPlugin extends Plugin {
|
344
|
+
initialize: (engine: Microservice) => Promise<void>;
|
345
|
+
}
|
346
|
+
|
347
|
+
interface PreStartChecker {
|
348
|
+
name: string;
|
349
|
+
check: () => Promise<void> | void;
|
350
|
+
skip?: boolean;
|
351
|
+
}
|
352
|
+
declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
|
353
|
+
|
270
354
|
/**
|
271
355
|
* 用于给微服务模块方法添加的注解
|
272
356
|
*/
|
@@ -279,6 +363,11 @@ declare function Action(options: ActionOptions): Function;
|
|
279
363
|
*/
|
280
364
|
declare function Module(name: string, options?: ModuleOptions): Function;
|
281
365
|
|
366
|
+
/**
|
367
|
+
* 用于给微服务模块方法添加的页面注解
|
368
|
+
*/
|
369
|
+
declare function Page(options: PageOptions): Function;
|
370
|
+
|
282
371
|
/**
|
283
372
|
* 用于给微服务模块方法添加的调度注解
|
284
373
|
*/
|
@@ -286,4 +375,4 @@ declare function Schedule(options: ScheduleOptions): Function;
|
|
286
375
|
|
287
376
|
declare const logger: winston.Logger;
|
288
377
|
|
289
|
-
export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, CacheAdapter, type CacheFn, type EtcdConfig, type EventServiceInfo, type McpOptions, MemoryCacheAdapter, Microservice, type MicroserviceOptions, ModelContextProtocolPlugin, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, Plugin, type PreStartChecker, RedisCacheAdapter, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, type ServiceStats, type StatisticsEvent, type StreamResponse, logger, startCheck };
|
378
|
+
export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, BaseLayout, CacheAdapter, type CacheFn, type CleanupHook, type EtcdConfig, type EventServiceInfo, HtmxLayout, type McpOptions, MemoryCacheAdapter, Microservice, type MicroserviceOptions, ModelContextProtocolPlugin, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, Page, type PageMetadata, type PageOptions, PageRenderPlugin, Plugin, type PreStartChecker, RedisCacheAdapter, type RequestInfo, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, ServiceInfoCards, type ServiceStats, ServiceStatusPage, type StatisticsEvent, type StreamResponse, logger, startCheck };
|