@morojs/moro 1.5.17 → 1.6.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.
Files changed (138) hide show
  1. package/README.md +48 -65
  2. package/dist/core/auth/morojs-adapter.js +12 -16
  3. package/dist/core/auth/morojs-adapter.js.map +1 -1
  4. package/dist/core/config/file-loader.d.ts +5 -0
  5. package/dist/core/config/file-loader.js +171 -0
  6. package/dist/core/config/file-loader.js.map +1 -1
  7. package/dist/core/config/index.d.ts +10 -39
  8. package/dist/core/config/index.js +29 -66
  9. package/dist/core/config/index.js.map +1 -1
  10. package/dist/core/config/loader.d.ts +7 -0
  11. package/dist/core/config/loader.js +269 -0
  12. package/dist/core/config/loader.js.map +1 -0
  13. package/dist/core/config/schema.js +31 -41
  14. package/dist/core/config/schema.js.map +1 -1
  15. package/dist/core/config/utils.d.ts +2 -9
  16. package/dist/core/config/utils.js +32 -19
  17. package/dist/core/config/utils.js.map +1 -1
  18. package/dist/core/config/validation.d.ts +17 -0
  19. package/dist/core/config/validation.js +131 -0
  20. package/dist/core/config/validation.js.map +1 -0
  21. package/dist/core/database/adapters/mongodb.d.ts +0 -10
  22. package/dist/core/database/adapters/mongodb.js +2 -23
  23. package/dist/core/database/adapters/mongodb.js.map +1 -1
  24. package/dist/core/database/adapters/mysql.d.ts +0 -11
  25. package/dist/core/database/adapters/mysql.js +0 -1
  26. package/dist/core/database/adapters/mysql.js.map +1 -1
  27. package/dist/core/database/adapters/postgresql.d.ts +1 -9
  28. package/dist/core/database/adapters/postgresql.js +1 -1
  29. package/dist/core/database/adapters/postgresql.js.map +1 -1
  30. package/dist/core/database/adapters/redis.d.ts +0 -9
  31. package/dist/core/database/adapters/redis.js +4 -14
  32. package/dist/core/database/adapters/redis.js.map +1 -1
  33. package/dist/core/framework.d.ts +7 -6
  34. package/dist/core/framework.js +16 -131
  35. package/dist/core/framework.js.map +1 -1
  36. package/dist/core/http/http-server.d.ts +0 -12
  37. package/dist/core/http/http-server.js +23 -151
  38. package/dist/core/http/http-server.js.map +1 -1
  39. package/dist/core/http/router.d.ts +0 -12
  40. package/dist/core/http/router.js +36 -114
  41. package/dist/core/http/router.js.map +1 -1
  42. package/dist/core/logger/filters.js +4 -12
  43. package/dist/core/logger/filters.js.map +1 -1
  44. package/dist/core/logger/index.d.ts +1 -1
  45. package/dist/core/logger/index.js +1 -2
  46. package/dist/core/logger/index.js.map +1 -1
  47. package/dist/core/logger/logger.d.ts +13 -29
  48. package/dist/core/logger/logger.js +203 -380
  49. package/dist/core/logger/logger.js.map +1 -1
  50. package/dist/core/logger/outputs.js +2 -0
  51. package/dist/core/logger/outputs.js.map +1 -1
  52. package/dist/core/middleware/built-in/auth.js +17 -88
  53. package/dist/core/middleware/built-in/auth.js.map +1 -1
  54. package/dist/core/middleware/built-in/cache.js +1 -3
  55. package/dist/core/middleware/built-in/cache.js.map +1 -1
  56. package/dist/core/middleware/built-in/index.d.ts +0 -1
  57. package/dist/core/middleware/built-in/index.js +1 -6
  58. package/dist/core/middleware/built-in/index.js.map +1 -1
  59. package/dist/core/middleware/built-in/request-logger.js +2 -3
  60. package/dist/core/middleware/built-in/request-logger.js.map +1 -1
  61. package/dist/core/middleware/built-in/sse.js +7 -9
  62. package/dist/core/middleware/built-in/sse.js.map +1 -1
  63. package/dist/core/modules/auto-discovery.d.ts +0 -17
  64. package/dist/core/modules/auto-discovery.js +12 -367
  65. package/dist/core/modules/auto-discovery.js.map +1 -1
  66. package/dist/core/modules/modules.js +2 -12
  67. package/dist/core/modules/modules.js.map +1 -1
  68. package/dist/core/networking/adapters/ws-adapter.d.ts +1 -1
  69. package/dist/core/networking/adapters/ws-adapter.js +2 -2
  70. package/dist/core/networking/adapters/ws-adapter.js.map +1 -1
  71. package/dist/core/networking/service-discovery.js +7 -7
  72. package/dist/core/networking/service-discovery.js.map +1 -1
  73. package/dist/core/routing/index.d.ts +0 -20
  74. package/dist/core/routing/index.js +13 -178
  75. package/dist/core/routing/index.js.map +1 -1
  76. package/dist/core/runtime/node-adapter.js +6 -12
  77. package/dist/core/runtime/node-adapter.js.map +1 -1
  78. package/dist/moro.d.ts +0 -48
  79. package/dist/moro.js +148 -456
  80. package/dist/moro.js.map +1 -1
  81. package/dist/types/config.d.ts +2 -58
  82. package/dist/types/core.d.ts +40 -34
  83. package/dist/types/http.d.ts +1 -16
  84. package/dist/types/logger.d.ts +0 -7
  85. package/dist/types/module.d.ts +0 -11
  86. package/package.json +2 -2
  87. package/src/core/auth/morojs-adapter.ts +13 -18
  88. package/src/core/config/file-loader.ts +233 -0
  89. package/src/core/config/index.ts +32 -77
  90. package/src/core/config/loader.ts +633 -0
  91. package/src/core/config/schema.ts +31 -41
  92. package/src/core/config/utils.ts +29 -22
  93. package/src/core/config/validation.ts +140 -0
  94. package/src/core/database/README.md +16 -26
  95. package/src/core/database/adapters/mongodb.ts +2 -30
  96. package/src/core/database/adapters/mysql.ts +0 -14
  97. package/src/core/database/adapters/postgresql.ts +2 -12
  98. package/src/core/database/adapters/redis.ts +4 -27
  99. package/src/core/framework.ts +23 -163
  100. package/src/core/http/http-server.ts +36 -176
  101. package/src/core/http/router.ts +38 -127
  102. package/src/core/logger/filters.ts +4 -12
  103. package/src/core/logger/index.ts +0 -1
  104. package/src/core/logger/logger.ts +216 -427
  105. package/src/core/logger/outputs.ts +2 -0
  106. package/src/core/middleware/built-in/auth.ts +17 -98
  107. package/src/core/middleware/built-in/cache.ts +1 -3
  108. package/src/core/middleware/built-in/index.ts +0 -8
  109. package/src/core/middleware/built-in/request-logger.ts +1 -3
  110. package/src/core/middleware/built-in/sse.ts +7 -9
  111. package/src/core/modules/auto-discovery.ts +13 -476
  112. package/src/core/modules/modules.ts +9 -20
  113. package/src/core/networking/adapters/ws-adapter.ts +5 -2
  114. package/src/core/networking/service-discovery.ts +7 -6
  115. package/src/core/routing/index.ts +14 -198
  116. package/src/core/runtime/node-adapter.ts +6 -12
  117. package/src/moro.ts +166 -554
  118. package/src/types/config.ts +2 -59
  119. package/src/types/core.ts +45 -47
  120. package/src/types/http.ts +1 -23
  121. package/src/types/logger.ts +0 -9
  122. package/src/types/module.ts +0 -12
  123. package/dist/core/config/config-manager.d.ts +0 -44
  124. package/dist/core/config/config-manager.js +0 -114
  125. package/dist/core/config/config-manager.js.map +0 -1
  126. package/dist/core/config/config-sources.d.ts +0 -21
  127. package/dist/core/config/config-sources.js +0 -502
  128. package/dist/core/config/config-sources.js.map +0 -1
  129. package/dist/core/config/config-validator.d.ts +0 -21
  130. package/dist/core/config/config-validator.js +0 -765
  131. package/dist/core/config/config-validator.js.map +0 -1
  132. package/dist/core/middleware/built-in/jwt-helpers.d.ts +0 -118
  133. package/dist/core/middleware/built-in/jwt-helpers.js +0 -221
  134. package/dist/core/middleware/built-in/jwt-helpers.js.map +0 -1
  135. package/src/core/config/config-manager.ts +0 -133
  136. package/src/core/config/config-sources.ts +0 -596
  137. package/src/core/config/config-validator.ts +0 -1078
  138. package/src/core/middleware/built-in/jwt-helpers.ts +0 -240
@@ -2,20 +2,14 @@
2
2
 
3
3
  import { AppConfig } from '../../types/config';
4
4
 
5
- // Minimal default configuration - performance-focused, most things opt-in
5
+ // Default configuration values
6
6
  export const DEFAULT_CONFIG: AppConfig = {
7
7
  server: {
8
8
  port: 3001,
9
9
  host: 'localhost',
10
+ environment: 'development',
10
11
  maxConnections: 1000,
11
12
  timeout: 30000,
12
- bodySizeLimit: '10mb',
13
- requestTracking: {
14
- enabled: true, // Enable by default for debugging
15
- },
16
- errorBoundary: {
17
- enabled: true, // Always enabled for safety
18
- },
19
13
  },
20
14
  serviceDiscovery: {
21
15
  enabled: false,
@@ -25,38 +19,33 @@ export const DEFAULT_CONFIG: AppConfig = {
25
19
  healthCheckInterval: 30000,
26
20
  retryAttempts: 3,
27
21
  },
28
- database: {},
22
+ database: {
23
+ redis: {
24
+ url: 'redis://localhost:6379',
25
+ maxRetries: 3,
26
+ retryDelay: 1000,
27
+ keyPrefix: 'moro:',
28
+ },
29
+ },
29
30
  modules: {
30
31
  cache: {
31
- enabled: false, // Opt-in for better performance
32
+ enabled: true,
32
33
  defaultTtl: 300,
33
34
  maxSize: 1000,
34
35
  strategy: 'lru',
35
36
  },
36
37
  rateLimit: {
37
- enabled: false, // Opt-in to avoid unnecessary overhead
38
+ enabled: true,
38
39
  defaultRequests: 100,
39
40
  defaultWindow: 60000,
40
41
  skipSuccessfulRequests: false,
41
42
  skipFailedRequests: false,
42
43
  },
43
44
  validation: {
44
- enabled: false,
45
+ enabled: true,
45
46
  stripUnknown: true,
46
47
  abortEarly: false,
47
48
  },
48
- autoDiscovery: {
49
- enabled: true, // Enable by default for better DX
50
- paths: ['./modules', './src/modules'],
51
- patterns: ['**/*.module.{ts,js}', '**/index.{ts,js}', '**/*.config.{ts,js}'],
52
- recursive: true,
53
- loadingStrategy: 'eager',
54
- watchForChanges: false, // Opt-in for development
55
- ignorePatterns: ['**/*.test.{ts,js}', '**/*.spec.{ts,js}', '**/node_modules/**'],
56
- loadOrder: 'dependency',
57
- failOnError: false, // Graceful degradation
58
- maxDepth: 5,
59
- },
60
49
  },
61
50
  logging: {
62
51
  level: 'info',
@@ -80,14 +69,14 @@ export const DEFAULT_CONFIG: AppConfig = {
80
69
  },
81
70
  security: {
82
71
  cors: {
83
- enabled: false, // Opt-in for better performance
72
+ enabled: true,
84
73
  origin: '*',
85
74
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
86
75
  allowedHeaders: ['Content-Type', 'Authorization'],
87
76
  credentials: false,
88
77
  },
89
78
  helmet: {
90
- enabled: false, // Opt-in for better performance
79
+ enabled: true,
91
80
  contentSecurityPolicy: true,
92
81
  hsts: true,
93
82
  noSniff: true,
@@ -101,15 +90,26 @@ export const DEFAULT_CONFIG: AppConfig = {
101
90
  },
102
91
  },
103
92
  },
104
- external: {},
93
+ external: {
94
+ stripe: {
95
+ apiVersion: '2023-10-16',
96
+ },
97
+ paypal: {
98
+ environment: 'sandbox',
99
+ },
100
+ smtp: {
101
+ port: 587,
102
+ secure: false,
103
+ },
104
+ },
105
105
  performance: {
106
106
  compression: {
107
- enabled: false, // Opt-in to avoid overhead
107
+ enabled: true,
108
108
  level: 6,
109
109
  threshold: 1024,
110
110
  },
111
111
  circuitBreaker: {
112
- enabled: false, // Opt-in to avoid overhead
112
+ enabled: true,
113
113
  failureThreshold: 5,
114
114
  resetTimeout: 60000,
115
115
  monitoringPeriod: 10000,
@@ -117,23 +117,13 @@ export const DEFAULT_CONFIG: AppConfig = {
117
117
  clustering: {
118
118
  enabled: false,
119
119
  workers: 1,
120
- memoryPerWorkerGB: undefined,
121
120
  },
122
121
  },
123
- websocket: {
124
- enabled: false, // Opt-in - user must explicitly enable WebSockets
125
- },
126
122
  };
127
123
 
128
- // Schema validation is now handled by config-validator.ts
129
- // This export is kept for backward compatibility only
130
- // Note: For actual validation, use validateConfig() from config-validator.ts directly
124
+ // Simple compatibility export - just return the config as-is
131
125
  export const ConfigSchema = {
132
- parse: (data: any): AppConfig => {
133
- // Simple pass-through for backward compatibility
134
- // Real validation happens in the config loading pipeline
135
- return data as AppConfig;
136
- },
126
+ parse: (data: any): AppConfig => data as AppConfig,
137
127
  };
138
128
 
139
129
  // Re-export types for backward compatibility
@@ -1,26 +1,28 @@
1
1
  // Configuration Utilities for Modules and Environment Handling
2
2
  import { AppConfig } from './schema';
3
3
  import { createFrameworkLogger } from '../logger';
4
- import { getGlobalConfig } from './config-manager';
5
4
 
6
5
  const logger = createFrameworkLogger('ConfigUtils');
7
6
 
7
+ // Global configuration store
8
+ let appConfig: AppConfig | null = null;
9
+
8
10
  /**
9
- * Set the global configuration (deprecated - for backward compatibility only)
10
- * @deprecated Use the new immutable config system instead
11
+ * Set the global configuration (used by framework initialization)
11
12
  */
12
- export function setConfig(_config: AppConfig): void {
13
- logger.warn(
14
- 'setConfig() is deprecated. Configuration is now immutable after createApp() initialization.'
15
- );
13
+ export function setConfig(config: AppConfig): void {
14
+ appConfig = config;
15
+ logger.debug('Global configuration updated');
16
16
  }
17
17
 
18
18
  /**
19
19
  * Get the global configuration
20
- * This now delegates to the new config manager
21
20
  */
22
21
  export function getConfig(): AppConfig {
23
- return getGlobalConfig();
22
+ if (!appConfig) {
23
+ throw new Error('Configuration not initialized. Call loadConfig() first.');
24
+ }
25
+ return appConfig;
24
26
  }
25
27
 
26
28
  /**
@@ -61,7 +63,6 @@ function coerceEnvironmentValue(value: string): any {
61
63
 
62
64
  /**
63
65
  * Create module-specific configuration with environment override support
64
- * This now uses the new immutable config system
65
66
  */
66
67
  export function createModuleConfig<T>(
67
68
  schema: { parse: (data: any) => T },
@@ -71,12 +72,10 @@ export function createModuleConfig<T>(
71
72
  // Try to get global config, but don't fail if not initialized
72
73
  let globalConfig = {};
73
74
  try {
75
+ const { getGlobalConfig } = require('./index');
74
76
  globalConfig = getGlobalConfig();
75
77
  } catch {
76
78
  // Global config not initialized - use empty object (module config can still work independently)
77
- logger.debug(
78
- `Global config not available for module config with prefix ${envPrefix}, using defaults only`
79
- );
80
79
  globalConfig = {};
81
80
  }
82
81
 
@@ -105,7 +104,7 @@ export function createModuleConfig<T>(
105
104
  // Priority: environment variables > global config > default config
106
105
  const mergedConfig = {
107
106
  ...defaultConfig,
108
- ...globalConfig, // Now uses the new immutable config system
107
+ ...globalConfig, // Now actually using global config!
109
108
  ...envConfig,
110
109
  };
111
110
 
@@ -209,10 +208,9 @@ export function envVar(prefix: string, name: string): string {
209
208
 
210
209
  /**
211
210
  * Get configuration value with dot notation
212
- * This now delegates to the new config manager
213
211
  */
214
212
  export function getConfigValue(path: string): any {
215
- const config = getGlobalConfig();
213
+ const config = getConfig();
216
214
 
217
215
  return path.split('.').reduce((obj, key) => {
218
216
  return obj && obj[key] !== undefined ? obj[key] : undefined;
@@ -221,24 +219,33 @@ export function getConfigValue(path: string): any {
221
219
 
222
220
  /**
223
221
  * Check if we're in development environment
224
- * Now reads NODE_ENV directly for consistency with Node.js ecosystem
225
222
  */
226
223
  export function isDevelopment(): boolean {
227
- return process.env.NODE_ENV === 'development';
224
+ try {
225
+ return getConfig().server.environment === 'development';
226
+ } catch {
227
+ return process.env.NODE_ENV === 'development';
228
+ }
228
229
  }
229
230
 
230
231
  /**
231
232
  * Check if we're in production environment
232
- * Now reads NODE_ENV directly for consistency with Node.js ecosystem
233
233
  */
234
234
  export function isProduction(): boolean {
235
- return process.env.NODE_ENV === 'production';
235
+ try {
236
+ return getConfig().server.environment === 'production';
237
+ } catch {
238
+ return process.env.NODE_ENV === 'production';
239
+ }
236
240
  }
237
241
 
238
242
  /**
239
243
  * Check if we're in staging environment
240
- * Now reads NODE_ENV directly for consistency with Node.js ecosystem
241
244
  */
242
245
  export function isStaging(): boolean {
243
- return process.env.NODE_ENV === 'staging';
246
+ try {
247
+ return getConfig().server.environment === 'staging';
248
+ } catch {
249
+ return process.env.NODE_ENV === 'staging';
250
+ }
244
251
  }
@@ -0,0 +1,140 @@
1
+ // Configuration Validation Functions
2
+ // Validation for config system with simple TypeScript functions
3
+
4
+ export class ConfigValidationError extends Error {
5
+ constructor(
6
+ public field: string,
7
+ public value: unknown,
8
+ message: string
9
+ ) {
10
+ super(`Configuration validation failed for '${field}': ${message}`);
11
+ this.name = 'ConfigValidationError';
12
+ }
13
+ }
14
+
15
+ // Type-safe validation functions for configuration
16
+ export function validatePort(value: unknown, field = 'port'): number {
17
+ const num = Number(value);
18
+ if (isNaN(num) || num < 1 || num > 65535) {
19
+ throw new ConfigValidationError(field, value, 'Must be a number between 1 and 65535');
20
+ }
21
+ return num;
22
+ }
23
+
24
+ export function validateBoolean(value: unknown, field = 'boolean'): boolean {
25
+ if (value === 'true' || value === true) return true;
26
+ if (value === 'false' || value === false) return false;
27
+ if (value === '1' || value === 1) return true;
28
+ if (value === '0' || value === 0) return false;
29
+ throw new ConfigValidationError(field, value, 'Must be a boolean (true/false) or numeric (1/0)');
30
+ }
31
+
32
+ export function validateNumber(
33
+ value: unknown,
34
+ field = 'number',
35
+ options: { min?: number; max?: number } = {}
36
+ ): number {
37
+ const num = Number(value);
38
+ if (isNaN(num)) {
39
+ throw new ConfigValidationError(field, value, 'Must be a valid number');
40
+ }
41
+ if (options.min !== undefined && num < options.min) {
42
+ throw new ConfigValidationError(field, value, `Must be at least ${options.min}`);
43
+ }
44
+ if (options.max !== undefined && num > options.max) {
45
+ throw new ConfigValidationError(field, value, `Must be at most ${options.max}`);
46
+ }
47
+ return num;
48
+ }
49
+
50
+ export function validateString(value: unknown, field = 'string'): string {
51
+ if (typeof value !== 'string') {
52
+ throw new ConfigValidationError(field, value, 'Must be a string');
53
+ }
54
+ return value;
55
+ }
56
+
57
+ export function validateUrl(value: unknown, field = 'url'): string {
58
+ const str = validateString(value, field);
59
+ try {
60
+ new URL(str);
61
+ return str;
62
+ } catch {
63
+ throw new ConfigValidationError(field, value, 'Must be a valid URL');
64
+ }
65
+ }
66
+
67
+ export function validateEnum<T extends string>(
68
+ value: unknown,
69
+ validValues: readonly T[],
70
+ field = 'enum'
71
+ ): T {
72
+ const str = validateString(value, field);
73
+ if (!validValues.includes(str as T)) {
74
+ throw new ConfigValidationError(field, value, `Must be one of: ${validValues.join(', ')}`);
75
+ }
76
+ return str as T;
77
+ }
78
+
79
+ export function validateStringArray(value: unknown, field = 'string array'): string[] {
80
+ if (!Array.isArray(value)) {
81
+ // Try to parse comma-separated string
82
+ if (typeof value === 'string') {
83
+ return value
84
+ .split(',')
85
+ .map(s => s.trim())
86
+ .filter(s => s.length > 0);
87
+ }
88
+ throw new ConfigValidationError(field, value, 'Must be an array or comma-separated string');
89
+ }
90
+ return value.map((item, index) => validateString(item, `${field}[${index}]`));
91
+ }
92
+
93
+ export function validateOptional<T>(
94
+ value: unknown,
95
+ validator: (value: unknown, field: string) => T,
96
+ field: string
97
+ ): T | undefined {
98
+ if (value === undefined || value === null || value === '') {
99
+ return undefined;
100
+ }
101
+ return validator(value, field);
102
+ }
103
+
104
+ // Coercion helpers for environment variables
105
+ export function coerceEnvValue(value: string): unknown {
106
+ // Handle common patterns in environment variables
107
+
108
+ // Null/undefined
109
+ if (value === '' || value === 'null' || value === 'undefined') {
110
+ return undefined;
111
+ }
112
+
113
+ // Boolean
114
+ if (value === 'true' || value === 'false') {
115
+ return value === 'true';
116
+ }
117
+
118
+ // Number (but not if it starts with 0 - could be port, zip code, etc.)
119
+ if (/^-?\d+(\.\d+)?$/.test(value) && !value.startsWith('0')) {
120
+ const num = Number(value);
121
+ if (!isNaN(num)) {
122
+ return num;
123
+ }
124
+ }
125
+
126
+ // JSON (for complex objects/arrays)
127
+ if (
128
+ (value.startsWith('{') && value.endsWith('}')) ||
129
+ (value.startsWith('[') && value.endsWith(']'))
130
+ ) {
131
+ try {
132
+ return JSON.parse(value);
133
+ } catch {
134
+ // Not valid JSON, treat as string
135
+ }
136
+ }
137
+
138
+ // Return as string for all other cases
139
+ return value;
140
+ }
@@ -7,19 +7,16 @@ The MoroJS database module provides a pluggable adapter system for different dat
7
7
  ### SQL Databases
8
8
 
9
9
  #### MySQL Adapter
10
-
11
10
  - **Package Required**: `mysql2`
12
11
  - **Usage**: Production-ready with connection pooling
13
12
  - **Type**: `mysql`
14
13
 
15
- #### PostgreSQL Adapter
16
-
14
+ #### PostgreSQL Adapter
17
15
  - **Package Required**: `pg` and `@types/pg`
18
16
  - **Usage**: Full PostgreSQL feature support
19
17
  - **Type**: `postgresql`, `postgres`, or `pg`
20
18
 
21
19
  #### SQLite Adapter
22
-
23
20
  - **Package Required**: `better-sqlite3`
24
21
  - **Usage**: Lightweight, file-based database
25
22
  - **Type**: `sqlite` or `sqlite3`
@@ -27,13 +24,11 @@ The MoroJS database module provides a pluggable adapter system for different dat
27
24
  ### NoSQL Databases
28
25
 
29
26
  #### MongoDB Adapter
30
-
31
27
  - **Package Required**: `mongodb`
32
28
  - **Usage**: Document database with aggregation support
33
29
  - **Type**: `mongodb` or `mongo`
34
30
 
35
31
  #### Redis Adapter
36
-
37
32
  - **Package Required**: `ioredis`
38
33
  - **Usage**: In-memory key-value store with pub/sub
39
34
  - **Type**: `redis`
@@ -41,7 +36,6 @@ The MoroJS database module provides a pluggable adapter system for different dat
41
36
  ### ORM
42
37
 
43
38
  #### Drizzle Adapter
44
-
45
39
  - **Package Required**: `drizzle-orm` + database driver
46
40
  - **Usage**: Type-safe ORM with schema validation
47
41
  - **Type**: `drizzle` or `orm`
@@ -49,7 +43,7 @@ The MoroJS database module provides a pluggable adapter system for different dat
49
43
  ## Factory Pattern (Recommended)
50
44
 
51
45
  ```typescript
52
- import { createDatabaseAdapter } from '@morojs/moro';
46
+ import { createDatabaseAdapter } from 'moro';
53
47
 
54
48
  // SQL Databases
55
49
  const mysql = createDatabaseAdapter('mysql', {
@@ -58,7 +52,7 @@ const mysql = createDatabaseAdapter('mysql', {
58
52
  user: 'root',
59
53
  password: 'password',
60
54
  database: 'my_app',
61
- connectionLimit: 10,
55
+ connectionLimit: 10
62
56
  });
63
57
 
64
58
  const postgres = createDatabaseAdapter('postgresql', {
@@ -68,12 +62,12 @@ const postgres = createDatabaseAdapter('postgresql', {
68
62
  password: 'password',
69
63
  database: 'my_app',
70
64
  connectionLimit: 10,
71
- ssl: false,
65
+ ssl: false
72
66
  });
73
67
 
74
68
  const sqlite = createDatabaseAdapter('sqlite', {
75
69
  filename: 'app.db',
76
- memory: false,
70
+ memory: false
77
71
  });
78
72
 
79
73
  // NoSQL Databases
@@ -82,34 +76,34 @@ const mongodb = createDatabaseAdapter('mongodb', {
82
76
  port: 27017,
83
77
  database: 'my_app',
84
78
  username: 'user',
85
- password: 'password',
79
+ password: 'password'
86
80
  });
87
81
 
88
82
  const redis = createDatabaseAdapter('redis', {
89
83
  host: 'localhost',
90
84
  port: 6379,
91
85
  password: 'password',
92
- keyPrefix: 'myapp:',
86
+ keyPrefix: 'myapp:'
93
87
  });
94
88
 
95
89
  // ORM
96
90
  const drizzle = createDatabaseAdapter('drizzle', {
97
91
  database: drizzleInstance,
98
- schema: schemaObject,
92
+ schema: schemaObject
99
93
  });
100
94
  ```
101
95
 
102
96
  ## Direct Instantiation
103
97
 
104
98
  ```typescript
105
- import {
106
- MySQLAdapter,
107
- PostgreSQLAdapter,
99
+ import {
100
+ MySQLAdapter,
101
+ PostgreSQLAdapter,
108
102
  SQLiteAdapter,
109
103
  MongoDBAdapter,
110
104
  RedisAdapter,
111
105
  DrizzleAdapter
112
- } from '@morojs/moro';
106
+ } from 'moro';
113
107
 
114
108
  // SQL
115
109
  const mysql = new MySQLAdapter({ host: 'localhost', ... });
@@ -157,7 +151,7 @@ const updated = await db.update('users', { name: 'Jane' }, { id: 1 });
157
151
  const deleted = await db.delete('users', { id: 1 });
158
152
 
159
153
  // Transactions
160
- const result = await db.transaction(async tx => {
154
+ const result = await db.transaction(async (tx) => {
161
155
  const user = await tx.insert('users', userData);
162
156
  await tx.insert('profiles', { user_id: user.id, ...profileData });
163
157
  return user;
@@ -167,7 +161,6 @@ const result = await db.transaction(async tx => {
167
161
  ## Usage Examples
168
162
 
169
163
  ### SQL Operations
170
-
171
164
  ```typescript
172
165
  // Standard CRUD operations work across all SQL adapters
173
166
  const users = await db.query('SELECT * FROM users WHERE age > ?', [18]);
@@ -178,7 +171,6 @@ const deleted = await db.delete('users', { id: 1 });
178
171
  ```
179
172
 
180
173
  ### MongoDB Operations
181
-
182
174
  ```typescript
183
175
  // MongoDB uses collections instead of tables
184
176
  const users = await mongoDb.query('users'); // Get all
@@ -187,13 +179,12 @@ const user = await mongoDb.queryOne('users', { email: 'john@example.com' });
187
179
 
188
180
  // MongoDB-specific methods
189
181
  const stats = await mongoDb.aggregate('users', [
190
- { $group: { _id: null, avgAge: { $avg: '$age' } } },
182
+ { $group: { _id: null, avgAge: { $avg: '$age' } } }
191
183
  ]);
192
184
  await mongoDb.createIndex('users', { email: 1 }, { unique: true });
193
185
  ```
194
186
 
195
187
  ### Redis Operations
196
-
197
188
  ```typescript
198
189
  // Key-value operations
199
190
  await redisDb.set('user:123', userData, 3600); // with TTL
@@ -206,7 +197,6 @@ await redisDb.publish('notifications', message);
206
197
  ```
207
198
 
208
199
  ### Drizzle ORM Operations
209
-
210
200
  ```typescript
211
201
  // Type-safe queries (requires schema setup)
212
202
  const users = await drizzleDb.select('users').where(eq(schema.users.age, 25));
@@ -223,7 +213,7 @@ Choose and install the appropriate database package:
223
213
  ```bash
224
214
  # SQL Databases
225
215
  npm install mysql2 # MySQL
226
- npm install pg @types/pg # PostgreSQL
216
+ npm install pg @types/pg # PostgreSQL
227
217
  npm install better-sqlite3 # SQLite
228
218
 
229
219
  # NoSQL Databases
@@ -235,4 +225,4 @@ npm install drizzle-orm # Drizzle ORM
235
225
  # Plus the appropriate driver (mysql2, pg, better-sqlite3, etc.)
236
226
  ```
237
227
 
238
- The adapters will gracefully handle missing packages with helpful error messages.
228
+ The adapters will gracefully handle missing packages with helpful error messages.
@@ -11,16 +11,6 @@ interface MongoDBConfig {
11
11
  database?: string;
12
12
  authSource?: string;
13
13
  ssl?: boolean;
14
- tls?: {
15
- ca?: string;
16
- cert?: string;
17
- key?: string;
18
- passphrase?: string;
19
- insecure?: boolean;
20
- allowInvalidCertificates?: boolean;
21
- allowInvalidHostnames?: boolean;
22
- checkServerIdentity?: boolean;
23
- };
24
14
  replicaSet?: string;
25
15
  maxPoolSize?: number;
26
16
  minPoolSize?: number;
@@ -42,29 +32,11 @@ export class MongoDBAdapter implements DatabaseAdapter {
42
32
 
43
33
  const url = config.url || this.buildConnectionString(config);
44
34
 
45
- const clientOptions: any = {
35
+ this.client = new MongoClient(url, {
46
36
  maxPoolSize: config.maxPoolSize || 10,
47
37
  minPoolSize: config.minPoolSize || 0,
48
38
  ssl: config.ssl || false,
49
- };
50
-
51
- // Add TLS options if provided
52
- if (config.tls) {
53
- clientOptions.tls = true;
54
- if (config.tls.ca) clientOptions.tlsCAFile = config.tls.ca;
55
- if (config.tls.cert) clientOptions.tlsCertificateFile = config.tls.cert;
56
- if (config.tls.key) clientOptions.tlsCertificateKeyFile = config.tls.key;
57
- if (config.tls.passphrase)
58
- clientOptions.tlsCertificateKeyFilePassword = config.tls.passphrase;
59
- if (config.tls.insecure) clientOptions.tlsInsecure = config.tls.insecure;
60
- if (config.tls.allowInvalidCertificates)
61
- clientOptions.tlsAllowInvalidCertificates = config.tls.allowInvalidCertificates;
62
- if (config.tls.allowInvalidHostnames)
63
- clientOptions.tlsAllowInvalidHostnames = config.tls.allowInvalidHostnames;
64
- if (config.tls.checkServerIdentity === false) clientOptions.checkServerIdentity = false;
65
- }
66
-
67
- this.client = new MongoClient(url, clientOptions);
39
+ });
68
40
 
69
41
  this.db = this.client.db(config.database || 'moro_app');
70
42
 
@@ -9,19 +9,6 @@ interface MySQLConfig {
9
9
  password?: string;
10
10
  database?: string;
11
11
  connectionLimit?: number;
12
- ssl?:
13
- | {
14
- rejectUnauthorized?: boolean;
15
- ca?: string;
16
- cert?: string;
17
- key?: string;
18
- passphrase?: string;
19
- servername?: string;
20
- checkServerIdentity?: boolean;
21
- ciphers?: string;
22
- secureProtocol?: string;
23
- }
24
- | boolean;
25
12
  }
26
13
 
27
14
  export class MySQLAdapter implements DatabaseAdapter {
@@ -40,7 +27,6 @@ export class MySQLAdapter implements DatabaseAdapter {
40
27
  waitForConnections: true,
41
28
  connectionLimit: config.connectionLimit || 10,
42
29
  queueLimit: 0,
43
- ssl: typeof config.ssl === 'object' ? { ...config.ssl } : config.ssl || false,
44
30
  });
45
31
  } catch (error) {
46
32
  throw new Error(
@@ -9,17 +9,7 @@ interface PostgreSQLConfig {
9
9
  password?: string;
10
10
  database?: string;
11
11
  connectionLimit?: number;
12
- ssl?:
13
- | {
14
- rejectUnauthorized?: boolean;
15
- ca?: string;
16
- cert?: string;
17
- key?: string;
18
- passphrase?: string;
19
- servername?: string;
20
- checkServerIdentity?: boolean;
21
- }
22
- | boolean;
12
+ ssl?: boolean;
23
13
  }
24
14
 
25
15
  export class PostgreSQLAdapter implements DatabaseAdapter {
@@ -36,7 +26,7 @@ export class PostgreSQLAdapter implements DatabaseAdapter {
36
26
  password: config.password || '',
37
27
  database: config.database || 'moro_app',
38
28
  max: config.connectionLimit || 10,
39
- ssl: typeof config.ssl === 'object' ? { ...config.ssl } : config.ssl || false,
29
+ ssl: config.ssl || false,
40
30
  });
41
31
 
42
32
  this.pool.on('error', (err: Error) => {