@morojs/moro 1.3.0 → 1.4.0

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 (70) hide show
  1. package/README.md +61 -7
  2. package/dist/core/config/types.d.ts +147 -0
  3. package/dist/core/config/types.js +124 -0
  4. package/dist/core/config/types.js.map +1 -0
  5. package/dist/core/config/typescript-loader.d.ts +6 -0
  6. package/dist/core/config/typescript-loader.js +268 -0
  7. package/dist/core/config/typescript-loader.js.map +1 -0
  8. package/dist/core/config/validation.d.ts +18 -0
  9. package/dist/core/config/validation.js +134 -0
  10. package/dist/core/config/validation.js.map +1 -0
  11. package/dist/core/docs/openapi-generator.js +6 -6
  12. package/dist/core/docs/openapi-generator.js.map +1 -1
  13. package/dist/core/docs/schema-to-openapi.d.ts +7 -0
  14. package/dist/core/docs/schema-to-openapi.js +124 -0
  15. package/dist/core/docs/schema-to-openapi.js.map +1 -0
  16. package/dist/core/docs/zod-to-openapi.d.ts +2 -0
  17. package/dist/core/docs/zod-to-openapi.js.map +1 -1
  18. package/dist/core/framework.d.ts +29 -6
  19. package/dist/core/framework.js +117 -18
  20. package/dist/core/framework.js.map +1 -1
  21. package/dist/core/networking/adapters/index.d.ts +3 -0
  22. package/dist/core/networking/adapters/index.js +10 -0
  23. package/dist/core/networking/adapters/index.js.map +1 -0
  24. package/dist/core/networking/adapters/socketio-adapter.d.ts +16 -0
  25. package/dist/core/networking/adapters/socketio-adapter.js +244 -0
  26. package/dist/core/networking/adapters/socketio-adapter.js.map +1 -0
  27. package/dist/core/networking/adapters/ws-adapter.d.ts +54 -0
  28. package/dist/core/networking/adapters/ws-adapter.js +383 -0
  29. package/dist/core/networking/adapters/ws-adapter.js.map +1 -0
  30. package/dist/core/networking/websocket-adapter.d.ts +171 -0
  31. package/dist/core/networking/websocket-adapter.js +5 -0
  32. package/dist/core/networking/websocket-adapter.js.map +1 -0
  33. package/dist/core/networking/websocket-manager.d.ts +53 -17
  34. package/dist/core/networking/websocket-manager.js +166 -108
  35. package/dist/core/networking/websocket-manager.js.map +1 -1
  36. package/dist/core/routing/index.d.ts +13 -13
  37. package/dist/core/routing/index.js.map +1 -1
  38. package/dist/core/validation/adapters.d.ts +51 -0
  39. package/dist/core/validation/adapters.js +135 -0
  40. package/dist/core/validation/adapters.js.map +1 -0
  41. package/dist/core/validation/index.d.ts +14 -11
  42. package/dist/core/validation/index.js +37 -26
  43. package/dist/core/validation/index.js.map +1 -1
  44. package/dist/core/validation/schema-interface.d.ts +36 -0
  45. package/dist/core/validation/schema-interface.js +68 -0
  46. package/dist/core/validation/schema-interface.js.map +1 -0
  47. package/dist/index.d.ts +6 -1
  48. package/dist/index.js +14 -3
  49. package/dist/index.js.map +1 -1
  50. package/dist/moro.js +8 -2
  51. package/dist/moro.js.map +1 -1
  52. package/package.json +31 -7
  53. package/src/core/config/types.ts +277 -0
  54. package/src/core/config/typescript-loader.ts +571 -0
  55. package/src/core/config/validation.ts +145 -0
  56. package/src/core/docs/openapi-generator.ts +7 -6
  57. package/src/core/docs/schema-to-openapi.ts +148 -0
  58. package/src/core/docs/zod-to-openapi.ts +2 -0
  59. package/src/core/framework.ts +121 -28
  60. package/src/core/networking/adapters/index.ts +16 -0
  61. package/src/core/networking/adapters/socketio-adapter.ts +252 -0
  62. package/src/core/networking/adapters/ws-adapter.ts +425 -0
  63. package/src/core/networking/websocket-adapter.ts +217 -0
  64. package/src/core/networking/websocket-manager.ts +185 -127
  65. package/src/core/routing/index.ts +13 -13
  66. package/src/core/validation/adapters.ts +147 -0
  67. package/src/core/validation/index.ts +60 -38
  68. package/src/core/validation/schema-interface.ts +100 -0
  69. package/src/index.ts +25 -2
  70. package/src/moro.ts +11 -2
package/README.md CHANGED
@@ -25,7 +25,8 @@ Moro eliminates the pain points of traditional Node.js frameworks with **intelli
25
25
  - **Multi-Runtime Support** - Deploy to Node.js, Vercel Edge, AWS Lambda, Cloudflare Workers
26
26
  - **Intelligent Routing** - Chainable + schema-first APIs with automatic middleware ordering
27
27
  - **Enterprise Authentication** - Auth.js integration with RBAC, OAuth, and native adapter
28
- - **Zod Validation** - Type-safe, functional validation with full TypeScript inference
28
+ - **Universal Validation** - Support for Zod, Joi, Yup, Class Validator with full TypeScript inference
29
+ - **WebSocket Support** - Pluggable adapters for Socket.IO, native WebSockets, or auto-detection
29
30
  - **Native Performance** - Zero framework overhead, optimized for each runtime
30
31
  - **Functional Architecture** - No decorators, pure functional patterns
31
32
  - **Zero Order Dependencies** - Framework handles optimal middleware execution
@@ -127,20 +128,30 @@ app.post('/users')
127
128
  .handler(createUser); // Always executed last
128
129
  ```
129
130
 
130
- ### **Full Type Safety with Zod**
131
+ ### **Universal Validation with Full Type Safety**
131
132
 
132
133
  ```typescript
134
+ // Use any validation library - Zod (default)
135
+ import { z } from '@morojs/moro';
133
136
  const UserSchema = z.object({
134
137
  name: z.string().min(2).max(50),
135
138
  email: z.string().email(),
136
139
  age: z.number().min(18).optional()
137
140
  });
138
141
 
142
+ // Or Joi with adapter
143
+ import { joi } from '@morojs/moro';
144
+ import Joi from 'joi';
145
+ const UserSchema = joi(Joi.object({
146
+ name: Joi.string().min(2).max(50).required(),
147
+ email: Joi.string().email().required(),
148
+ age: Joi.number().min(18).optional()
149
+ }));
150
+
139
151
  app.post('/users')
140
- .body(UserSchema)
152
+ .body(UserSchema) // Works with any validation library!
141
153
  .handler((req, res) => {
142
- // req.body is typed as z.infer<typeof UserSchema>
143
- // Full IDE support, no type assertions needed!
154
+ // req.body is fully typed regardless of validation library
144
155
  const user = req.body; // ✨ Fully typed
145
156
  return { success: true, data: user };
146
157
  });
@@ -168,6 +179,45 @@ app.route({
168
179
  });
169
180
  ```
170
181
 
182
+ ### WebSocket Support
183
+
184
+ Pluggable WebSocket adapters with auto-detection:
185
+
186
+ ```typescript
187
+ import { createApp, SocketIOAdapter, WSAdapter } from '@morojs/moro';
188
+
189
+ const app = createApp({
190
+ // Auto-detect available WebSocket library
191
+ websocket: { enabled: true },
192
+
193
+ // Or use specific adapter
194
+ websocket: { adapter: new SocketIOAdapter() },
195
+
196
+ // Or native WebSockets
197
+ websocket: { adapter: new WSAdapter() }
198
+ });
199
+
200
+ // Define WebSocket handlers
201
+ app.websocket('/chat', {
202
+ connect: (socket) => {
203
+ console.log(`Client connected: ${socket.id}`);
204
+ socket.join('general');
205
+ },
206
+
207
+ message: (socket, data) => {
208
+ socket.to('general').emit('message', {
209
+ user: socket.user,
210
+ text: data.text,
211
+ timestamp: new Date()
212
+ });
213
+ },
214
+
215
+ disconnect: (socket) => {
216
+ console.log(`Client disconnected: ${socket.id}`);
217
+ }
218
+ });
219
+ ```
220
+
171
221
  ### Authentication & Security
172
222
 
173
223
  Built-in Auth.js integration with enterprise features:
@@ -256,15 +306,19 @@ await app.loadModule(UsersModule);
256
306
  - **Multi-Runtime Support** - Same API works on Node.js, Edge, Lambda, and Workers
257
307
  - **Intelligent Routing** - Automatic middleware ordering eliminates Express.js pain points
258
308
  - **Enterprise Authentication** - Auth.js integration with OAuth, RBAC, and native adapter
309
+ - **Universal Validation** - Support for any validation library with full type safety
310
+ - **WebSocket Flexibility** - Choose between Socket.IO, native WebSockets, or auto-detection
259
311
  - **Functional Architecture** - No decorators, pure functions, better performance
260
- - **Type Safety** - Zod provides compile-time and runtime type safety
312
+ - **Type Safety** - Universal validation with compile-time and runtime type safety
261
313
 
262
314
  ## Why Choose Moro?
263
315
 
264
316
  **Same API everywhere** - Write once, deploy to any runtime
265
317
  **No middleware dependencies** - Framework handles optimal ordering
266
318
  **Enterprise authentication** - Auth.js integration with native adapter
267
- **Full type safety** - Zod provides end-to-end TypeScript inference
319
+ **Validation flexibility** - Use any validation library (Zod, Joi, Yup, Class Validator)
320
+ **WebSocket choice** - Socket.IO, native WebSockets, or auto-detection
321
+ **Full type safety** - Universal validation provides end-to-end TypeScript inference
268
322
  **Clean APIs** - Chainable and schema-first approaches
269
323
  **Production ready** - Circuit breakers, rate limiting, events, RBAC
270
324
  **Performance optimized** - Runtime-specific adapters
@@ -0,0 +1,147 @@
1
+ export interface ServerConfig {
2
+ port: number;
3
+ host: string;
4
+ environment: 'development' | 'staging' | 'production';
5
+ maxConnections: number;
6
+ timeout: number;
7
+ }
8
+ export interface ServiceDiscoveryConfig {
9
+ enabled: boolean;
10
+ type: 'memory' | 'consul' | 'kubernetes';
11
+ consulUrl: string;
12
+ kubernetesNamespace: string;
13
+ healthCheckInterval: number;
14
+ retryAttempts: number;
15
+ }
16
+ export interface DatabaseConfig {
17
+ url?: string;
18
+ redis: {
19
+ url: string;
20
+ maxRetries: number;
21
+ retryDelay: number;
22
+ keyPrefix: string;
23
+ };
24
+ mysql?: {
25
+ host: string;
26
+ port: number;
27
+ database?: string;
28
+ username?: string;
29
+ password?: string;
30
+ connectionLimit: number;
31
+ acquireTimeout: number;
32
+ timeout: number;
33
+ };
34
+ }
35
+ export interface ModuleDefaultsConfig {
36
+ cache: {
37
+ enabled: boolean;
38
+ defaultTtl: number;
39
+ maxSize: number;
40
+ strategy: 'lru' | 'lfu' | 'fifo';
41
+ };
42
+ rateLimit: {
43
+ enabled: boolean;
44
+ defaultRequests: number;
45
+ defaultWindow: number;
46
+ skipSuccessfulRequests: boolean;
47
+ skipFailedRequests: boolean;
48
+ };
49
+ validation: {
50
+ enabled: boolean;
51
+ stripUnknown: boolean;
52
+ abortEarly: boolean;
53
+ };
54
+ }
55
+ export interface LoggingConfig {
56
+ level: 'debug' | 'info' | 'warn' | 'error' | 'fatal';
57
+ format: 'pretty' | 'json' | 'compact';
58
+ enableColors: boolean;
59
+ enableTimestamp: boolean;
60
+ enableContext: boolean;
61
+ outputs: {
62
+ console: boolean;
63
+ file: {
64
+ enabled: boolean;
65
+ path: string;
66
+ maxSize: string;
67
+ maxFiles: number;
68
+ };
69
+ webhook: {
70
+ enabled: boolean;
71
+ url?: string;
72
+ headers: Record<string, string>;
73
+ };
74
+ };
75
+ }
76
+ export interface SecurityConfig {
77
+ cors: {
78
+ enabled: boolean;
79
+ origin: string | string[] | boolean;
80
+ methods: string[];
81
+ allowedHeaders: string[];
82
+ credentials: boolean;
83
+ };
84
+ helmet: {
85
+ enabled: boolean;
86
+ contentSecurityPolicy: boolean;
87
+ hsts: boolean;
88
+ noSniff: boolean;
89
+ frameguard: boolean;
90
+ };
91
+ rateLimit: {
92
+ global: {
93
+ enabled: boolean;
94
+ requests: number;
95
+ window: number;
96
+ };
97
+ };
98
+ }
99
+ export interface ExternalServicesConfig {
100
+ stripe?: {
101
+ secretKey?: string;
102
+ publishableKey?: string;
103
+ webhookSecret?: string;
104
+ apiVersion: string;
105
+ };
106
+ paypal?: {
107
+ clientId?: string;
108
+ clientSecret?: string;
109
+ webhookId?: string;
110
+ environment: 'sandbox' | 'production';
111
+ };
112
+ smtp?: {
113
+ host?: string;
114
+ port: number;
115
+ secure: boolean;
116
+ username?: string;
117
+ password?: string;
118
+ };
119
+ }
120
+ export interface PerformanceConfig {
121
+ compression: {
122
+ enabled: boolean;
123
+ level: number;
124
+ threshold: number;
125
+ };
126
+ circuitBreaker: {
127
+ enabled: boolean;
128
+ failureThreshold: number;
129
+ resetTimeout: number;
130
+ monitoringPeriod: number;
131
+ };
132
+ clustering: {
133
+ enabled: boolean;
134
+ workers: number | 'auto';
135
+ };
136
+ }
137
+ export interface AppConfig {
138
+ server: ServerConfig;
139
+ serviceDiscovery: ServiceDiscoveryConfig;
140
+ database: DatabaseConfig;
141
+ modules: ModuleDefaultsConfig;
142
+ logging: LoggingConfig;
143
+ security: SecurityConfig;
144
+ external: ExternalServicesConfig;
145
+ performance: PerformanceConfig;
146
+ }
147
+ export declare const DEFAULT_CONFIG: AppConfig;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ // TypeScript-based Configuration Types for Moro Framework
3
+ // Replaces Zod schemas with pure TypeScript interfaces
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.DEFAULT_CONFIG = void 0;
6
+ // Default configuration
7
+ exports.DEFAULT_CONFIG = {
8
+ server: {
9
+ port: 3001,
10
+ host: 'localhost',
11
+ environment: 'development',
12
+ maxConnections: 1000,
13
+ timeout: 30000,
14
+ },
15
+ serviceDiscovery: {
16
+ enabled: false,
17
+ type: 'memory',
18
+ consulUrl: 'http://localhost:8500',
19
+ kubernetesNamespace: 'default',
20
+ healthCheckInterval: 30000,
21
+ retryAttempts: 3,
22
+ },
23
+ database: {
24
+ redis: {
25
+ url: 'redis://localhost:6379',
26
+ maxRetries: 3,
27
+ retryDelay: 1000,
28
+ keyPrefix: 'moro:',
29
+ },
30
+ },
31
+ modules: {
32
+ cache: {
33
+ enabled: true,
34
+ defaultTtl: 300,
35
+ maxSize: 1000,
36
+ strategy: 'lru',
37
+ },
38
+ rateLimit: {
39
+ enabled: true,
40
+ defaultRequests: 100,
41
+ defaultWindow: 60000,
42
+ skipSuccessfulRequests: false,
43
+ skipFailedRequests: false,
44
+ },
45
+ validation: {
46
+ enabled: true,
47
+ stripUnknown: true,
48
+ abortEarly: false,
49
+ },
50
+ },
51
+ logging: {
52
+ level: 'info',
53
+ format: 'pretty',
54
+ enableColors: true,
55
+ enableTimestamp: true,
56
+ enableContext: true,
57
+ outputs: {
58
+ console: true,
59
+ file: {
60
+ enabled: false,
61
+ path: './logs/moro.log',
62
+ maxSize: '10MB',
63
+ maxFiles: 5,
64
+ },
65
+ webhook: {
66
+ enabled: false,
67
+ headers: {},
68
+ },
69
+ },
70
+ },
71
+ security: {
72
+ cors: {
73
+ enabled: true,
74
+ origin: '*',
75
+ methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
76
+ allowedHeaders: ['Content-Type', 'Authorization'],
77
+ credentials: false,
78
+ },
79
+ helmet: {
80
+ enabled: true,
81
+ contentSecurityPolicy: true,
82
+ hsts: true,
83
+ noSniff: true,
84
+ frameguard: true,
85
+ },
86
+ rateLimit: {
87
+ global: {
88
+ enabled: false,
89
+ requests: 1000,
90
+ window: 60000,
91
+ },
92
+ },
93
+ },
94
+ external: {
95
+ stripe: {
96
+ apiVersion: '2023-10-16',
97
+ },
98
+ paypal: {
99
+ environment: 'sandbox',
100
+ },
101
+ smtp: {
102
+ port: 587,
103
+ secure: false,
104
+ },
105
+ },
106
+ performance: {
107
+ compression: {
108
+ enabled: true,
109
+ level: 6,
110
+ threshold: 1024,
111
+ },
112
+ circuitBreaker: {
113
+ enabled: true,
114
+ failureThreshold: 5,
115
+ resetTimeout: 60000,
116
+ monitoringPeriod: 10000,
117
+ },
118
+ clustering: {
119
+ enabled: false,
120
+ workers: 1,
121
+ },
122
+ },
123
+ };
124
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/config/types.ts"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,uDAAuD;;;AA8JvD,wBAAwB;AACX,QAAA,cAAc,GAAc;IACvC,MAAM,EAAE;QACN,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,aAAa;QAC1B,cAAc,EAAE,IAAI;QACpB,OAAO,EAAE,KAAK;KACf;IACD,gBAAgB,EAAE;QAChB,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,uBAAuB;QAClC,mBAAmB,EAAE,SAAS;QAC9B,mBAAmB,EAAE,KAAK;QAC1B,aAAa,EAAE,CAAC;KACjB;IACD,QAAQ,EAAE;QACR,KAAK,EAAE;YACL,GAAG,EAAE,wBAAwB;YAC7B,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,IAAI;YAChB,SAAS,EAAE,OAAO;SACnB;KACF;IACD,OAAO,EAAE;QACP,KAAK,EAAE;YACL,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,KAAK;SAChB;QACD,SAAS,EAAE;YACT,OAAO,EAAE,IAAI;YACb,eAAe,EAAE,GAAG;YACpB,aAAa,EAAE,KAAK;YACpB,sBAAsB,EAAE,KAAK;YAC7B,kBAAk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,EAAE;YACX,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,CAAC;YACR,SAAS,EAAE,IAAI;SAChB;QACD,cAAc,EAAE;YACd,OAAO,EAAE,IAAI;YACb,gBAAgB,EAAE,CAAC;YACnB,YAAY,EAAE,KAAK;YACnB,gBAAgB,EAAE,KAAK;SACxB;QACD,UAAU,EAAE;YACV,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,CAAC;SACX;KACF;CACF,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { AppConfig } from './types';
2
+ /**
3
+ * Load and validate configuration using TypeScript + simple validation
4
+ * No Zod dependency required!
5
+ */
6
+ export declare function loadConfigWithTypeScript(): AppConfig;