@weconjs/core 0.1.1

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/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # @weconjs/core
2
+
3
+ > Core framework package for Wecon - A convention-over-configuration Node.js framework.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@weconjs/core.svg)](https://www.npmjs.com/package/@weconjs/core)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @weconjs/core
12
+ # or
13
+ yarn add @weconjs/core
14
+ ```
15
+
16
+ ## Features
17
+
18
+ - 🔧 **Configuration System** - Mode-based config with inheritance
19
+ - 📦 **Module System** - Auto-discovery and dependency resolution
20
+ - 🌐 **i18n Support** - Auto-load translations from modules
21
+ - 🔌 **Socket.IO Integration** - Auto-discover socket handlers
22
+ - 🗄️ **Database Connection** - MongoDB/Mongoose integration
23
+ - 🚀 **Server Factory** - Express server setup in one call
24
+
25
+ ## Quick Start
26
+
27
+ ### Define Configuration
28
+
29
+ ```typescript
30
+ // wecon.config.ts
31
+ import { defineConfig } from '@weconjs/core';
32
+
33
+ export default defineConfig({
34
+ app: {
35
+ name: 'my-api',
36
+ version: '1.0.0',
37
+ },
38
+ port: 3000,
39
+ modes: {
40
+ development: {
41
+ database: { uri: 'mongodb://localhost:27017/myapp' },
42
+ },
43
+ production: {
44
+ database: { uri: process.env.DATABASE_URL },
45
+ },
46
+ },
47
+ });
48
+ ```
49
+
50
+ ### Define Modules
51
+
52
+ ```typescript
53
+ // src/modules/users/users.module.ts
54
+ import { defineModule } from '@weconjs/core';
55
+
56
+ export default defineModule({
57
+ name: 'users',
58
+ description: 'User management module',
59
+ routes: userRoutes,
60
+ onInit: async (ctx) => {
61
+ console.log('Users module initialized');
62
+ },
63
+ });
64
+ ```
65
+
66
+ ### Create Application
67
+
68
+ ```typescript
69
+ // src/index.ts
70
+ import { createWecon, resolveConfig, loadConfig, createDatabaseConnection } from '@weconjs/core';
71
+
72
+ const config = resolveConfig(await loadConfig(), process.env.NODE_ENV);
73
+ const db = await createDatabaseConnection({ uri: config.database.uri });
74
+
75
+ const app = await createWecon({
76
+ config,
77
+ modules: [usersModule, authModule],
78
+ hooks: {
79
+ onBoot: async () => {
80
+ await db.connect();
81
+ },
82
+ },
83
+ });
84
+
85
+ await app.start();
86
+ ```
87
+
88
+ ## API Reference
89
+
90
+ ### Configuration
91
+
92
+ - `defineConfig(config)` - Define application configuration
93
+ - `resolveConfig(config, mode)` - Resolve config for a specific mode
94
+ - `loadConfig()` - Load config from `wecon.config.ts`
95
+
96
+ ### Modules
97
+
98
+ - `defineModule(definition)` - Define a module
99
+ - `loadModule(path)` - Load a module from file
100
+ - `resolveModuleDependencies(modules)` - Topologically sort modules
101
+
102
+ ### Server
103
+
104
+ - `createWecon(options)` - Create Wecon application
105
+ - `initI18n(modulesDir)` - Initialize i18n middleware
106
+ - `createDatabaseConnection(options)` - Create database connection
107
+
108
+ ### Socket.IO
109
+
110
+ - `setupSocketIO(httpServer, modulesDir, options)` - Setup Socket.IO
111
+ - `discoverSocketHandlers(modulesDir)` - Find socket handlers
112
+ - `discoverSocketMiddleware(modulesDir)` - Find socket middleware
113
+
114
+ ### Context
115
+
116
+ - `createContext(options)` - Create application context
117
+ - `createLogger(options)` - Create logger instance
118
+
119
+ ## Testing
120
+
121
+ ```bash
122
+ yarn test # Run tests
123
+ yarn build # Build package
124
+ ```
125
+
126
+ ## License
127
+
128
+ MIT © [weconjs](https://github.com/weconjs)
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @wecon/core - defineConfig
3
+ *
4
+ * Creates a type-safe Wecon configuration object.
5
+ * Supports mode inheritance, feature flags, and lifecycle hooks.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { defineConfig } from '@wecon/core';
10
+ *
11
+ * export default defineConfig({
12
+ * app: { name: 'my-app', version: '1.0.0' },
13
+ * modes: {
14
+ * development: { port: 3001, logging: { level: 'debug' } },
15
+ * production: { port: 8080, logging: { level: 'warn' } },
16
+ * },
17
+ * modules: ['./modules/auth', './modules/users'],
18
+ * features: {
19
+ * socket: { enabled: true },
20
+ * fieldShield: { enabled: true, strict: true },
21
+ * },
22
+ * });
23
+ * ```
24
+ */
25
+ import type { WeconConfig, ResolvedConfig } from "./types.js";
26
+ /**
27
+ * Define a Wecon configuration
28
+ *
29
+ * @param config - The configuration object
30
+ * @returns The validated configuration
31
+ */
32
+ export declare function defineConfig(config: WeconConfig): WeconConfig;
33
+ /**
34
+ * Resolve configuration for a specific mode
35
+ *
36
+ * @param config - The Wecon configuration
37
+ * @param mode - The mode to resolve (defaults to NODE_ENV or 'development')
38
+ * @returns The fully resolved configuration
39
+ */
40
+ export declare function resolveConfig(config: WeconConfig, mode?: string): ResolvedConfig;
41
+ /**
42
+ * Load and resolve configuration from a file path
43
+ *
44
+ * @param configPath - Path to wecon.config.ts
45
+ * @param mode - Optional mode override
46
+ */
47
+ export declare function loadConfig(configPath: string, mode?: string): Promise<ResolvedConfig>;
48
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAc,MAAM,YAAY,CAAC;AAiC1E;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAiB7D;AAwED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,EACnB,IAAI,CAAC,EAAE,MAAM,GACZ,cAAc,CAoChB;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,cAAc,CAAC,CAYzB"}
package/dist/config.js ADDED
@@ -0,0 +1,182 @@
1
+ /**
2
+ * @wecon/core - defineConfig
3
+ *
4
+ * Creates a type-safe Wecon configuration object.
5
+ * Supports mode inheritance, feature flags, and lifecycle hooks.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { defineConfig } from '@wecon/core';
10
+ *
11
+ * export default defineConfig({
12
+ * app: { name: 'my-app', version: '1.0.0' },
13
+ * modes: {
14
+ * development: { port: 3001, logging: { level: 'debug' } },
15
+ * production: { port: 8080, logging: { level: 'warn' } },
16
+ * },
17
+ * modules: ['./modules/auth', './modules/users'],
18
+ * features: {
19
+ * socket: { enabled: true },
20
+ * fieldShield: { enabled: true, strict: true },
21
+ * },
22
+ * });
23
+ * ```
24
+ */
25
+ /**
26
+ * Default configuration values
27
+ */
28
+ const DEFAULT_CONFIG = {
29
+ port: 3001,
30
+ database: {
31
+ debug: false,
32
+ mongoose: {
33
+ protocol: "mongodb",
34
+ host: "localhost",
35
+ port: 27017,
36
+ database: "wecon-dev",
37
+ },
38
+ },
39
+ logging: {
40
+ level: "info",
41
+ enableConsole: true,
42
+ enableFile: false,
43
+ },
44
+ https: {
45
+ enabled: false,
46
+ },
47
+ features: {
48
+ fieldShield: { enabled: false, strict: false },
49
+ i18n: { enabled: true, defaultLocale: "en" },
50
+ swagger: { enabled: false },
51
+ socket: { enabled: false },
52
+ },
53
+ modules: [],
54
+ };
55
+ /**
56
+ * Define a Wecon configuration
57
+ *
58
+ * @param config - The configuration object
59
+ * @returns The validated configuration
60
+ */
61
+ export function defineConfig(config) {
62
+ // Validate required fields
63
+ if (!config.app?.name) {
64
+ throw new Error("[Wecon] app.name is required in wecon.config.ts");
65
+ }
66
+ // Return the config (validation happens at resolve time)
67
+ return {
68
+ app: {
69
+ name: config.app.name,
70
+ version: config.app.version ?? "1.0.0",
71
+ },
72
+ modes: config.modes ?? {},
73
+ modules: config.modules ?? [],
74
+ features: config.features ?? {},
75
+ hooks: config.hooks ?? {},
76
+ };
77
+ }
78
+ /**
79
+ * Deep merge two objects
80
+ */
81
+ function deepMerge(target, source) {
82
+ const result = { ...target };
83
+ for (const key in source) {
84
+ const sourceValue = source[key];
85
+ const targetValue = target[key];
86
+ if (sourceValue &&
87
+ typeof sourceValue === "object" &&
88
+ !Array.isArray(sourceValue) &&
89
+ targetValue &&
90
+ typeof targetValue === "object" &&
91
+ !Array.isArray(targetValue)) {
92
+ result[key] = deepMerge(targetValue, sourceValue);
93
+ }
94
+ else if (sourceValue !== undefined) {
95
+ result[key] = sourceValue;
96
+ }
97
+ }
98
+ return result;
99
+ }
100
+ /**
101
+ * Resolve a mode configuration with inheritance
102
+ *
103
+ * @param modes - All mode configurations
104
+ * @param modeName - The mode to resolve
105
+ * @param visited - Set of visited modes (for circular detection)
106
+ */
107
+ function resolveMode(modes, modeName, visited = new Set()) {
108
+ if (visited.has(modeName)) {
109
+ throw new Error(`[Wecon] Circular mode inheritance detected: ${Array.from(visited).join(" -> ")} -> ${modeName}`);
110
+ }
111
+ const mode = modes[modeName];
112
+ if (!mode) {
113
+ throw new Error(`[Wecon] Mode "${modeName}" not found in configuration`);
114
+ }
115
+ visited.add(modeName);
116
+ // If this mode extends another, resolve the parent first
117
+ if (mode.extends) {
118
+ const parentMode = resolveMode(modes, mode.extends, visited);
119
+ const { extends: _, ...modeWithoutExtends } = mode;
120
+ return deepMerge(parentMode, modeWithoutExtends);
121
+ }
122
+ return mode;
123
+ }
124
+ /**
125
+ * Resolve configuration for a specific mode
126
+ *
127
+ * @param config - The Wecon configuration
128
+ * @param mode - The mode to resolve (defaults to NODE_ENV or 'development')
129
+ * @returns The fully resolved configuration
130
+ */
131
+ export function resolveConfig(config, mode) {
132
+ const targetMode = mode ?? process.env.NODE_ENV ?? "development";
133
+ // Start with defaults
134
+ let resolved = {
135
+ app: {
136
+ name: config.app.name,
137
+ version: config.app.version ?? "1.0.0",
138
+ },
139
+ mode: targetMode,
140
+ port: DEFAULT_CONFIG.port,
141
+ database: { ...DEFAULT_CONFIG.database },
142
+ logging: { ...DEFAULT_CONFIG.logging },
143
+ https: { ...DEFAULT_CONFIG.https },
144
+ features: { ...DEFAULT_CONFIG.features },
145
+ modules: [...(config.modules ?? [])],
146
+ };
147
+ // Apply mode-specific configuration if defined
148
+ if (config.modes && config.modes[targetMode]) {
149
+ const modeConfig = resolveMode(config.modes, targetMode);
150
+ resolved = deepMerge(resolved, {
151
+ port: modeConfig.port,
152
+ database: modeConfig.database,
153
+ logging: modeConfig.logging,
154
+ https: modeConfig.https,
155
+ });
156
+ }
157
+ // Merge features
158
+ if (config.features) {
159
+ resolved.features = deepMerge(resolved.features, config.features);
160
+ }
161
+ return resolved;
162
+ }
163
+ /**
164
+ * Load and resolve configuration from a file path
165
+ *
166
+ * @param configPath - Path to wecon.config.ts
167
+ * @param mode - Optional mode override
168
+ */
169
+ export async function loadConfig(configPath, mode) {
170
+ try {
171
+ const configModule = await import(configPath);
172
+ const config = configModule.default ?? configModule;
173
+ return resolveConfig(config, mode);
174
+ }
175
+ catch (error) {
176
+ if (error.code === "ERR_MODULE_NOT_FOUND") {
177
+ throw new Error(`[Wecon] Configuration file not found: ${configPath}`);
178
+ }
179
+ throw error;
180
+ }
181
+ }
182
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH;;GAEG;AACH,MAAM,cAAc,GAA4B;IAC9C,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE;QACR,KAAK,EAAE,KAAK;QACZ,QAAQ,EAAE;YACR,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,KAAK;YACX,QAAQ,EAAE,WAAW;SACtB;KACF;IACD,OAAO,EAAE;QACP,KAAK,EAAE,MAAM;QACb,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,KAAK;KAClB;IACD,KAAK,EAAE;QACL,OAAO,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Q,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,UAAkB,EAClB,IAAa;IAEb,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAgB,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC;QAEjE,OAAO,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;YACrE,MAAM,IAAI,KAAK,CAAC,yCAAyC,UAAU,EAAE,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @wecon/core - Context
3
+ *
4
+ * Creates and manages the Wecon application context.
5
+ * The context is passed to handlers, middleware, and hooks.
6
+ */
7
+ import type { Application } from "express";
8
+ import type { Server } from "socket.io";
9
+ import type { WeconContext, ResolvedConfig, WeconLogger } from "./types.js";
10
+ /**
11
+ * Create a Wecon application context
12
+ *
13
+ * @param options - Context options
14
+ * @returns The application context
15
+ */
16
+ export declare function createContext(options: {
17
+ config: ResolvedConfig;
18
+ app: Application;
19
+ io?: Server;
20
+ logger?: WeconLogger;
21
+ }): WeconContext;
22
+ /**
23
+ * Enhance the logger based on configuration
24
+ *
25
+ * @param config - The resolved configuration
26
+ * @param customLogger - Optional custom logger implementation
27
+ */
28
+ export declare function createLogger(config: ResolvedConfig, customLogger?: WeconLogger): WeconLogger;
29
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EAEZ,MAAM,YAAY,CAAC;AAYpB;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE;IACrC,MAAM,EAAE,cAAc,CAAC;IACvB,GAAG,EAAE,WAAW,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GAAG,YAAY,CAuBf;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,cAAc,EACtB,YAAY,CAAC,EAAE,WAAW,GACzB,WAAW,CAiCb"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @wecon/core - Context
3
+ *
4
+ * Creates and manages the Wecon application context.
5
+ * The context is passed to handlers, middleware, and hooks.
6
+ */
7
+ /**
8
+ * Default logger implementation (console-based)
9
+ */
10
+ const defaultLogger = {
11
+ debug: (message, meta) => console.debug(`[DEBUG] ${message}`, meta ?? ""),
12
+ info: (message, meta) => console.info(`[INFO] ${message}`, meta ?? ""),
13
+ warn: (message, meta) => console.warn(`[WARN] ${message}`, meta ?? ""),
14
+ error: (message, meta) => console.error(`[ERROR] ${message}`, meta ?? ""),
15
+ };
16
+ /**
17
+ * Create a Wecon application context
18
+ *
19
+ * @param options - Context options
20
+ * @returns The application context
21
+ */
22
+ export function createContext(options) {
23
+ const services = {};
24
+ const ctx = {
25
+ config: options.config,
26
+ app: options.app,
27
+ io: options.io,
28
+ logger: options.logger ?? defaultLogger,
29
+ services,
30
+ getService(name) {
31
+ return services[name];
32
+ },
33
+ registerService(name, service) {
34
+ if (services[name]) {
35
+ ctx.logger.warn(`Service "${name}" is being overwritten`);
36
+ }
37
+ services[name] = service;
38
+ },
39
+ };
40
+ return ctx;
41
+ }
42
+ /**
43
+ * Enhance the logger based on configuration
44
+ *
45
+ * @param config - The resolved configuration
46
+ * @param customLogger - Optional custom logger implementation
47
+ */
48
+ export function createLogger(config, customLogger) {
49
+ if (customLogger) {
50
+ return customLogger;
51
+ }
52
+ const level = config.logging.level ?? "info";
53
+ const levels = ["debug", "info", "warn", "error"];
54
+ const minLevel = levels.indexOf(level);
55
+ const shouldLog = (logLevel) => levels.indexOf(logLevel) >= minLevel;
56
+ return {
57
+ debug: (message, meta) => {
58
+ if (shouldLog("debug")) {
59
+ console.debug(`[DEBUG] ${message}`, meta ?? "");
60
+ }
61
+ },
62
+ info: (message, meta) => {
63
+ if (shouldLog("info")) {
64
+ console.info(`[INFO] ${message}`, meta ?? "");
65
+ }
66
+ },
67
+ warn: (message, meta) => {
68
+ if (shouldLog("warn")) {
69
+ console.warn(`[WARN] ${message}`, meta ?? "");
70
+ }
71
+ },
72
+ error: (message, meta) => {
73
+ if (shouldLog("error")) {
74
+ console.error(`[ERROR] ${message}`, meta ?? "");
75
+ }
76
+ },
77
+ };
78
+ }
79
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;GAEG;AACH,MAAM,aAAa,GAAgB;IACjC,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;IACzE,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;IACtE,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;IACtE,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,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,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACvB,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;gBACvB,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACtB,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;gBACtB,OAAO,CAAC,IAAI,CAAC,UAAU,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACtB,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;gBACtB,OAAO,CAAC,IAAI,CAAC,UAAU,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QACD,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACvB,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;gBACvB,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @weconjs/core - Database Connection
3
+ *
4
+ * Manages database connections based on configuration.
5
+ */
6
+ /**
7
+ * Database connection options
8
+ */
9
+ export interface DatabaseOptions {
10
+ /**
11
+ * MongoDB connection URI
12
+ */
13
+ uri: string;
14
+ /**
15
+ * Database name
16
+ */
17
+ name?: string;
18
+ /**
19
+ * Connection options
20
+ */
21
+ options?: Record<string, unknown>;
22
+ }
23
+ /**
24
+ * Database connection instance
25
+ */
26
+ export interface DatabaseConnection {
27
+ /**
28
+ * Connect to the database
29
+ */
30
+ connect: () => Promise<void>;
31
+ /**
32
+ * Disconnect from the database
33
+ */
34
+ disconnect: () => Promise<void>;
35
+ /**
36
+ * Check if connected
37
+ */
38
+ isConnected: () => boolean;
39
+ }
40
+ /**
41
+ * Create a MongoDB database connection
42
+ *
43
+ * @param options - Database options
44
+ * @returns Database connection instance
45
+ */
46
+ export declare function createDatabaseConnection(options: DatabaseOptions): Promise<DatabaseConnection>;
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7B;;OAEG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,kBAAkB,CAAC,CA8B7B"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @weconjs/core - Database Connection
3
+ *
4
+ * Manages database connections based on configuration.
5
+ */
6
+ /**
7
+ * Create a MongoDB database connection
8
+ *
9
+ * @param options - Database options
10
+ * @returns Database connection instance
11
+ */
12
+ export async function createDatabaseConnection(options) {
13
+ let connected = false;
14
+ // Dynamic import mongoose to avoid bundling issues
15
+ const mongoose = await import("mongoose");
16
+ return {
17
+ async connect() {
18
+ try {
19
+ await mongoose.default.connect(options.uri, options.options);
20
+ connected = true;
21
+ console.log("[Wecon] Database connected successfully");
22
+ }
23
+ catch (err) {
24
+ console.error("[Wecon] Database connection failed:", err);
25
+ throw err;
26
+ }
27
+ },
28
+ async disconnect() {
29
+ if (connected) {
30
+ await mongoose.default.disconnect();
31
+ connected = false;
32
+ console.log("[Wecon] Database disconnected");
33
+ }
34
+ },
35
+ isConnected() {
36
+ return connected;
37
+ },
38
+ };
39
+ }
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0CH;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAwB;IAExB,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,mDAAmD;IACnD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IAE1C,OAAO;QACL,KAAK,CAAC,OAAO;YACX,IAAI,CAAC;gBACH,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,OAAc,CAAC,CAAC;gBACpE,SAAS,GAAG,IAAI,CAAC;gBACjB,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;YACzD,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;gBAC1D,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;QAED,KAAK,CAAC,UAAU;YACd,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;gBACpC,SAAS,GAAG,KAAK,CAAC;gBAClB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QAED,WAAW;YACT,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @weconjs/core - i18n Loader
3
+ *
4
+ * Auto-discovers and loads translation files from module i18n/ directories.
5
+ */
6
+ /**
7
+ * i18n resource structure
8
+ */
9
+ export interface I18nResources {
10
+ [namespace: string]: {
11
+ [language: string]: Record<string, any>;
12
+ };
13
+ }
14
+ /**
15
+ * Load translations from all module i18n directories
16
+ *
17
+ * @param modulesDir - Path to the modules directory
18
+ * @returns Loaded translation resources
19
+ */
20
+ export declare function loadI18nResources(modulesDir: string): Promise<I18nResources>;
21
+ /**
22
+ * Create i18n middleware for Express
23
+ *
24
+ * @param resources - Loaded translation resources
25
+ * @param defaultLanguage - Default language code
26
+ * @returns Express middleware function
27
+ */
28
+ export declare function createI18nMiddleware(resources: I18nResources, defaultLanguage?: string): (req: any, res: any, next: any) => void;
29
+ /**
30
+ * Initialize i18n for a Wecon application
31
+ *
32
+ * @param modulesDir - Path to modules directory
33
+ * @param defaultLanguage - Default language
34
+ * @returns Express middleware
35
+ */
36
+ export declare function initI18n(modulesDir: string, defaultLanguage?: string): Promise<(req: any, res: any, next: any) => void>;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/i18n/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,SAAS,EAAE,MAAM,GAAG;QACnB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACzC,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAqClF;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,aAAa,EACxB,eAAe,GAAE,MAAa,IAEtB,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG,UAoCtC;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,GAAE,MAAa,iBA7ClE,GAAG,OAAO,GAAG,QAAQ,GAAG,WAgDtC"}