@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.
@@ -1,126 +1,140 @@
1
+ "use strict";
1
2
  "use server";
2
3
 
3
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
4
- const require_types = require('../types.cjs');
5
- let _arch_cadre_core_server = require("@arch-cadre/core/server");
6
- let node_fs_promises = require("node:fs/promises");
7
- node_fs_promises = require_runtime.__toESM(node_fs_promises);
8
- let node_path = require("node:path");
9
- node_path = require_runtime.__toESM(node_path);
10
- let _arch_cadre_core = require("@arch-cadre/core");
11
- let drizzle_orm = require("drizzle-orm");
12
-
13
- //#region src/server/manage.ts
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__) globalForModules.__KRYO_REGISTERED_MODULES__ = /* @__PURE__ */ new Map();
22
+ if (!globalForModules.__KRYO_REGISTERED_MODULES__) {
23
+ globalForModules.__KRYO_REGISTERED_MODULES__ = /* @__PURE__ */new Map();
24
+ }
16
25
  async function registerModules(modules) {
17
- const store = globalForModules.__KRYO_REGISTERED_MODULES__;
18
- for (const mod of modules) if (mod.manifest?.id) store.set(mod.manifest.id, mod);
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
- try {
22
- const modulesDir = await (0, _arch_cadre_core_server.getModulesDir)();
23
- const manifests = [];
24
- const entries = await node_fs_promises.default.readdir(modulesDir).catch(() => []);
25
- for (const dir of entries) {
26
- if (dir.startsWith(".")) continue;
27
- try {
28
- const content = await node_fs_promises.default.readFile(node_path.default.join(modulesDir, dir, "manifest.json"), "utf-8");
29
- const manifest = require_types.ModuleManifestSchema.parse(JSON.parse(content));
30
- manifests.push({
31
- ...manifest,
32
- hasDocs: false
33
- });
34
- } catch {}
35
- }
36
- const store = globalForModules.__KRYO_REGISTERED_MODULES__;
37
- for (const mod of store.values()) if (!manifests.some((m) => m.id === mod.manifest.id)) manifests.push({
38
- ...mod.manifest,
39
- hasDocs: false
40
- });
41
- const dbModules = await _arch_cadre_core_server.db.select().from(_arch_cadre_core.systemModulesTable).catch(() => []);
42
- const dbMap = new Map(dbModules.map((m) => [m.id, m]));
43
- return manifests.map((mod) => {
44
- const dbEntry = dbMap.get(mod.id);
45
- return {
46
- ...mod,
47
- enabled: mod.system ? true : dbEntry?.enabled ?? false,
48
- installed: mod.system ? true : dbEntry?.installed ?? false,
49
- lastStep: dbEntry?.lastStep,
50
- hasDocs: mod.hasDocs
51
- };
52
- });
53
- } catch {
54
- return [];
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
- try {
59
- const [mod] = await _arch_cadre_core_server.db.select().from(_arch_cadre_core.systemModulesTable).where((0, drizzle_orm.eq)(_arch_cadre_core.systemModulesTable.id, moduleId));
60
- return {
61
- enabled: mod?.enabled,
62
- installed: mod?.installed,
63
- lastStep: mod?.lastStep
64
- };
65
- } catch {
66
- return {
67
- enabled: false,
68
- installed: false,
69
- lastStep: null
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
- try {
75
- const [mod] = await _arch_cadre_core_server.db.select().from(_arch_cadre_core.systemModulesTable).where((0, drizzle_orm.eq)(_arch_cadre_core.systemModulesTable.id, moduleId));
76
- return !!mod?.enabled || !!mod?.system;
77
- } catch {
78
- return false;
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
- try {
83
- const store = globalForModules.__KRYO_REGISTERED_MODULES__;
84
- if (store.has(moduleId)) {
85
- console.log(`[Kernel:Manage] Module "${moduleId}" found in registry.`);
86
- return store.get(moduleId) || null;
87
- }
88
- console.log(`[Kernel:Manage] Module "${moduleId}" not in registry. Registry size: ${store.size}. Keys: ${Array.from(store.keys()).join(", ")}`);
89
- if (!moduleId.startsWith(".") && !moduleId.startsWith("/")) try {
90
- const mod = await import(`@arch-cadre/${moduleId}`);
91
- console.log(`[Kernel:Manage] Module "${moduleId}" loaded via import().`);
92
- return mod.default || mod || null;
93
- } catch (e) {
94
- console.warn(`[Kernel:Manage] Failed to import module "${moduleId} via import().": ${e.message}`);
95
- }
96
- return null;
97
- } catch (error) {
98
- console.error(`[Kernel:Manage] Error in getModuleInstance for "${moduleId}":`, error);
99
- return null;
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
- try {
104
- const [mod] = await _arch_cadre_core_server.db.select({ config: _arch_cadre_core.systemModulesTable.config }).from(_arch_cadre_core.systemModulesTable).where((0, drizzle_orm.eq)(_arch_cadre_core.systemModulesTable.id, moduleId));
105
- if (!mod?.config) return null;
106
- return JSON.parse(mod.config);
107
- } catch {
108
- return null;
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
- try {
113
- await _arch_cadre_core_server.db.update(_arch_cadre_core.systemModulesTable).set({ config: JSON.stringify(config) }).where((0, drizzle_orm.eq)(_arch_cadre_core.systemModulesTable.id, moduleId));
114
- } catch (e) {
115
- console.warn(`[Kernel:Manage] Failed to update config for ${moduleId}:`, e);
116
- }
117
- }
118
-
119
- //#endregion
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>;
@@ -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__) globalForModules.__KRYO_REGISTERED_MODULES__ = /* @__PURE__ */ new Map();
13
- async function registerModules(modules) {
14
- const store = globalForModules.__KRYO_REGISTERED_MODULES__;
15
- for (const mod of modules) if (mod.manifest?.id) store.set(mod.manifest.id, mod);
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
- try {
19
- const modulesDir = await getModulesDir();
20
- const manifests = [];
21
- const entries = await fs.readdir(modulesDir).catch(() => []);
22
- for (const dir of entries) {
23
- if (dir.startsWith(".")) continue;
24
- try {
25
- const content = await fs.readFile(path.join(modulesDir, dir, "manifest.json"), "utf-8");
26
- const manifest = ModuleManifestSchema.parse(JSON.parse(content));
27
- manifests.push({
28
- ...manifest,
29
- hasDocs: false
30
- });
31
- } catch {}
32
- }
33
- const store = globalForModules.__KRYO_REGISTERED_MODULES__;
34
- for (const mod of store.values()) if (!manifests.some((m) => m.id === mod.manifest.id)) manifests.push({
35
- ...mod.manifest,
36
- hasDocs: false
37
- });
38
- const dbModules = await db.select().from(systemModulesTable).catch(() => []);
39
- const dbMap = new Map(dbModules.map((m) => [m.id, m]));
40
- return manifests.map((mod) => {
41
- const dbEntry = dbMap.get(mod.id);
42
- return {
43
- ...mod,
44
- enabled: mod.system ? true : dbEntry?.enabled ?? false,
45
- installed: mod.system ? true : dbEntry?.installed ?? false,
46
- lastStep: dbEntry?.lastStep,
47
- hasDocs: mod.hasDocs
48
- };
49
- });
50
- } catch {
51
- return [];
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
- try {
56
- const [mod] = await db.select().from(systemModulesTable).where(eq(systemModulesTable.id, moduleId));
57
- return {
58
- enabled: mod?.enabled,
59
- installed: mod?.installed,
60
- lastStep: mod?.lastStep
61
- };
62
- } catch {
63
- return {
64
- enabled: false,
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
- try {
72
- const [mod] = await db.select().from(systemModulesTable).where(eq(systemModulesTable.id, moduleId));
73
- return !!mod?.enabled || !!mod?.system;
74
- } catch {
75
- return false;
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
- try {
80
- const store = globalForModules.__KRYO_REGISTERED_MODULES__;
81
- if (store.has(moduleId)) {
82
- console.log(`[Kernel:Manage] Module "${moduleId}" found in registry.`);
83
- return store.get(moduleId) || null;
84
- }
85
- console.log(`[Kernel:Manage] Module "${moduleId}" not in registry. Registry size: ${store.size}. Keys: ${Array.from(store.keys()).join(", ")}`);
86
- if (!moduleId.startsWith(".") && !moduleId.startsWith("/")) try {
87
- const mod = await import(`@arch-cadre/${moduleId}`);
88
- console.log(`[Kernel:Manage] Module "${moduleId}" loaded via import().`);
89
- return mod.default || mod || null;
90
- } catch (e) {
91
- console.warn(`[Kernel:Manage] Failed to import module "${moduleId} via import().": ${e.message}`);
92
- }
93
- return null;
94
- } catch (error) {
95
- console.error(`[Kernel:Manage] Error in getModuleInstance for "${moduleId}":`, error);
96
- return null;
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
- try {
101
- const [mod] = await db.select({ config: systemModulesTable.config }).from(systemModulesTable).where(eq(systemModulesTable.id, moduleId));
102
- if (!mod?.config) return null;
103
- return JSON.parse(mod.config);
104
- } catch {
105
- return null;
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
- try {
110
- await db.update(systemModulesTable).set({ config: JSON.stringify(config) }).where(eq(systemModulesTable.id, moduleId));
111
- } catch (e) {
112
- console.warn(`[Kernel:Manage] Failed to update config for ${moduleId}:`, e);
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 };