@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/manage.cjs
CHANGED
|
@@ -1,126 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
"use server";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getModuleConfig = getModuleConfig;
|
|
8
|
+
exports.getModuleInstance = getModuleInstance;
|
|
9
|
+
exports.getModuleStatus = getModuleStatus;
|
|
10
|
+
exports.getModules = getModules;
|
|
11
|
+
exports.isModuleEnabled = isModuleEnabled;
|
|
12
|
+
exports.registerModules = registerModules;
|
|
13
|
+
exports.updateModuleConfig = updateModuleConfig;
|
|
14
|
+
var _promises = _interopRequireDefault(require("node:fs/promises"));
|
|
15
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
16
|
+
var _core = require("@arch-cadre/core");
|
|
17
|
+
var _server = require("@arch-cadre/core/server");
|
|
18
|
+
var _drizzleOrm = require("drizzle-orm");
|
|
19
|
+
var _types = require("../types.js");
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
21
|
const globalForModules = globalThis;
|
|
15
|
-
if (!globalForModules.__KRYO_REGISTERED_MODULES__)
|
|
22
|
+
if (!globalForModules.__KRYO_REGISTERED_MODULES__) {
|
|
23
|
+
globalForModules.__KRYO_REGISTERED_MODULES__ = /* @__PURE__ */new Map();
|
|
24
|
+
}
|
|
16
25
|
async function registerModules(modules) {
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
const store = globalForModules.__KRYO_REGISTERED_MODULES__;
|
|
27
|
+
for (const mod of modules) {
|
|
28
|
+
if (mod.manifest?.id) {
|
|
29
|
+
store.set(mod.manifest.id, mod);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
19
32
|
}
|
|
20
33
|
async function getModules() {
|
|
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
|
-
|
|
34
|
+
try {
|
|
35
|
+
const modulesDir = await (0, _server.getModulesDir)();
|
|
36
|
+
const manifests = [];
|
|
37
|
+
const entries = await _promises.default.readdir(modulesDir).catch(() => []);
|
|
38
|
+
for (const dir of entries) {
|
|
39
|
+
if (dir.startsWith(".")) continue;
|
|
40
|
+
try {
|
|
41
|
+
const content = await _promises.default.readFile(_nodePath.default.join(modulesDir, dir, "manifest.json"), "utf-8");
|
|
42
|
+
const manifest = _types.ModuleManifestSchema.parse(JSON.parse(content));
|
|
43
|
+
manifests.push({
|
|
44
|
+
...manifest,
|
|
45
|
+
hasDocs: false
|
|
46
|
+
});
|
|
47
|
+
} catch {}
|
|
48
|
+
}
|
|
49
|
+
const store = globalForModules.__KRYO_REGISTERED_MODULES__;
|
|
50
|
+
for (const mod of store.values()) {
|
|
51
|
+
if (!manifests.some(m => m.id === mod.manifest.id)) {
|
|
52
|
+
manifests.push({
|
|
53
|
+
...mod.manifest,
|
|
54
|
+
hasDocs: false
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const dbModules = await _server.db.select().from(_core.systemModulesTable).catch(() => []);
|
|
59
|
+
const dbMap = new Map(dbModules.map(m => [m.id, m]));
|
|
60
|
+
return manifests.map(mod => {
|
|
61
|
+
const dbEntry = dbMap.get(mod.id);
|
|
62
|
+
return {
|
|
63
|
+
...mod,
|
|
64
|
+
enabled: mod.system ? true : dbEntry?.enabled ?? false,
|
|
65
|
+
installed: mod.system ? true : dbEntry?.installed ?? false,
|
|
66
|
+
lastStep: dbEntry?.lastStep,
|
|
67
|
+
hasDocs: mod.hasDocs
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
} catch {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
56
73
|
}
|
|
57
74
|
async function getModuleStatus(moduleId) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
try {
|
|
76
|
+
const [mod] = await _server.db.select().from(_core.systemModulesTable).where((0, _drizzleOrm.eq)(_core.systemModulesTable.id, moduleId));
|
|
77
|
+
return {
|
|
78
|
+
enabled: mod?.enabled,
|
|
79
|
+
installed: mod?.installed,
|
|
80
|
+
lastStep: mod?.lastStep
|
|
81
|
+
};
|
|
82
|
+
} catch {
|
|
83
|
+
return {
|
|
84
|
+
enabled: false,
|
|
85
|
+
installed: false,
|
|
86
|
+
lastStep: null
|
|
87
|
+
};
|
|
88
|
+
}
|
|
72
89
|
}
|
|
73
90
|
async function isModuleEnabled(moduleId) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
try {
|
|
92
|
+
const [mod] = await _server.db.select().from(_core.systemModulesTable).where((0, _drizzleOrm.eq)(_core.systemModulesTable.id, moduleId));
|
|
93
|
+
return !!mod?.enabled || !!mod?.system;
|
|
94
|
+
} catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
80
97
|
}
|
|
81
98
|
async function getModuleInstance(moduleId) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
try {
|
|
100
|
+
const store = globalForModules.__KRYO_REGISTERED_MODULES__;
|
|
101
|
+
if (store.has(moduleId)) {
|
|
102
|
+
console.log(`[Kernel:Manage] Module "${moduleId}" found in registry.`);
|
|
103
|
+
return store.get(moduleId) || null;
|
|
104
|
+
}
|
|
105
|
+
console.log(`[Kernel:Manage] Module "${moduleId}" not in registry. Registry size: ${store.size}. Keys: ${Array.from(store.keys()).join(", ")}`);
|
|
106
|
+
if (!moduleId.startsWith(".") && !moduleId.startsWith("/")) {
|
|
107
|
+
try {
|
|
108
|
+
const mod = await Promise.resolve(`@arch-cadre/${moduleId}`).then(s => require(s));
|
|
109
|
+
console.log(`[Kernel:Manage] Module "${moduleId}" loaded via import().`);
|
|
110
|
+
return mod.default || mod || null;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.warn(`[Kernel:Manage] Failed to import module "${moduleId} via import().": ${e.message}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error(`[Kernel:Manage] Error in getModuleInstance for "${moduleId}":`, error);
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
101
120
|
}
|
|
102
121
|
async function getModuleConfig(moduleId) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
try {
|
|
123
|
+
const [mod] = await _server.db.select({
|
|
124
|
+
config: _core.systemModulesTable.config
|
|
125
|
+
}).from(_core.systemModulesTable).where((0, _drizzleOrm.eq)(_core.systemModulesTable.id, moduleId));
|
|
126
|
+
if (!mod?.config) return null;
|
|
127
|
+
return JSON.parse(mod.config);
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
110
131
|
}
|
|
111
132
|
async function updateModuleConfig(moduleId, config) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
exports.getModuleConfig = getModuleConfig;
|
|
121
|
-
exports.getModuleInstance = getModuleInstance;
|
|
122
|
-
exports.getModuleStatus = getModuleStatus;
|
|
123
|
-
exports.getModules = getModules;
|
|
124
|
-
exports.isModuleEnabled = isModuleEnabled;
|
|
125
|
-
exports.registerModules = registerModules;
|
|
126
|
-
exports.updateModuleConfig = updateModuleConfig;
|
|
133
|
+
try {
|
|
134
|
+
await _server.db.update(_core.systemModulesTable).set({
|
|
135
|
+
config: JSON.stringify(config)
|
|
136
|
+
}).where((0, _drizzleOrm.eq)(_core.systemModulesTable.id, moduleId));
|
|
137
|
+
} catch (e) {
|
|
138
|
+
console.warn(`[Kernel:Manage] Failed to update config for ${moduleId}:`, e);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type IModule } from "../types.js";
|
|
2
|
+
export declare function registerModules(modules: IModule[]): Promise<void>;
|
|
3
|
+
export declare function getModules(): Promise<any[]>;
|
|
4
|
+
export declare function getModuleStatus(moduleId: string): Promise<{
|
|
5
|
+
enabled: any;
|
|
6
|
+
installed: any;
|
|
7
|
+
lastStep: any;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function isModuleEnabled(moduleId: string): Promise<boolean>;
|
|
10
|
+
export declare function getModuleInstance(moduleId: string): Promise<IModule | null>;
|
|
11
|
+
export declare function getModuleConfig<T>(moduleId: string): Promise<T | null>;
|
|
12
|
+
export declare function updateModuleConfig(moduleId: string, config: any): Promise<void>;
|
package/dist/server/manage.mjs
CHANGED
|
@@ -1,117 +1,126 @@
|
|
|
1
1
|
"use server";
|
|
2
|
-
|
|
3
|
-
import { ModuleManifestSchema } from "../types.mjs";
|
|
4
|
-
import { db, getModulesDir } from "@arch-cadre/core/server";
|
|
5
2
|
import fs from "node:fs/promises";
|
|
6
3
|
import path from "node:path";
|
|
7
4
|
import { systemModulesTable } from "@arch-cadre/core";
|
|
5
|
+
import { db, getModulesDir } from "@arch-cadre/core/server";
|
|
8
6
|
import { eq } from "drizzle-orm";
|
|
9
|
-
|
|
10
|
-
//#region src/server/manage.ts
|
|
7
|
+
import { ModuleManifestSchema } from "../types.js";
|
|
11
8
|
const globalForModules = globalThis;
|
|
12
|
-
if (!globalForModules.__KRYO_REGISTERED_MODULES__)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
if (!globalForModules.__KRYO_REGISTERED_MODULES__) {
|
|
10
|
+
globalForModules.__KRYO_REGISTERED_MODULES__ = /* @__PURE__ */ new Map();
|
|
11
|
+
}
|
|
12
|
+
export async function registerModules(modules) {
|
|
13
|
+
const store = globalForModules.__KRYO_REGISTERED_MODULES__;
|
|
14
|
+
for (const mod of modules) {
|
|
15
|
+
if (mod.manifest?.id) {
|
|
16
|
+
store.set(mod.manifest.id, mod);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
16
19
|
}
|
|
17
|
-
async function getModules() {
|
|
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
|
-
|
|
20
|
+
export async function getModules() {
|
|
21
|
+
try {
|
|
22
|
+
const modulesDir = await getModulesDir();
|
|
23
|
+
const manifests = [];
|
|
24
|
+
const entries = await fs.readdir(modulesDir).catch(() => []);
|
|
25
|
+
for (const dir of entries) {
|
|
26
|
+
if (dir.startsWith(".")) continue;
|
|
27
|
+
try {
|
|
28
|
+
const content = await fs.readFile(
|
|
29
|
+
path.join(modulesDir, dir, "manifest.json"),
|
|
30
|
+
"utf-8"
|
|
31
|
+
);
|
|
32
|
+
const manifest = ModuleManifestSchema.parse(JSON.parse(content));
|
|
33
|
+
manifests.push({ ...manifest, hasDocs: false });
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const store = globalForModules.__KRYO_REGISTERED_MODULES__;
|
|
38
|
+
for (const mod of store.values()) {
|
|
39
|
+
if (!manifests.some((m) => m.id === mod.manifest.id)) {
|
|
40
|
+
manifests.push({ ...mod.manifest, hasDocs: false });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const dbModules = await db.select().from(systemModulesTable).catch(() => []);
|
|
44
|
+
const dbMap = new Map(dbModules.map((m) => [m.id, m]));
|
|
45
|
+
return manifests.map((mod) => {
|
|
46
|
+
const dbEntry = dbMap.get(mod.id);
|
|
47
|
+
return {
|
|
48
|
+
...mod,
|
|
49
|
+
enabled: mod.system ? true : dbEntry?.enabled ?? false,
|
|
50
|
+
installed: mod.system ? true : dbEntry?.installed ?? false,
|
|
51
|
+
lastStep: dbEntry?.lastStep,
|
|
52
|
+
hasDocs: mod.hasDocs
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
} catch {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
53
58
|
}
|
|
54
|
-
async function getModuleStatus(moduleId) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
installed: false,
|
|
66
|
-
lastStep: null
|
|
67
|
-
};
|
|
68
|
-
}
|
|
59
|
+
export async function getModuleStatus(moduleId) {
|
|
60
|
+
try {
|
|
61
|
+
const [mod] = await db.select().from(systemModulesTable).where(eq(systemModulesTable.id, moduleId));
|
|
62
|
+
return {
|
|
63
|
+
enabled: mod?.enabled,
|
|
64
|
+
installed: mod?.installed,
|
|
65
|
+
lastStep: mod?.lastStep
|
|
66
|
+
};
|
|
67
|
+
} catch {
|
|
68
|
+
return { enabled: false, installed: false, lastStep: null };
|
|
69
|
+
}
|
|
69
70
|
}
|
|
70
|
-
async function isModuleEnabled(moduleId) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
export async function isModuleEnabled(moduleId) {
|
|
72
|
+
try {
|
|
73
|
+
const [mod] = await db.select().from(systemModulesTable).where(eq(systemModulesTable.id, moduleId));
|
|
74
|
+
return !!mod?.enabled || !!mod?.system;
|
|
75
|
+
} catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
77
78
|
}
|
|
78
|
-
async function getModuleInstance(moduleId) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
79
|
+
export async function getModuleInstance(moduleId) {
|
|
80
|
+
try {
|
|
81
|
+
const store = globalForModules.__KRYO_REGISTERED_MODULES__;
|
|
82
|
+
if (store.has(moduleId)) {
|
|
83
|
+
console.log(`[Kernel:Manage] Module "${moduleId}" found in registry.`);
|
|
84
|
+
return store.get(moduleId) || null;
|
|
85
|
+
}
|
|
86
|
+
console.log(
|
|
87
|
+
`[Kernel:Manage] Module "${moduleId}" not in registry. Registry size: ${store.size}. Keys: ${Array.from(store.keys()).join(", ")}`
|
|
88
|
+
);
|
|
89
|
+
if (!moduleId.startsWith(".") && !moduleId.startsWith("/")) {
|
|
90
|
+
try {
|
|
91
|
+
const mod = await import(`@arch-cadre/${moduleId}`);
|
|
92
|
+
console.log(
|
|
93
|
+
`[Kernel:Manage] Module "${moduleId}" loaded via import().`
|
|
94
|
+
);
|
|
95
|
+
return mod.default || mod || null;
|
|
96
|
+
} catch (e) {
|
|
97
|
+
console.warn(
|
|
98
|
+
`[Kernel:Manage] Failed to import module "${moduleId} via import().": ${e.message}`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error(
|
|
105
|
+
`[Kernel:Manage] Error in getModuleInstance for "${moduleId}":`,
|
|
106
|
+
error
|
|
107
|
+
);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
98
110
|
}
|
|
99
|
-
async function getModuleConfig(moduleId) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
export async function getModuleConfig(moduleId) {
|
|
112
|
+
try {
|
|
113
|
+
const [mod] = await db.select({ config: systemModulesTable.config }).from(systemModulesTable).where(eq(systemModulesTable.id, moduleId));
|
|
114
|
+
if (!mod?.config) return null;
|
|
115
|
+
return JSON.parse(mod.config);
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
107
119
|
}
|
|
108
|
-
async function updateModuleConfig(moduleId, config) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
export async function updateModuleConfig(moduleId, config) {
|
|
121
|
+
try {
|
|
122
|
+
await db.update(systemModulesTable).set({ config: JSON.stringify(config) }).where(eq(systemModulesTable.id, moduleId));
|
|
123
|
+
} catch (e) {
|
|
124
|
+
console.warn(`[Kernel:Manage] Failed to update config for ${moduleId}:`, e);
|
|
125
|
+
}
|
|
114
126
|
}
|
|
115
|
-
|
|
116
|
-
//#endregion
|
|
117
|
-
export { getModuleConfig, getModuleInstance, getModuleStatus, getModules, isModuleEnabled, registerModules, updateModuleConfig };
|