@morojs/moro 1.4.0 → 1.5.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.
- package/dist/core/config/index.d.ts +0 -1
- package/dist/core/config/index.js +0 -4
- package/dist/core/config/index.js.map +1 -1
- package/dist/core/config/loader.js +219 -226
- package/dist/core/config/loader.js.map +1 -1
- package/dist/core/config/schema.d.ts +30 -335
- package/dist/core/config/schema.js +133 -224
- package/dist/core/config/schema.js.map +1 -1
- package/dist/core/config/utils.d.ts +3 -2
- package/dist/core/config/utils.js.map +1 -1
- package/dist/core/config/validation.d.ts +0 -1
- package/dist/core/config/validation.js +5 -10
- package/dist/core/config/validation.js.map +1 -1
- package/dist/core/docs/index.js +1 -1
- package/dist/core/docs/index.js.map +1 -1
- package/dist/core/docs/simple-docs.js +5 -5
- package/dist/core/docs/zod-to-openapi.d.ts +2 -3
- package/dist/core/docs/zod-to-openapi.js +28 -0
- package/dist/core/docs/zod-to-openapi.js.map +1 -1
- package/dist/core/networking/websocket-manager.js +19 -19
- package/dist/core/networking/websocket-manager.js.map +1 -1
- package/dist/core/validation/index.d.ts +0 -2
- package/dist/core/validation/index.js +3 -8
- package/dist/core/validation/index.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/moro.js +16 -15
- package/dist/moro.js.map +1 -1
- package/dist/{core/config/types.d.ts → types/config.d.ts} +0 -1
- package/dist/types/config.js +4 -0
- package/dist/types/config.js.map +1 -0
- package/package.json +6 -7
- package/src/core/config/index.ts +0 -3
- package/src/core/config/loader.ts +571 -247
- package/src/core/config/schema.ts +146 -279
- package/src/core/config/utils.ts +1 -2
- package/src/core/config/validation.ts +5 -10
- package/src/core/docs/index.ts +1 -1
- package/src/core/docs/simple-docs.ts +5 -5
- package/src/core/docs/zod-to-openapi.ts +50 -20
- package/src/core/networking/websocket-manager.ts +17 -17
- package/src/core/validation/index.ts +2 -8
- package/src/index.ts +11 -1
- package/src/moro.ts +16 -15
- package/src/{core/config/types.ts → types/config.ts} +0 -120
- package/dist/core/config/types.js +0 -124
- package/dist/core/config/types.js.map +0 -1
- package/dist/core/config/typescript-loader.d.ts +0 -6
- package/dist/core/config/typescript-loader.js +0 -268
- package/dist/core/config/typescript-loader.js.map +0 -1
- package/src/core/config/typescript-loader.ts +0 -571
|
@@ -128,26 +128,26 @@ export class WebSocketManager {
|
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
//
|
|
131
|
+
// Universal validation (works with any ValidationSchema)
|
|
132
132
|
if (wsConfig.validation) {
|
|
133
133
|
try {
|
|
134
|
-
data = wsConfig.validation.
|
|
134
|
+
data = await wsConfig.validation.parseAsync(data);
|
|
135
135
|
} catch (validationError: any) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
136
|
+
// Handle universal validation errors
|
|
137
|
+
const { normalizeValidationError } = require('../validation/schema-interface');
|
|
138
|
+
const normalizedError = normalizeValidationError(validationError);
|
|
139
|
+
const error = {
|
|
140
|
+
success: false,
|
|
141
|
+
error: 'Validation failed',
|
|
142
|
+
details: normalizedError.issues.map((issue: any) => ({
|
|
143
|
+
field: issue.path.length > 0 ? issue.path.join('.') : 'data',
|
|
144
|
+
message: issue.message,
|
|
145
|
+
code: issue.code,
|
|
146
|
+
})),
|
|
147
|
+
};
|
|
148
|
+
if (callback) callback(error);
|
|
149
|
+
else socket.emit('error', error);
|
|
150
|
+
return;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
@@ -11,12 +11,7 @@ import {
|
|
|
11
11
|
} from './schema-interface';
|
|
12
12
|
|
|
13
13
|
// Re-export zod if available (for backward compatibility)
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
z = require('zod').z;
|
|
17
|
-
} catch {
|
|
18
|
-
// Zod not available - that's fine!
|
|
19
|
-
}
|
|
14
|
+
// The dynamic import is handled in the main index.ts
|
|
20
15
|
|
|
21
16
|
const logger = createFrameworkLogger('Validation');
|
|
22
17
|
|
|
@@ -208,5 +203,4 @@ export {
|
|
|
208
203
|
} from './schema-interface';
|
|
209
204
|
export { joi, yup, fn as customValidator, classValidator } from './adapters';
|
|
210
205
|
|
|
211
|
-
//
|
|
212
|
-
export { z };
|
|
206
|
+
// Note: z is re-exported from main index.ts with dynamic import
|
package/src/index.ts
CHANGED
|
@@ -106,7 +106,17 @@ export type {
|
|
|
106
106
|
export { createFrameworkLogger, logger } from './core/logger';
|
|
107
107
|
|
|
108
108
|
// Universal Validation System
|
|
109
|
-
export { validate, body, query, params, combineSchemas
|
|
109
|
+
export { validate, body, query, params, combineSchemas } from './core/validation';
|
|
110
|
+
|
|
111
|
+
// Dynamic Zod export (optional dependency)
|
|
112
|
+
let z: any;
|
|
113
|
+
try {
|
|
114
|
+
z = require('zod').z;
|
|
115
|
+
} catch {
|
|
116
|
+
// Zod not available - that's fine!
|
|
117
|
+
z = undefined;
|
|
118
|
+
}
|
|
119
|
+
export { z };
|
|
110
120
|
export type {
|
|
111
121
|
ValidationConfig,
|
|
112
122
|
ValidationResult,
|
package/src/moro.ts
CHANGED
|
@@ -770,25 +770,26 @@ export class Moro extends EventEmitter {
|
|
|
770
770
|
// Enhance request with events property for direct routes
|
|
771
771
|
req.events = this.eventBus;
|
|
772
772
|
|
|
773
|
-
//
|
|
773
|
+
// Universal validation middleware (works with any ValidationSchema)
|
|
774
774
|
if (route.validation) {
|
|
775
775
|
try {
|
|
776
|
-
const validated = route.validation.
|
|
776
|
+
const validated = await route.validation.parseAsync(req.body);
|
|
777
777
|
req.body = validated;
|
|
778
778
|
} catch (error: any) {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
779
|
+
// Handle universal validation errors
|
|
780
|
+
const { normalizeValidationError } = require('./core/validation/schema-interface');
|
|
781
|
+
const normalizedError = normalizeValidationError(error);
|
|
782
|
+
res.status(400).json({
|
|
783
|
+
success: false,
|
|
784
|
+
error: 'Validation failed',
|
|
785
|
+
details: normalizedError.issues.map((issue: any) => ({
|
|
786
|
+
field: issue.path.length > 0 ? issue.path.join('.') : 'body',
|
|
787
|
+
message: issue.message,
|
|
788
|
+
code: issue.code,
|
|
789
|
+
})),
|
|
790
|
+
requestId: req.requestId,
|
|
791
|
+
});
|
|
792
|
+
return;
|
|
792
793
|
}
|
|
793
794
|
}
|
|
794
795
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// TypeScript-based Configuration Types for Moro Framework
|
|
2
|
-
// Replaces Zod schemas with pure TypeScript interfaces
|
|
3
2
|
|
|
4
3
|
export interface ServerConfig {
|
|
5
4
|
port: number;
|
|
@@ -156,122 +155,3 @@ export interface AppConfig {
|
|
|
156
155
|
external: ExternalServicesConfig;
|
|
157
156
|
performance: PerformanceConfig;
|
|
158
157
|
}
|
|
159
|
-
|
|
160
|
-
// Default configuration
|
|
161
|
-
export const DEFAULT_CONFIG: AppConfig = {
|
|
162
|
-
server: {
|
|
163
|
-
port: 3001,
|
|
164
|
-
host: 'localhost',
|
|
165
|
-
environment: 'development',
|
|
166
|
-
maxConnections: 1000,
|
|
167
|
-
timeout: 30000,
|
|
168
|
-
},
|
|
169
|
-
serviceDiscovery: {
|
|
170
|
-
enabled: false,
|
|
171
|
-
type: 'memory',
|
|
172
|
-
consulUrl: 'http://localhost:8500',
|
|
173
|
-
kubernetesNamespace: 'default',
|
|
174
|
-
healthCheckInterval: 30000,
|
|
175
|
-
retryAttempts: 3,
|
|
176
|
-
},
|
|
177
|
-
database: {
|
|
178
|
-
redis: {
|
|
179
|
-
url: 'redis://localhost:6379',
|
|
180
|
-
maxRetries: 3,
|
|
181
|
-
retryDelay: 1000,
|
|
182
|
-
keyPrefix: 'moro:',
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
modules: {
|
|
186
|
-
cache: {
|
|
187
|
-
enabled: true,
|
|
188
|
-
defaultTtl: 300,
|
|
189
|
-
maxSize: 1000,
|
|
190
|
-
strategy: 'lru',
|
|
191
|
-
},
|
|
192
|
-
rateLimit: {
|
|
193
|
-
enabled: true,
|
|
194
|
-
defaultRequests: 100,
|
|
195
|
-
defaultWindow: 60000,
|
|
196
|
-
skipSuccessfulRequests: false,
|
|
197
|
-
skipFailedRequests: false,
|
|
198
|
-
},
|
|
199
|
-
validation: {
|
|
200
|
-
enabled: true,
|
|
201
|
-
stripUnknown: true,
|
|
202
|
-
abortEarly: false,
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
logging: {
|
|
206
|
-
level: 'info',
|
|
207
|
-
format: 'pretty',
|
|
208
|
-
enableColors: true,
|
|
209
|
-
enableTimestamp: true,
|
|
210
|
-
enableContext: true,
|
|
211
|
-
outputs: {
|
|
212
|
-
console: true,
|
|
213
|
-
file: {
|
|
214
|
-
enabled: false,
|
|
215
|
-
path: './logs/moro.log',
|
|
216
|
-
maxSize: '10MB',
|
|
217
|
-
maxFiles: 5,
|
|
218
|
-
},
|
|
219
|
-
webhook: {
|
|
220
|
-
enabled: false,
|
|
221
|
-
headers: {},
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
security: {
|
|
226
|
-
cors: {
|
|
227
|
-
enabled: true,
|
|
228
|
-
origin: '*',
|
|
229
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
|
|
230
|
-
allowedHeaders: ['Content-Type', 'Authorization'],
|
|
231
|
-
credentials: false,
|
|
232
|
-
},
|
|
233
|
-
helmet: {
|
|
234
|
-
enabled: true,
|
|
235
|
-
contentSecurityPolicy: true,
|
|
236
|
-
hsts: true,
|
|
237
|
-
noSniff: true,
|
|
238
|
-
frameguard: true,
|
|
239
|
-
},
|
|
240
|
-
rateLimit: {
|
|
241
|
-
global: {
|
|
242
|
-
enabled: false,
|
|
243
|
-
requests: 1000,
|
|
244
|
-
window: 60000,
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
external: {
|
|
249
|
-
stripe: {
|
|
250
|
-
apiVersion: '2023-10-16',
|
|
251
|
-
},
|
|
252
|
-
paypal: {
|
|
253
|
-
environment: 'sandbox',
|
|
254
|
-
},
|
|
255
|
-
smtp: {
|
|
256
|
-
port: 587,
|
|
257
|
-
secure: false,
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
performance: {
|
|
261
|
-
compression: {
|
|
262
|
-
enabled: true,
|
|
263
|
-
level: 6,
|
|
264
|
-
threshold: 1024,
|
|
265
|
-
},
|
|
266
|
-
circuitBreaker: {
|
|
267
|
-
enabled: true,
|
|
268
|
-
failureThreshold: 5,
|
|
269
|
-
resetTimeout: 60000,
|
|
270
|
-
monitoringPeriod: 10000,
|
|
271
|
-
},
|
|
272
|
-
clustering: {
|
|
273
|
-
enabled: false,
|
|
274
|
-
workers: 1,
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
};
|
|
@@ -1,124 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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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