imean-service-engine 1.7.0 → 1.7.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/mod.cjs +41 -20
- package/dist/mod.d.cts +8 -2
- package/dist/mod.d.ts +8 -2
- package/dist/mod.js +41 -20
- package/package.json +1 -1
package/dist/mod.cjs
CHANGED
@@ -611,12 +611,21 @@ function Page(options) {
|
|
611
611
|
name: methodName,
|
612
612
|
description: options.description || "",
|
613
613
|
method: options.method,
|
614
|
-
path: options.path
|
614
|
+
path: normalizePath(options.path),
|
615
|
+
absolutePath: options.absolutePath ?? false
|
615
616
|
};
|
616
617
|
prototype[PAGE_METADATA] = existingMetadata;
|
617
618
|
});
|
618
619
|
};
|
619
620
|
}
|
621
|
+
function normalizePath(path) {
|
622
|
+
if (Array.isArray(path)) {
|
623
|
+
return path.map((p) => normalizePath(p));
|
624
|
+
}
|
625
|
+
if (!path.startsWith("/")) path = "/" + path;
|
626
|
+
if (path === "/") return "";
|
627
|
+
return path;
|
628
|
+
}
|
620
629
|
function getPageMetadata(target) {
|
621
630
|
return target.constructor.prototype[PAGE_METADATA] ?? {};
|
622
631
|
}
|
@@ -930,10 +939,14 @@ var Microservice = class {
|
|
930
939
|
moduleName
|
931
940
|
);
|
932
941
|
this.pageHandlers.set(`${moduleName}.${page.name}`, handler);
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
942
|
+
const paths = Array.isArray(page.path) ? page.path : [page.path];
|
943
|
+
for (let path of paths) {
|
944
|
+
path = page.absolutePath ? path : `${this.options.prefix}${path}`;
|
945
|
+
this.app[page.method](path, (ctx) => handler.handle(ctx));
|
946
|
+
logger_default.info(
|
947
|
+
`[ \u6CE8\u518C\u9875\u9762 ] ${moduleName}.${page.name} ${page.method.toUpperCase()} ${page.path} ${page.description}`
|
948
|
+
);
|
949
|
+
}
|
937
950
|
}
|
938
951
|
const schedules = getScheduleMetadata(ModuleClass.prototype);
|
939
952
|
if (schedules && Object.keys(schedules).length > 0) {
|
@@ -1672,23 +1685,31 @@ var ServiceStatusPage_default = ServiceStatusPage;
|
|
1672
1685
|
|
1673
1686
|
// core/plugins/page/mod.ts
|
1674
1687
|
var PageRenderPlugin = class extends Plugin {
|
1688
|
+
constructor(options = {
|
1689
|
+
useDefaultStatusPage: true
|
1690
|
+
}) {
|
1691
|
+
super();
|
1692
|
+
this.options = options;
|
1693
|
+
}
|
1675
1694
|
initialize = async (engine) => {
|
1676
1695
|
const app = engine.getApp();
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1696
|
+
if (this.options.useDefaultStatusPage) {
|
1697
|
+
app.get(`${engine.options.prefix}`, async (ctx) => {
|
1698
|
+
return ctx.html(HtmxLayout({
|
1699
|
+
title: engine.options.name,
|
1700
|
+
children: ServiceStatusPage_default({
|
1701
|
+
serviceInfo: {
|
1702
|
+
name: engine.options.name,
|
1703
|
+
prefix: engine.options.prefix,
|
1704
|
+
version: engine.options.version,
|
1705
|
+
env: engine.options.env,
|
1706
|
+
id: engine.serviceId,
|
1707
|
+
modules: engine.getModules(false)
|
1708
|
+
}
|
1709
|
+
})
|
1710
|
+
}));
|
1711
|
+
});
|
1712
|
+
}
|
1692
1713
|
logger_default.info(`PageRenderPlugin enabled`);
|
1693
1714
|
};
|
1694
1715
|
};
|
package/dist/mod.d.cts
CHANGED
@@ -43,7 +43,8 @@ interface ActionOptions {
|
|
43
43
|
}
|
44
44
|
interface PageOptions {
|
45
45
|
method: "get" | "post" | "put" | "delete" | "patch" | "options";
|
46
|
-
path: string;
|
46
|
+
path: string | string[];
|
47
|
+
absolutePath?: boolean;
|
47
48
|
description?: string;
|
48
49
|
}
|
49
50
|
interface PageMetadata extends PageOptions {
|
@@ -340,7 +341,12 @@ declare const ServiceStatusPage: ({ serviceInfo, }: {
|
|
340
341
|
serviceInfo: ServiceInfo;
|
341
342
|
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
342
343
|
|
344
|
+
interface PageRenderPluginOptions {
|
345
|
+
useDefaultStatusPage?: boolean;
|
346
|
+
}
|
343
347
|
declare class PageRenderPlugin extends Plugin {
|
348
|
+
private readonly options;
|
349
|
+
constructor(options?: PageRenderPluginOptions);
|
344
350
|
initialize: (engine: Microservice) => Promise<void>;
|
345
351
|
}
|
346
352
|
|
@@ -375,4 +381,4 @@ declare function Schedule(options: ScheduleOptions): Function;
|
|
375
381
|
|
376
382
|
declare const logger: winston.Logger;
|
377
383
|
|
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 };
|
384
|
+
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, type PageRenderPluginOptions, 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
@@ -43,7 +43,8 @@ interface ActionOptions {
|
|
43
43
|
}
|
44
44
|
interface PageOptions {
|
45
45
|
method: "get" | "post" | "put" | "delete" | "patch" | "options";
|
46
|
-
path: string;
|
46
|
+
path: string | string[];
|
47
|
+
absolutePath?: boolean;
|
47
48
|
description?: string;
|
48
49
|
}
|
49
50
|
interface PageMetadata extends PageOptions {
|
@@ -340,7 +341,12 @@ declare const ServiceStatusPage: ({ serviceInfo, }: {
|
|
340
341
|
serviceInfo: ServiceInfo;
|
341
342
|
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
342
343
|
|
344
|
+
interface PageRenderPluginOptions {
|
345
|
+
useDefaultStatusPage?: boolean;
|
346
|
+
}
|
343
347
|
declare class PageRenderPlugin extends Plugin {
|
348
|
+
private readonly options;
|
349
|
+
constructor(options?: PageRenderPluginOptions);
|
344
350
|
initialize: (engine: Microservice) => Promise<void>;
|
345
351
|
}
|
346
352
|
|
@@ -375,4 +381,4 @@ declare function Schedule(options: ScheduleOptions): Function;
|
|
375
381
|
|
376
382
|
declare const logger: winston.Logger;
|
377
383
|
|
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 };
|
384
|
+
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, type PageRenderPluginOptions, 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.js
CHANGED
@@ -602,12 +602,21 @@ function Page(options) {
|
|
602
602
|
name: methodName,
|
603
603
|
description: options.description || "",
|
604
604
|
method: options.method,
|
605
|
-
path: options.path
|
605
|
+
path: normalizePath(options.path),
|
606
|
+
absolutePath: options.absolutePath ?? false
|
606
607
|
};
|
607
608
|
prototype[PAGE_METADATA] = existingMetadata;
|
608
609
|
});
|
609
610
|
};
|
610
611
|
}
|
612
|
+
function normalizePath(path) {
|
613
|
+
if (Array.isArray(path)) {
|
614
|
+
return path.map((p) => normalizePath(p));
|
615
|
+
}
|
616
|
+
if (!path.startsWith("/")) path = "/" + path;
|
617
|
+
if (path === "/") return "";
|
618
|
+
return path;
|
619
|
+
}
|
611
620
|
function getPageMetadata(target) {
|
612
621
|
return target.constructor.prototype[PAGE_METADATA] ?? {};
|
613
622
|
}
|
@@ -921,10 +930,14 @@ var Microservice = class {
|
|
921
930
|
moduleName
|
922
931
|
);
|
923
932
|
this.pageHandlers.set(`${moduleName}.${page.name}`, handler);
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
933
|
+
const paths = Array.isArray(page.path) ? page.path : [page.path];
|
934
|
+
for (let path of paths) {
|
935
|
+
path = page.absolutePath ? path : `${this.options.prefix}${path}`;
|
936
|
+
this.app[page.method](path, (ctx) => handler.handle(ctx));
|
937
|
+
logger_default.info(
|
938
|
+
`[ \u6CE8\u518C\u9875\u9762 ] ${moduleName}.${page.name} ${page.method.toUpperCase()} ${page.path} ${page.description}`
|
939
|
+
);
|
940
|
+
}
|
928
941
|
}
|
929
942
|
const schedules = getScheduleMetadata(ModuleClass.prototype);
|
930
943
|
if (schedules && Object.keys(schedules).length > 0) {
|
@@ -1663,23 +1676,31 @@ var ServiceStatusPage_default = ServiceStatusPage;
|
|
1663
1676
|
|
1664
1677
|
// core/plugins/page/mod.ts
|
1665
1678
|
var PageRenderPlugin = class extends Plugin {
|
1679
|
+
constructor(options = {
|
1680
|
+
useDefaultStatusPage: true
|
1681
|
+
}) {
|
1682
|
+
super();
|
1683
|
+
this.options = options;
|
1684
|
+
}
|
1666
1685
|
initialize = async (engine) => {
|
1667
1686
|
const app = engine.getApp();
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1687
|
+
if (this.options.useDefaultStatusPage) {
|
1688
|
+
app.get(`${engine.options.prefix}`, async (ctx) => {
|
1689
|
+
return ctx.html(HtmxLayout({
|
1690
|
+
title: engine.options.name,
|
1691
|
+
children: ServiceStatusPage_default({
|
1692
|
+
serviceInfo: {
|
1693
|
+
name: engine.options.name,
|
1694
|
+
prefix: engine.options.prefix,
|
1695
|
+
version: engine.options.version,
|
1696
|
+
env: engine.options.env,
|
1697
|
+
id: engine.serviceId,
|
1698
|
+
modules: engine.getModules(false)
|
1699
|
+
}
|
1700
|
+
})
|
1701
|
+
}));
|
1702
|
+
});
|
1703
|
+
}
|
1683
1704
|
logger_default.info(`PageRenderPlugin enabled`);
|
1684
1705
|
};
|
1685
1706
|
};
|