@arch-cadre/modules 0.0.49 → 0.0.50
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/client/extension-point-client.cjs +33 -26
- package/dist/client/extension-point-client.d.ts +10 -0
- package/dist/client/extension-point-client.mjs +19 -23
- package/dist/client/extension-point.cjs +25 -18
- package/dist/client/extension-point.d.ts +9 -0
- package/dist/client/extension-point.mjs +14 -17
- package/dist/client/index.cjs +38 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.mjs +3 -0
- package/dist/client/widget-area.cjs +29 -22
- package/dist/client/widget-area.d.ts +9 -0
- package/dist/client/widget-area.mjs +16 -20
- package/dist/index.cjs +42 -9
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +4 -6
- package/dist/server/lifecycle.cjs +204 -180
- package/dist/server/lifecycle.d.ts +5 -0
- package/dist/server/lifecycle.mjs +223 -173
- package/dist/server/manage.cjs +124 -110
- package/dist/server/manage.d.ts +12 -0
- package/dist/server/manage.mjs +113 -104
- package/dist/server/registry.cjs +90 -82
- package/dist/server/registry.d.ts +1 -0
- package/dist/server/registry.mjs +94 -80
- package/dist/server/ui.cjs +197 -155
- package/dist/server/ui.d.ts +12 -0
- package/dist/server/ui.mjs +203 -154
- package/dist/server.cjs +59 -29
- package/dist/server.d.ts +5 -0
- package/dist/server.mjs +5 -7
- package/dist/types.cjs +18 -17
- package/dist/types.d.ts +113 -0
- package/dist/types.mjs +12 -16
- package/package.json +20 -6
- package/dist/_virtual/_rolldown/runtime.cjs +0 -29
package/dist/server/registry.cjs
CHANGED
|
@@ -1,86 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
"use server";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.initModules = initModules;
|
|
8
|
+
var _core = require("@arch-cadre/core");
|
|
9
|
+
var _server = require("@arch-cadre/core/server");
|
|
10
|
+
var _drizzleOrm = require("drizzle-orm");
|
|
11
|
+
var _manage = require("./manage.js");
|
|
10
12
|
const globalForRegistry = globalThis;
|
|
11
13
|
async function initModules(force = false) {
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
14
|
+
if (globalForRegistry.__KRYO_MODULES_INITIALIZED__ && !force) return;
|
|
15
|
+
if (force) {
|
|
16
|
+
console.log("[Kernel:Registry] Forcing re-initialization...");
|
|
17
|
+
_core.eventBus.clearAll();
|
|
18
|
+
}
|
|
19
|
+
console.log("[Kernel:Registry] Synchronizing module listeners...");
|
|
20
|
+
globalForRegistry.__KRYO_MODULES_INITIALIZED__ = true;
|
|
21
|
+
await _core.eventBus.publish("system:modules:init:start", {
|
|
22
|
+
timestamp: Date.now()
|
|
23
|
+
});
|
|
24
|
+
const processedModuleIds = /* @__PURE__ */new Set();
|
|
25
|
+
let hasNewModules = true;
|
|
26
|
+
let iterations = 0;
|
|
27
|
+
const MAX_ITERATIONS = 10;
|
|
28
|
+
while (hasNewModules && iterations < MAX_ITERATIONS) {
|
|
29
|
+
hasNewModules = false;
|
|
30
|
+
iterations++;
|
|
31
|
+
const currentModules = await (0, _manage.getModules)();
|
|
32
|
+
const pendingModules = currentModules.filter(mod => !processedModuleIds.has(mod.id));
|
|
33
|
+
if (pendingModules.length === 0) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
for (const mod of pendingModules) {
|
|
37
|
+
try {
|
|
38
|
+
await _server.db.insert(_core.systemModulesTable).values({
|
|
39
|
+
id: mod.id,
|
|
40
|
+
enabled: mod.system ?? false,
|
|
41
|
+
installed: mod.system ?? false,
|
|
42
|
+
system: mod.system ?? false
|
|
43
|
+
}).onConflictDoNothing();
|
|
44
|
+
} catch (_e) {}
|
|
45
|
+
}
|
|
46
|
+
const sortedPending = [...pendingModules].sort((a, b) => a.system === b.system ? 0 : a.system ? -1 : 1);
|
|
47
|
+
for (const mod of sortedPending) {
|
|
48
|
+
processedModuleIds.add(mod.id);
|
|
49
|
+
hasNewModules = true;
|
|
50
|
+
try {
|
|
51
|
+
const enabled = await (0, _manage.isModuleEnabled)(mod.id);
|
|
52
|
+
if (!enabled) continue;
|
|
53
|
+
const instance = await (0, _manage.getModuleInstance)(mod.id);
|
|
54
|
+
if (!instance) {
|
|
55
|
+
console.warn(`[Kernel:Registry] No instance found for module ${mod.id}. Ensure it is registered correctly.`);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
let dbMod = null;
|
|
59
|
+
try {
|
|
60
|
+
[dbMod] = await _server.db.select().from(_core.systemModulesTable).where((0, _drizzleOrm.eq)(_core.systemModulesTable.id, mod.id));
|
|
61
|
+
} catch (_e) {}
|
|
62
|
+
if (enabled && (!dbMod || !dbMod.installed)) {
|
|
63
|
+
console.log(`[Kernel:Registry] Installing module ${mod.id}...`);
|
|
64
|
+
if (instance.onMigrate) {
|
|
65
|
+
console.log(`[Kernel:Registry] Running onMigrate for ${mod.id}...`);
|
|
66
|
+
await instance.onMigrate();
|
|
67
|
+
}
|
|
68
|
+
console.log(`[Kernel:Registry] Running onEnable for ${mod.id}...`);
|
|
69
|
+
if (instance.onEnable) await instance.onEnable();
|
|
70
|
+
try {
|
|
71
|
+
await _server.db.update(_core.systemModulesTable).set({
|
|
72
|
+
installed: true,
|
|
73
|
+
lastStep: null
|
|
74
|
+
}).where((0, _drizzleOrm.eq)(_core.systemModulesTable.id, mod.id));
|
|
75
|
+
} catch (_e) {}
|
|
76
|
+
}
|
|
77
|
+
if (instance.init) {
|
|
78
|
+
console.log(`[Kernel:Registry] Initializing ${mod.id}...`);
|
|
79
|
+
await instance.init();
|
|
80
|
+
console.log(`[Kernel:Registry] Module ${mod.id} is active.`);
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(`[Kernel:Registry] Critical failure for ${mod.id}:`, error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (iterations >= MAX_ITERATIONS) {
|
|
88
|
+
console.warn("[Kernel:Registry] Max init iterations reached. Check for circular module registrations.");
|
|
89
|
+
}
|
|
90
|
+
await _core.eventBus.publish("system:modules:init:end", {
|
|
91
|
+
timestamp: Date.now(),
|
|
92
|
+
moduleCount: processedModuleIds.size
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initModules(force?: boolean): Promise<void>;
|
package/dist/server/registry.mjs
CHANGED
|
@@ -1,85 +1,99 @@
|
|
|
1
1
|
"use server";
|
|
2
|
-
|
|
3
|
-
import { getModuleInstance, getModules, isModuleEnabled } from "./manage.mjs";
|
|
4
|
-
import { db } from "@arch-cadre/core/server";
|
|
5
2
|
import { eventBus, systemModulesTable } from "@arch-cadre/core";
|
|
3
|
+
import { db } from "@arch-cadre/core/server";
|
|
6
4
|
import { eq } from "drizzle-orm";
|
|
7
|
-
|
|
8
|
-
//#region src/server/registry.ts
|
|
5
|
+
import { getModuleInstance, getModules, isModuleEnabled } from "./manage.js";
|
|
9
6
|
const globalForRegistry = globalThis;
|
|
10
|
-
async function initModules(force = false) {
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
7
|
+
export async function initModules(force = false) {
|
|
8
|
+
if (globalForRegistry.__KRYO_MODULES_INITIALIZED__ && !force) return;
|
|
9
|
+
if (force) {
|
|
10
|
+
console.log("[Kernel:Registry] Forcing re-initialization...");
|
|
11
|
+
eventBus.clearAll();
|
|
12
|
+
}
|
|
13
|
+
console.log("[Kernel:Registry] Synchronizing module listeners...");
|
|
14
|
+
globalForRegistry.__KRYO_MODULES_INITIALIZED__ = true;
|
|
15
|
+
await eventBus.publish("system:modules:init:start", {
|
|
16
|
+
timestamp: Date.now()
|
|
17
|
+
});
|
|
18
|
+
const processedModuleIds = /* @__PURE__ */ new Set();
|
|
19
|
+
let hasNewModules = true;
|
|
20
|
+
let iterations = 0;
|
|
21
|
+
const MAX_ITERATIONS = 10;
|
|
22
|
+
while (hasNewModules && iterations < MAX_ITERATIONS) {
|
|
23
|
+
hasNewModules = false;
|
|
24
|
+
iterations++;
|
|
25
|
+
const currentModules = await getModules();
|
|
26
|
+
const pendingModules = currentModules.filter(
|
|
27
|
+
(mod) => !processedModuleIds.has(mod.id)
|
|
28
|
+
);
|
|
29
|
+
if (pendingModules.length === 0) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
for (const mod of pendingModules) {
|
|
33
|
+
try {
|
|
34
|
+
await db.insert(systemModulesTable).values({
|
|
35
|
+
id: mod.id,
|
|
36
|
+
enabled: mod.system ?? false,
|
|
37
|
+
installed: mod.system ?? false,
|
|
38
|
+
system: mod.system ?? false
|
|
39
|
+
}).onConflictDoNothing();
|
|
40
|
+
} catch (_e) {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const sortedPending = [...pendingModules].sort(
|
|
44
|
+
(a, b) => a.system === b.system ? 0 : a.system ? -1 : 1
|
|
45
|
+
);
|
|
46
|
+
for (const mod of sortedPending) {
|
|
47
|
+
processedModuleIds.add(mod.id);
|
|
48
|
+
hasNewModules = true;
|
|
49
|
+
try {
|
|
50
|
+
const enabled = await isModuleEnabled(mod.id);
|
|
51
|
+
if (!enabled) continue;
|
|
52
|
+
const instance = await getModuleInstance(mod.id);
|
|
53
|
+
if (!instance) {
|
|
54
|
+
console.warn(
|
|
55
|
+
`[Kernel:Registry] No instance found for module ${mod.id}. Ensure it is registered correctly.`
|
|
56
|
+
);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
let dbMod = null;
|
|
60
|
+
try {
|
|
61
|
+
[dbMod] = await db.select().from(systemModulesTable).where(eq(systemModulesTable.id, mod.id));
|
|
62
|
+
} catch (_e) {
|
|
63
|
+
}
|
|
64
|
+
if (enabled && (!dbMod || !dbMod.installed)) {
|
|
65
|
+
console.log(`[Kernel:Registry] Installing module ${mod.id}...`);
|
|
66
|
+
if (instance.onMigrate) {
|
|
67
|
+
console.log(`[Kernel:Registry] Running onMigrate for ${mod.id}...`);
|
|
68
|
+
await instance.onMigrate();
|
|
69
|
+
}
|
|
70
|
+
console.log(`[Kernel:Registry] Running onEnable for ${mod.id}...`);
|
|
71
|
+
if (instance.onEnable) await instance.onEnable();
|
|
72
|
+
try {
|
|
73
|
+
await db.update(systemModulesTable).set({ installed: true, lastStep: null }).where(eq(systemModulesTable.id, mod.id));
|
|
74
|
+
} catch (_e) {
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (instance.init) {
|
|
78
|
+
console.log(`[Kernel:Registry] Initializing ${mod.id}...`);
|
|
79
|
+
await instance.init();
|
|
80
|
+
console.log(`[Kernel:Registry] Module ${mod.id} is active.`);
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(
|
|
84
|
+
`[Kernel:Registry] Critical failure for ${mod.id}:`,
|
|
85
|
+
error
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (iterations >= MAX_ITERATIONS) {
|
|
91
|
+
console.warn(
|
|
92
|
+
"[Kernel:Registry] Max init iterations reached. Check for circular module registrations."
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
await eventBus.publish("system:modules:init:end", {
|
|
96
|
+
timestamp: Date.now(),
|
|
97
|
+
moduleCount: processedModuleIds.size
|
|
98
|
+
});
|
|
82
99
|
}
|
|
83
|
-
|
|
84
|
-
//#endregion
|
|
85
|
-
export { initModules };
|