@arch-cadre/modules 0.0.62 → 0.0.64

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.
Files changed (52) hide show
  1. package/dist/client/extension-point-client.d.ts +8 -17
  2. package/dist/client/extension-point-client.d.ts.map +1 -1
  3. package/dist/client/extension-point-client.js +19 -0
  4. package/dist/client/extension-point.d.ts +8 -19
  5. package/dist/client/extension-point.d.ts.map +1 -1
  6. package/dist/client/extension-point.js +12 -0
  7. package/dist/client/index.d.ts +4 -0
  8. package/dist/client/index.d.ts.map +1 -0
  9. package/dist/client/index.js +3 -0
  10. package/dist/client/widget-area.d.ts +7 -16
  11. package/dist/client/widget-area.d.ts.map +1 -1
  12. package/dist/client/widget-area.js +12 -0
  13. package/dist/index.d.ts +5 -5
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +6 -0
  16. package/dist/server/lifecycle.d.ts +5 -8
  17. package/dist/server/lifecycle.d.ts.map +1 -1
  18. package/dist/server/lifecycle.js +250 -0
  19. package/dist/server/manage.d.ts +25 -29
  20. package/dist/server/manage.d.ts.map +1 -1
  21. package/dist/server/manage.js +143 -0
  22. package/dist/server/registry.d.ts +2 -5
  23. package/dist/server/registry.d.ts.map +1 -1
  24. package/dist/server/registry.js +118 -0
  25. package/dist/server/ui.d.ts +13 -17
  26. package/dist/server/ui.d.ts.map +1 -1
  27. package/dist/server/ui.js +235 -0
  28. package/dist/server.d.ts +6 -6
  29. package/dist/server.d.ts.map +1 -0
  30. package/dist/server.js +8 -0
  31. package/dist/types.d.ts +91 -94
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/types.js +13 -0
  34. package/package.json +17 -13
  35. package/dist/client/extension-point-client.mjs +0 -2
  36. package/dist/client/extension-point-client.mjs.map +0 -1
  37. package/dist/client/extension-point.mjs +0 -2
  38. package/dist/client/extension-point.mjs.map +0 -1
  39. package/dist/client/widget-area.mjs +0 -2
  40. package/dist/client/widget-area.mjs.map +0 -1
  41. package/dist/index.mjs +0 -1
  42. package/dist/server/lifecycle.mjs +0 -2
  43. package/dist/server/lifecycle.mjs.map +0 -1
  44. package/dist/server/manage.mjs +0 -2
  45. package/dist/server/manage.mjs.map +0 -1
  46. package/dist/server/registry.mjs +0 -2
  47. package/dist/server/registry.mjs.map +0 -1
  48. package/dist/server/ui.mjs +0 -2
  49. package/dist/server/ui.mjs.map +0 -1
  50. package/dist/server.mjs +0 -1
  51. package/dist/types.mjs +0 -2
  52. package/dist/types.mjs.map +0 -1
@@ -1,20 +1,11 @@
1
1
  import * as React from "react";
2
-
3
- //#region src/client/extension-point-client.d.ts
4
2
  interface ExtensionPointProps {
5
- module: string;
6
- point: string;
7
- className?: string;
8
- props?: any;
9
- fallback?: React.ReactNode;
3
+ module: string;
4
+ point: string;
5
+ className?: string;
6
+ props?: any;
7
+ fallback?: React.ReactNode;
10
8
  }
11
- declare function ExtensionPointClient({
12
- module,
13
- point,
14
- className,
15
- props,
16
- fallback
17
- }: ExtensionPointProps): any;
18
- //#endregion
19
- export { ExtensionPointClient };
20
- //# sourceMappingURL=extension-point-client.d.mts.map
9
+ export declare function ExtensionPointClient({ module, point, className, props, fallback, }: ExtensionPointProps): any;
10
+ export {};
11
+ //# sourceMappingURL=extension-point-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extension-point-client.d.mts","names":[],"sources":["../../src/client/extension-point-client.tsx"],"mappings":";;;UAOU,mBAAA;EACR,MAAA;EACA,KAAA;EACA,SAAA;EACA,KAAA;EACA,QAAA,GAAW,KAAA,CAAM,SAAA;AAAA;AAAA,iBAGH,oBAAA,CAAA;EACd,MAAA;EACA,KAAA;EACA,SAAA;EACA,KAAA;EACA;AAAA,GACC,mBAAA"}
1
+ {"version":3,"file":"extension-point-client.d.ts","sourceRoot":"","sources":["../../src/client/extension-point-client.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,oBAAoB,CAAC,EACnC,MAAM,EACN,KAAK,EACL,SAAS,EACT,KAAK,EACL,QAAQ,GACT,EAAE,mBAAmB,OAkBrB"}
@@ -0,0 +1,19 @@
1
+ /** biome-ignore-all lint/suspicious/noExplicitAny: <> */
2
+ "use client";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ import { useEffect, useState } from "react";
5
+ import { getExtensions } from "../server/ui";
6
+ export function ExtensionPointClient({ module, point, className, props, fallback, }) {
7
+ const [extensions, setExtensions] = useState([]);
8
+ useEffect(() => {
9
+ getExtensions(module, point).then(setExtensions);
10
+ }, [module, point]);
11
+ if (extensions.length === 0)
12
+ return fallback || null;
13
+ return (_jsx("div", { className: className, children: extensions.map((ext) => {
14
+ const Component = ext.component;
15
+ if (!Component)
16
+ return null;
17
+ return _jsx(Component, { ...props }, ext.id);
18
+ }) }));
19
+ }
@@ -1,21 +1,10 @@
1
- import * as react_jsx_runtime0 from "react/jsx-runtime";
2
- import * as react from "react";
3
-
4
- //#region src/client/extension-point.d.ts
5
1
  interface ExtensionPointProps {
6
- module: string;
7
- point: string;
8
- className?: string;
9
- props?: any;
10
- fallback?: React.ReactNode;
2
+ module: string;
3
+ point: string;
4
+ className?: string;
5
+ props?: any;
6
+ fallback?: React.ReactNode;
11
7
  }
12
- declare function ExtensionPoint({
13
- module,
14
- point,
15
- className,
16
- props,
17
- fallback
18
- }: ExtensionPointProps): Promise<string | number | bigint | boolean | Iterable<react.ReactNode> | react_jsx_runtime0.JSX.Element | null | undefined>;
19
- //#endregion
20
- export { ExtensionPoint };
21
- //# sourceMappingURL=extension-point.d.mts.map
8
+ export declare function ExtensionPoint({ module, point, className, props, fallback, }: ExtensionPointProps): Promise<string | number | bigint | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined>;
9
+ export {};
10
+ //# sourceMappingURL=extension-point.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extension-point.d.mts","names":[],"sources":["../../src/client/extension-point.tsx"],"mappings":";;;;UAGU,mBAAA;EACR,MAAA;EACA,KAAA;EACA,SAAA;EACA,KAAA;EACA,QAAA,GAAW,KAAA,CAAM,SAAA;AAAA;AAAA,iBAGG,cAAA,CAAA;EACpB,MAAA;EACA,KAAA;EACA,SAAA;EACA,KAAA;EACA;AAAA,GACC,mBAAA,GAAmB,OAAA,sCAAA,QAAA,CAAA,KAAA,CAAA,SAAA,IAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"extension-point.d.ts","sourceRoot":"","sources":["../../src/client/extension-point.tsx"],"names":[],"mappings":"AAGA,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAsB,cAAc,CAAC,EACnC,MAAM,EACN,KAAK,EACL,SAAS,EACT,KAAK,EACL,QAAQ,GACT,EAAE,mBAAmB,kJAarB"}
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // import * as React from "react";
3
+ import { getExtensions } from "../server/ui";
4
+ export async function ExtensionPoint({ module, point, className, props, fallback, }) {
5
+ const extensions = await getExtensions(module, point);
6
+ if (extensions.length === 0)
7
+ return fallback || null;
8
+ return (_jsx("div", { className: className, children: extensions.map((ext) => {
9
+ const Component = ext.component;
10
+ return _jsx(Component, { ...props }, ext.id);
11
+ }) }));
12
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./extension-point";
2
+ export * from "./extension-point-client";
3
+ export * from "./widget-area";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./extension-point";
2
+ export * from "./extension-point-client";
3
+ export * from "./widget-area";
@@ -1,19 +1,10 @@
1
- import * as react_jsx_runtime0 from "react/jsx-runtime";
2
1
  import * as React from "react";
3
-
4
- //#region src/client/widget-area.d.ts
5
2
  interface WidgetAreaProps {
6
- area: string;
7
- className?: string;
8
- fallback?: React.ReactNode;
9
- props?: any;
3
+ area: string;
4
+ className?: string;
5
+ fallback?: React.ReactNode;
6
+ props?: any;
10
7
  }
11
- declare function WidgetArea({
12
- area,
13
- className,
14
- fallback,
15
- props
16
- }: WidgetAreaProps): Promise<string | number | bigint | boolean | Iterable<React.ReactNode> | react_jsx_runtime0.JSX.Element | null | undefined>;
17
- //#endregion
18
- export { WidgetArea };
19
- //# sourceMappingURL=widget-area.d.mts.map
8
+ export declare function WidgetArea({ area, className, fallback, props, }: WidgetAreaProps): Promise<string | number | bigint | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined>;
9
+ export {};
10
+ //# sourceMappingURL=widget-area.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"widget-area.d.mts","names":[],"sources":["../../src/client/widget-area.tsx"],"mappings":";;;;UAIU,eAAA;EACR,IAAA;EACA,SAAA;EACA,QAAA,GAAW,KAAA,CAAM,SAAA;EAEjB,KAAA;AAAA;AAAA,iBAGoB,UAAA,CAAA;EACpB,IAAA;EACA,SAAA;EACA,QAAA;EACA;AAAA,GACC,eAAA,GAAe,OAAA,sCAAA,QAAA,CAAA,KAAA,CAAA,SAAA,IAAA,kBAAA,CAAA,GAAA,CAAA,OAAA"}
1
+ {"version":3,"file":"widget-area.d.ts","sourceRoot":"","sources":["../../src/client/widget-area.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE3B,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,wBAAsB,UAAU,CAAC,EAC/B,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,KAAK,GACN,EAAE,eAAe,wIAejB"}
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { getModuleWidgets } from "../server/ui";
3
+ export async function WidgetArea({ area, className, fallback, props, }) {
4
+ const widgets = await getModuleWidgets(area);
5
+ if (widgets.length === 0) {
6
+ return fallback || null;
7
+ }
8
+ return (_jsx("div", { className: className, children: widgets.map((widget) => {
9
+ const Component = widget.component;
10
+ return _jsx(Component, { ...props }, widget.id);
11
+ }) }));
12
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ExtensionPoint } from "./client/extension-point.mjs";
2
- import { ExtensionPointClient } from "./client/extension-point-client.mjs";
3
- import { WidgetArea } from "./client/widget-area.mjs";
4
- import { ApiRouteDefinition, IModule, ModuleExtension, ModuleManifest, ModuleManifestSchema, ModuleNavElement, ModuleNavigation, ModuleNavigationGroupMap, ModulePageProps, ModuleRouteDefinition, ModuleWidget, PrivateRouteDefinition, PublicRouteDefinition, SidebarGroupType, SidebarMenuItemType, SidebarMenuType, SystemEvent } from "./types.mjs";
5
- export { ApiRouteDefinition, ExtensionPoint, ExtensionPointClient, IModule, ModuleExtension, ModuleManifest, ModuleManifestSchema, ModuleNavElement, ModuleNavigation, ModuleNavigationGroupMap, ModulePageProps, ModuleRouteDefinition, ModuleWidget, PrivateRouteDefinition, PublicRouteDefinition, SidebarGroupType, SidebarMenuItemType, SidebarMenuType, SystemEvent, WidgetArea };
1
+ export { ExtensionPoint } from "./client/extension-point";
2
+ export { ExtensionPointClient } from "./client/extension-point-client";
3
+ export { WidgetArea } from "./client/widget-area";
4
+ export * from "./types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { ExtensionPoint } from "./client/extension-point";
2
+ export { ExtensionPointClient } from "./client/extension-point-client";
3
+ export { WidgetArea } from "./client/widget-area";
4
+ // Shared Constants & Models (Safe for Browser)
5
+ // export * from "./server/ui";
6
+ export * from "./types";
@@ -1,9 +1,6 @@
1
- //#region src/server/lifecycle.d.ts
2
- declare function pushModuleSchema(moduleId: string): Promise<void>;
3
- declare function toggleModuleState(moduleId: string, isEnabled: boolean): Promise<{
4
- success: boolean;
1
+ export declare function pushModuleSchema(moduleId: string): Promise<void>;
2
+ export declare function toggleModuleState(moduleId: string, isEnabled: boolean): Promise<{
3
+ success: boolean;
5
4
  }>;
6
- declare function initOperationalModules(): Promise<void>;
7
- //#endregion
8
- export { initOperationalModules, pushModuleSchema, toggleModuleState };
9
- //# sourceMappingURL=lifecycle.d.mts.map
5
+ export declare function initOperationalModules(): Promise<void>;
6
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.d.mts","names":[],"sources":["../../src/server/lifecycle.ts"],"mappings":";iBA4GsB,gBAAA,CAAiB,QAAA,WAAgB,OAAA;AAAA,iBAwLjC,iBAAA,CAAkB,QAAA,UAAkB,SAAA,YAAkB,OAAA;;;iBAWtD,sBAAA,CAAA,GAAsB,OAAA"}
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/server/lifecycle.ts"],"names":[],"mappings":"AA4GA,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,iBA6DtD;AA2HD,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO;;GAS3E;AAED,wBAAsB,sBAAsB,kBAc3C"}
@@ -0,0 +1,250 @@
1
+ "use server";
2
+ import { exec } from "node:child_process";
3
+ import fs from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { promisify } from "node:util";
6
+ import { systemModulesTable } from "@arch-cadre/core";
7
+ import { db } from "@arch-cadre/core/server";
8
+ import { eq } from "drizzle-orm";
9
+ import { getModuleInstance, getModules } from "./manage";
10
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
11
+ async function updateStep(moduleId, step) {
12
+ console.log(`[Kernel] "${moduleId}" step: ${step}`);
13
+ await db
14
+ .update(systemModulesTable)
15
+ .set({ lastStep: step })
16
+ .where(eq(systemModulesTable.id, moduleId));
17
+ }
18
+ async function resolveSchemaPath(moduleId) {
19
+ // const path = await import("node:path");
20
+ // const fs = await import("node:fs/promises");
21
+ const root = process.cwd();
22
+ // 1. Special case for core
23
+ if (moduleId === "@arch-cadre/core" || moduleId === "core") {
24
+ const p = path.join(root, "node_modules", "@kryo", "core", "dist", "server", "database", "schema.cjs");
25
+ try {
26
+ await fs.access(p);
27
+ return p;
28
+ }
29
+ catch {
30
+ // Monorepo dev fallback
31
+ const devP = path.resolve(root, "../../packages/kryo-core/src/server/database/schema.ts");
32
+ try {
33
+ await fs.access(devP);
34
+ return devP;
35
+ }
36
+ catch { }
37
+ }
38
+ return null;
39
+ }
40
+ // Normalize moduleId (remove @arch-cadre/ prefix if present for directory searching)
41
+ const cleanId = moduleId.replace("@arch-cadre/", "");
42
+ const possible = [
43
+ // Local module
44
+ path.join(root, "modules", cleanId, "schema.ts"),
45
+ path.join(root, "modules", moduleId, "schema.ts"),
46
+ // node_modules (installed or symlinked)
47
+ path.join(root, "node_modules", moduleId, "dist", "schema.cjs"),
48
+ path.join(root, "node_modules", `@arch-cadre/${cleanId}`, "dist", "schema.cjs"),
49
+ path.join(root, "node_modules", moduleId, "src", "schema.ts"),
50
+ path.join(root, "node_modules", `@arch-cadre/${cleanId}`, "src", "schema.ts"),
51
+ // Monorepo packages (searching by various naming conventions)
52
+ path.resolve(root, "../../packages", cleanId, "src", "schema.ts"),
53
+ path.resolve(root, "../../packages", `kryo-${cleanId}`, "src", "schema.ts"),
54
+ path.resolve(root, "../../packages", cleanId, "schema.ts"),
55
+ ];
56
+ for (const p of possible) {
57
+ try {
58
+ await fs.access(p);
59
+ console.log(`[Kernel:Lifecycle] Resolved schema for ${moduleId} at: ${p}`);
60
+ return p;
61
+ }
62
+ catch {
63
+ console.warn(`[Kernel:Lifecycle] Unresolved schema for ${moduleId} at: ${p}`);
64
+ }
65
+ }
66
+ console.warn(`[Kernel:Lifecycle] Could not resolve schema path for: ${moduleId}`);
67
+ return null;
68
+ }
69
+ export async function pushModuleSchema(moduleId) {
70
+ const execAsync = promisify(exec);
71
+ console.log(`[Kernel:Lifecycle] Targeted sync for module: ${moduleId}`);
72
+ const root = process.cwd();
73
+ // 1. Get all currently enabled modules to avoid dropping their tables
74
+ const enabledFromDb = await db
75
+ .select({ id: systemModulesTable.id })
76
+ .from(systemModulesTable)
77
+ .where(eq(systemModulesTable.enabled, true));
78
+ const activeModuleIds = new Set(enabledFromDb.map((m) => m.id));
79
+ activeModuleIds.add("@arch-cadre/core");
80
+ activeModuleIds.add(moduleId);
81
+ // 2. Resolve physical paths for all active schemas
82
+ const schemaPaths = [];
83
+ for (const id of Array.from(activeModuleIds)) {
84
+ const p = await resolveSchemaPath(id);
85
+ if (p)
86
+ schemaPaths.push(p);
87
+ }
88
+ if (schemaPaths.length === 0) {
89
+ console.warn(`[Kernel:Lifecycle] No schema paths resolved for ${moduleId}, skipping push.`);
90
+ return;
91
+ }
92
+ // 3. Prepare command
93
+ const configPath = path.join(root, "drizzle.config.ts");
94
+ const drizzleKitBin = path.join(root, "node_modules", ".bin", "drizzle-kit");
95
+ const cmd = `"${drizzleKitBin}" push --force --config=${configPath}`;
96
+ console.log(`[Kernel:Lifecycle] Executing isolated migration. Modules: ${Array.from(activeModuleIds).join(", ")}`);
97
+ try {
98
+ await execAsync(cmd, {
99
+ env: {
100
+ ...process.env,
101
+ CI: "true",
102
+ // Pass the calculated schemas to our dynamic drizzle.config.ts
103
+ DRIZZLE_SCHEMA_OVERRIDE: schemaPaths.join(","),
104
+ },
105
+ cwd: root,
106
+ });
107
+ console.log(`[Kernel:Lifecycle] Isolated migration successful for ${moduleId}`);
108
+ }
109
+ catch (e) {
110
+ console.error(`[Kernel:Lifecycle] Isolated migration failed for ${moduleId}:`);
111
+ console.error(e.stdout || e.message);
112
+ throw new Error(`Migration failed: ${moduleId}`);
113
+ }
114
+ }
115
+ async function performToggle(moduleId, isEnabled) {
116
+ var _a;
117
+ try {
118
+ const allModules = await getModules();
119
+ const manifest = allModules.find((m) => m.id === moduleId);
120
+ await updateStep(moduleId, "Validate module...");
121
+ await sleep(500);
122
+ if (!manifest)
123
+ return;
124
+ if (isEnabled) {
125
+ await updateStep(moduleId, "Queued...");
126
+ await sleep(500);
127
+ /*
128
+ * 1. Check dependencies
129
+ * 2. Enable module in DB (but not marked as installed yet)
130
+ * 3. Run onMigrate (or default push) to sync DB
131
+ * 4. Run onEnable
132
+ * 5. Mark as installed
133
+ */
134
+ if ((_a = manifest.dependencies) === null || _a === void 0 ? void 0 : _a.length) {
135
+ const pendingDeps = manifest.dependencies.filter((depId) => {
136
+ const dep = allModules.find((m) => m.id === depId);
137
+ return dep && !dep.enabled && !dep.system;
138
+ });
139
+ if (pendingDeps.length > 0) {
140
+ // await updateStep(moduleId, "Waiting for dependencies...");
141
+ for (const depId of pendingDeps) {
142
+ await updateStep(moduleId, `Waiting for dependency "${depId}"...`);
143
+ await performToggle(depId, true);
144
+ await sleep(500);
145
+ }
146
+ }
147
+ }
148
+ await updateStep(moduleId, "Initializing...");
149
+ await sleep(500);
150
+ await db
151
+ .update(systemModulesTable)
152
+ .set({ enabled: true })
153
+ .where(eq(systemModulesTable.id, moduleId));
154
+ const instance = await getModuleInstance(moduleId);
155
+ await updateStep(moduleId, "Migrate database...");
156
+ await sleep(500);
157
+ try {
158
+ if (instance === null || instance === void 0 ? void 0 : instance.onMigrate) {
159
+ await instance.onMigrate();
160
+ }
161
+ else {
162
+ // Fallback to default push if no hook provided but schema might exist
163
+ await pushModuleSchema(moduleId);
164
+ }
165
+ await updateStep(moduleId, "Migration successful");
166
+ }
167
+ catch (e) {
168
+ console.error(`[Kernel] Migration failed for ${moduleId}:`, e);
169
+ await updateStep(moduleId, `Migration failed: ${e.message}`);
170
+ await sleep(500);
171
+ }
172
+ if (instance === null || instance === void 0 ? void 0 : instance.onEnable) {
173
+ await updateStep(moduleId, "Running setup...");
174
+ await sleep(500);
175
+ await instance.onEnable();
176
+ }
177
+ await updateStep(moduleId, "Finishing...");
178
+ await sleep(500);
179
+ await db
180
+ .update(systemModulesTable)
181
+ .set({ installed: true, lastStep: null })
182
+ .where(eq(systemModulesTable.id, moduleId));
183
+ }
184
+ else {
185
+ const dependents = allModules.filter((m) => {
186
+ var _a, _b;
187
+ if (!m.enabled || m.id === moduleId)
188
+ return false;
189
+ if ((_a = m.dependencies) === null || _a === void 0 ? void 0 : _a.includes(moduleId))
190
+ return true;
191
+ if ((_b = m.extends) === null || _b === void 0 ? void 0 : _b.includes(moduleId)) {
192
+ const otherActiveTargets = m.extends.filter((targetId) => {
193
+ if (targetId === moduleId)
194
+ return false;
195
+ const target = allModules.find((mod) => mod.id === targetId);
196
+ return target === null || target === void 0 ? void 0 : target.enabled;
197
+ });
198
+ return otherActiveTargets.length === 0;
199
+ }
200
+ return false;
201
+ });
202
+ if (dependents.length > 0) {
203
+ await updateStep(moduleId, `Deactivating dependents...`);
204
+ for (const dep of dependents) {
205
+ await performToggle(dep.id, false);
206
+ await sleep(500);
207
+ }
208
+ }
209
+ await updateStep(moduleId, "Deactivating...");
210
+ const instance = await getModuleInstance(moduleId);
211
+ if (instance === null || instance === void 0 ? void 0 : instance.onDisable)
212
+ await instance.onDisable();
213
+ await db
214
+ .update(systemModulesTable)
215
+ .set({ enabled: false, installed: false })
216
+ .where(eq(systemModulesTable.id, moduleId));
217
+ await updateStep(moduleId, null);
218
+ }
219
+ }
220
+ catch (e) {
221
+ console.error(`[Kernel] Fatal error for ${moduleId}:`, e);
222
+ await updateStep(moduleId, `Error: ${e.message}`);
223
+ }
224
+ }
225
+ export async function toggleModuleState(moduleId, isEnabled) {
226
+ const allModules = await getModules();
227
+ const manifest = allModules.find((m) => m.id === moduleId);
228
+ if (!manifest)
229
+ throw new Error(`Module "${moduleId}" not found`);
230
+ if (manifest.enabled === isEnabled)
231
+ return { success: true };
232
+ void performToggle(moduleId, isEnabled);
233
+ return { success: true };
234
+ }
235
+ export async function initOperationalModules() {
236
+ const allModules = await getModules();
237
+ for (const mod of allModules) {
238
+ if (mod.enabled) {
239
+ try {
240
+ const instance = await getModuleInstance(mod.id);
241
+ if (instance === null || instance === void 0 ? void 0 : instance.init) {
242
+ await instance.init();
243
+ }
244
+ }
245
+ catch (e) {
246
+ console.error(`[Kernel] Failed to init module ${mod.id}:`, e);
247
+ }
248
+ }
249
+ }
250
+ }
@@ -1,31 +1,27 @@
1
- import { IModule } from "../types.mjs";
2
-
3
- //#region src/server/manage.d.ts
4
- declare function registerModules(modules: IModule[]): Promise<void>;
5
- declare function getModules(): Promise<{
6
- enabled: boolean;
7
- installed: boolean;
8
- lastStep: string | null | undefined;
9
- hasDocs: boolean;
10
- id: string;
11
- name: string;
12
- version: string;
13
- dependencies: string[];
14
- extends: string[];
15
- system: boolean;
16
- description?: string | undefined;
17
- npmDependencies?: string[] | undefined;
18
- npmDevDependencies?: string[] | undefined;
1
+ import { type IModule } from "../types";
2
+ export declare function registerModules(modules: IModule[]): Promise<void>;
3
+ export declare function getModules(): Promise<{
4
+ enabled: boolean;
5
+ installed: boolean;
6
+ lastStep: string | null | undefined;
7
+ hasDocs: boolean;
8
+ id: string;
9
+ name: string;
10
+ version: string;
11
+ dependencies: string[];
12
+ extends: string[];
13
+ system: boolean;
14
+ description?: string | undefined;
15
+ npmDependencies?: string[] | undefined;
16
+ npmDevDependencies?: string[] | undefined;
19
17
  }[]>;
20
- declare function getModuleStatus(moduleId: string): Promise<{
21
- enabled: boolean;
22
- installed: boolean;
23
- lastStep: string | null;
18
+ export declare function getModuleStatus(moduleId: string): Promise<{
19
+ enabled: boolean;
20
+ installed: boolean;
21
+ lastStep: string | null;
24
22
  }>;
25
- declare function isModuleEnabled(moduleId: string): Promise<boolean>;
26
- declare function getModuleInstance(moduleId: string): Promise<IModule | null>;
27
- declare function getModuleConfig<T>(moduleId: string): Promise<T | null>;
28
- declare function updateModuleConfig(moduleId: string, config: any): Promise<void>;
29
- //#endregion
30
- export { getModuleConfig, getModuleInstance, getModuleStatus, getModules, isModuleEnabled, registerModules, updateModuleConfig };
31
- //# sourceMappingURL=manage.d.mts.map
23
+ export declare function isModuleEnabled(moduleId: string): Promise<boolean>;
24
+ export declare function getModuleInstance(moduleId: string): Promise<IModule | null>;
25
+ export declare function getModuleConfig<T>(moduleId: string): Promise<T | null>;
26
+ export declare function updateModuleConfig(moduleId: string, config: any): Promise<void>;
27
+ //# sourceMappingURL=manage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"manage.d.mts","names":[],"sources":["../../src/server/manage.ts"],"mappings":";;;iBAesB,eAAA,CAAgB,OAAA,EAAS,OAAA,KAAS,OAAA;AAAA,iBASlC,UAAA,CAAA,GAAU,OAAA;;;;;;;;;;;;;;;iBAmDV,eAAA,CAAgB,QAAA,WAAgB,OAAA;;;;;iBAiBhC,eAAA,CAAgB,QAAA,WAAmB,OAAA;AAAA,iBAYnC,iBAAA,CACpB,QAAA,WACC,OAAA,CAAQ,OAAA;AAAA,iBA6CW,eAAA,GAAA,CAAmB,QAAA,WAAmB,OAAA,CAAQ,CAAA;AAAA,iBAa9C,kBAAA,CAAmB,QAAA,UAAkB,MAAA,QAAW,OAAA"}
1
+ {"version":3,"file":"manage.d.ts","sourceRoot":"","sources":["../../src/server/manage.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,OAAO,EAAwB,MAAM,UAAU,CAAC;AAQ9D,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,iBAOvD;AAED,wBAAsB,UAAU;;;;;;;;;;;;;;KAiD/B;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM;;;;GAerD;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAUxE;AAED,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CA2CzB;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAW5E;AAED,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,iBASrE"}