@morojs/moro 1.2.1 → 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.
- package/LICENSE +2 -2
- package/README.md +61 -7
- package/dist/core/config/file-loader.js +31 -25
- package/dist/core/config/file-loader.js.map +1 -1
- package/dist/core/config/schema.d.ts +2 -2
- package/dist/core/config/schema.js +1 -1
- package/dist/core/config/schema.js.map +1 -1
- package/dist/core/config/types.d.ts +147 -0
- package/dist/core/config/types.js +124 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/config/typescript-loader.d.ts +6 -0
- package/dist/core/config/typescript-loader.js +268 -0
- package/dist/core/config/typescript-loader.js.map +1 -0
- package/dist/core/config/validation.d.ts +18 -0
- package/dist/core/config/validation.js +134 -0
- package/dist/core/config/validation.js.map +1 -0
- package/dist/core/docs/openapi-generator.js +6 -6
- package/dist/core/docs/openapi-generator.js.map +1 -1
- package/dist/core/docs/schema-to-openapi.d.ts +7 -0
- package/dist/core/docs/schema-to-openapi.js +124 -0
- package/dist/core/docs/schema-to-openapi.js.map +1 -0
- package/dist/core/docs/zod-to-openapi.d.ts +2 -0
- package/dist/core/docs/zod-to-openapi.js.map +1 -1
- package/dist/core/events/event-bus.js +4 -0
- package/dist/core/events/event-bus.js.map +1 -1
- package/dist/core/framework.d.ts +29 -6
- package/dist/core/framework.js +117 -18
- package/dist/core/framework.js.map +1 -1
- package/dist/core/http/http-server.d.ts +33 -0
- package/dist/core/http/http-server.js +329 -28
- package/dist/core/http/http-server.js.map +1 -1
- package/dist/core/networking/adapters/index.d.ts +3 -0
- package/dist/core/networking/adapters/index.js +10 -0
- package/dist/core/networking/adapters/index.js.map +1 -0
- package/dist/core/networking/adapters/socketio-adapter.d.ts +16 -0
- package/dist/core/networking/adapters/socketio-adapter.js +244 -0
- package/dist/core/networking/adapters/socketio-adapter.js.map +1 -0
- package/dist/core/networking/adapters/ws-adapter.d.ts +54 -0
- package/dist/core/networking/adapters/ws-adapter.js +383 -0
- package/dist/core/networking/adapters/ws-adapter.js.map +1 -0
- package/dist/core/networking/websocket-adapter.d.ts +171 -0
- package/dist/core/networking/websocket-adapter.js +5 -0
- package/dist/core/networking/websocket-adapter.js.map +1 -0
- package/dist/core/networking/websocket-manager.d.ts +53 -17
- package/dist/core/networking/websocket-manager.js +166 -108
- package/dist/core/networking/websocket-manager.js.map +1 -1
- package/dist/core/routing/index.d.ts +13 -13
- package/dist/core/routing/index.js.map +1 -1
- package/dist/core/utilities/container.d.ts +1 -0
- package/dist/core/utilities/container.js +11 -1
- package/dist/core/utilities/container.js.map +1 -1
- package/dist/core/validation/adapters.d.ts +51 -0
- package/dist/core/validation/adapters.js +135 -0
- package/dist/core/validation/adapters.js.map +1 -0
- package/dist/core/validation/index.d.ts +14 -11
- package/dist/core/validation/index.js +37 -26
- package/dist/core/validation/index.js.map +1 -1
- package/dist/core/validation/schema-interface.d.ts +36 -0
- package/dist/core/validation/schema-interface.js +68 -0
- package/dist/core/validation/schema-interface.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/moro.d.ts +8 -0
- package/dist/moro.js +339 -14
- package/dist/moro.js.map +1 -1
- package/dist/types/core.d.ts +17 -0
- package/package.json +42 -14
- package/src/core/config/file-loader.ts +34 -25
- package/src/core/config/schema.ts +1 -1
- package/src/core/config/types.ts +277 -0
- package/src/core/config/typescript-loader.ts +571 -0
- package/src/core/config/validation.ts +145 -0
- package/src/core/docs/openapi-generator.ts +7 -6
- package/src/core/docs/schema-to-openapi.ts +148 -0
- package/src/core/docs/zod-to-openapi.ts +2 -0
- package/src/core/events/event-bus.ts +5 -0
- package/src/core/framework.ts +121 -28
- package/src/core/http/http-server.ts +377 -28
- package/src/core/networking/adapters/index.ts +16 -0
- package/src/core/networking/adapters/socketio-adapter.ts +252 -0
- package/src/core/networking/adapters/ws-adapter.ts +425 -0
- package/src/core/networking/websocket-adapter.ts +217 -0
- package/src/core/networking/websocket-manager.ts +185 -127
- package/src/core/routing/index.ts +13 -13
- package/src/core/utilities/container.ts +14 -1
- package/src/core/validation/adapters.ts +147 -0
- package/src/core/validation/index.ts +60 -38
- package/src/core/validation/schema-interface.ts +100 -0
- package/src/index.ts +25 -2
- package/src/moro.ts +405 -15
- package/src/types/core.ts +18 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ValidationSchema } from './schema-interface';
|
|
2
|
+
/**
|
|
3
|
+
* Zod Compatibility Check
|
|
4
|
+
* Zod ALREADY implements ValidationSchema interface natively!
|
|
5
|
+
* No adapter needed - it just works.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Joi Adapter - makes Joi schemas compatible with ValidationSchema
|
|
9
|
+
*/
|
|
10
|
+
export declare class JoiAdapter<T = any> implements ValidationSchema<T> {
|
|
11
|
+
private joiSchema;
|
|
12
|
+
constructor(joiSchema: any);
|
|
13
|
+
parseAsync(data: unknown): Promise<T>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Yup Adapter - makes Yup schemas compatible with ValidationSchema
|
|
17
|
+
*/
|
|
18
|
+
export declare class YupAdapter<T = any> implements ValidationSchema<T> {
|
|
19
|
+
private yupSchema;
|
|
20
|
+
constructor(yupSchema: any);
|
|
21
|
+
parseAsync(data: unknown): Promise<T>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Custom Validation Function Adapter
|
|
25
|
+
* Allows users to use simple validation functions
|
|
26
|
+
*/
|
|
27
|
+
export declare class FunctionAdapter<T = any> implements ValidationSchema<T> {
|
|
28
|
+
private validateFn;
|
|
29
|
+
private name;
|
|
30
|
+
constructor(validateFn: (data: unknown) => T | Promise<T>, name?: string);
|
|
31
|
+
parseAsync(data: unknown): Promise<T>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Class Validator Adapter (for TypeScript decorators)
|
|
35
|
+
*/
|
|
36
|
+
export declare class ClassValidatorAdapter<T extends object = any> implements ValidationSchema<T> {
|
|
37
|
+
private ClassType;
|
|
38
|
+
private validate?;
|
|
39
|
+
constructor(ClassType: new () => T, validate?: ((obj: any) => Promise<any[]>) | undefined);
|
|
40
|
+
parseAsync(data: unknown): Promise<T>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Utility functions for creating adapters
|
|
44
|
+
*/
|
|
45
|
+
export declare function joi<T = any>(joiSchema: any): ValidationSchema<T>;
|
|
46
|
+
export declare function yup<T = any>(yupSchema: any): ValidationSchema<T>;
|
|
47
|
+
export declare function fn<T = any>(validateFn: (data: unknown) => T | Promise<T>, name?: string): ValidationSchema<T>;
|
|
48
|
+
export declare function classValidator<T extends object = any>(ClassType: new () => T, validate?: (obj: any) => Promise<any[]>): ValidationSchema<T>;
|
|
49
|
+
export type JoiSchema<T> = ValidationSchema<T>;
|
|
50
|
+
export type YupSchema<T> = ValidationSchema<T>;
|
|
51
|
+
export type CustomValidator<T> = ValidationSchema<T>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Validation Library Adapters for Moro Framework
|
|
3
|
+
// Makes Joi, Yup, and other libraries compatible with ValidationSchema interface
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ClassValidatorAdapter = exports.FunctionAdapter = exports.YupAdapter = exports.JoiAdapter = void 0;
|
|
6
|
+
exports.joi = joi;
|
|
7
|
+
exports.yup = yup;
|
|
8
|
+
exports.fn = fn;
|
|
9
|
+
exports.classValidator = classValidator;
|
|
10
|
+
const schema_interface_1 = require("./schema-interface");
|
|
11
|
+
/**
|
|
12
|
+
* Zod Compatibility Check
|
|
13
|
+
* Zod ALREADY implements ValidationSchema interface natively!
|
|
14
|
+
* No adapter needed - it just works.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Joi Adapter - makes Joi schemas compatible with ValidationSchema
|
|
18
|
+
*/
|
|
19
|
+
class JoiAdapter {
|
|
20
|
+
constructor(joiSchema) {
|
|
21
|
+
this.joiSchema = joiSchema;
|
|
22
|
+
if (!joiSchema || typeof joiSchema.validateAsync !== 'function') {
|
|
23
|
+
throw new Error('Invalid Joi schema provided to JoiAdapter');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async parseAsync(data) {
|
|
27
|
+
try {
|
|
28
|
+
const result = await this.joiSchema.validateAsync(data, { abortEarly: false });
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw (0, schema_interface_1.normalizeValidationError)(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.JoiAdapter = JoiAdapter;
|
|
37
|
+
/**
|
|
38
|
+
* Yup Adapter - makes Yup schemas compatible with ValidationSchema
|
|
39
|
+
*/
|
|
40
|
+
class YupAdapter {
|
|
41
|
+
constructor(yupSchema) {
|
|
42
|
+
this.yupSchema = yupSchema;
|
|
43
|
+
if (!yupSchema || typeof yupSchema.validate !== 'function') {
|
|
44
|
+
throw new Error('Invalid Yup schema provided to YupAdapter');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async parseAsync(data) {
|
|
48
|
+
try {
|
|
49
|
+
const result = await this.yupSchema.validate(data, { abortEarly: false });
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw (0, schema_interface_1.normalizeValidationError)(error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.YupAdapter = YupAdapter;
|
|
58
|
+
/**
|
|
59
|
+
* Custom Validation Function Adapter
|
|
60
|
+
* Allows users to use simple validation functions
|
|
61
|
+
*/
|
|
62
|
+
class FunctionAdapter {
|
|
63
|
+
constructor(validateFn, name = 'custom') {
|
|
64
|
+
this.validateFn = validateFn;
|
|
65
|
+
this.name = name;
|
|
66
|
+
if (typeof validateFn !== 'function') {
|
|
67
|
+
throw new Error('Validation function is required for FunctionAdapter');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async parseAsync(data) {
|
|
71
|
+
try {
|
|
72
|
+
return await this.validateFn(data);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new schema_interface_1.ValidationError([
|
|
76
|
+
{
|
|
77
|
+
path: [],
|
|
78
|
+
message: error instanceof Error ? error.message : String(error),
|
|
79
|
+
code: this.name,
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.FunctionAdapter = FunctionAdapter;
|
|
86
|
+
/**
|
|
87
|
+
* Class Validator Adapter (for TypeScript decorators)
|
|
88
|
+
*/
|
|
89
|
+
class ClassValidatorAdapter {
|
|
90
|
+
constructor(ClassType, validate) {
|
|
91
|
+
this.ClassType = ClassType;
|
|
92
|
+
this.validate = validate;
|
|
93
|
+
if (typeof ClassType !== 'function') {
|
|
94
|
+
throw new Error('Class constructor is required for ClassValidatorAdapter');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async parseAsync(data) {
|
|
98
|
+
try {
|
|
99
|
+
const instance = Object.assign(new this.ClassType(), data);
|
|
100
|
+
if (this.validate) {
|
|
101
|
+
const errors = await this.validate(instance);
|
|
102
|
+
if (errors && errors.length > 0) {
|
|
103
|
+
throw new schema_interface_1.ValidationError(errors.map((error, index) => ({
|
|
104
|
+
path: error.property ? [error.property] : [index],
|
|
105
|
+
message: Object.values(error.constraints || {}).join(', ') || 'Validation failed',
|
|
106
|
+
code: 'class_validator',
|
|
107
|
+
})));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return instance;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error instanceof schema_interface_1.ValidationError)
|
|
114
|
+
throw error;
|
|
115
|
+
throw (0, schema_interface_1.normalizeValidationError)(error);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.ClassValidatorAdapter = ClassValidatorAdapter;
|
|
120
|
+
/**
|
|
121
|
+
* Utility functions for creating adapters
|
|
122
|
+
*/
|
|
123
|
+
function joi(joiSchema) {
|
|
124
|
+
return new JoiAdapter(joiSchema);
|
|
125
|
+
}
|
|
126
|
+
function yup(yupSchema) {
|
|
127
|
+
return new YupAdapter(yupSchema);
|
|
128
|
+
}
|
|
129
|
+
function fn(validateFn, name) {
|
|
130
|
+
return new FunctionAdapter(validateFn, name);
|
|
131
|
+
}
|
|
132
|
+
function classValidator(ClassType, validate) {
|
|
133
|
+
return new ClassValidatorAdapter(ClassType, validate);
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.js","sourceRoot":"","sources":["../../../src/core/validation/adapters.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iFAAiF;;;AAwHjF,kBAEC;AAED,kBAEC;AAED,gBAKC;AAED,wCAKC;AA1ID,yDAAiG;AAEjG;;;;GAIG;AAEH;;GAEG;AACH,MAAa,UAAU;IACrB,YAAoB,SAAc;QAAd,cAAS,GAAT,SAAS,CAAK;QAChC,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,CAAC,aAAa,KAAK,UAAU,EAAE,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAa;QAC5B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;YAC/E,OAAO,MAAW,CAAC;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAA,2CAAwB,EAAC,KAAK,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF;AAfD,gCAeC;AAED;;GAEG;AACH,MAAa,UAA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jCD,sDAiCC;AAED;;GAEG;AACH,SAAgB,GAAG,CAAU,SAAc;IACzC,OAAO,IAAI,UAAU,CAAI,SAAS,CAAC,CAAC;AACtC,CAAC;AAED,SAAgB,GAAG,CAAU,SAAc;IACzC,OAAO,IAAI,UAAU,CAAI,SAAS,CAAC,CAAC;AACtC,CAAC;AAED,SAAgB,EAAE,CAChB,UAA6C,EAC7C,IAAa;IAEb,OAAO,IAAI,eAAe,CAAI,UAAU,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAED,SAAgB,cAAc,CAC5B,SAAsB,EACtB,QAAuC;IAEvC,OAAO,IAAI,qBAAqB,CAAI,SAAS,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { ZodSchema } from 'zod';
|
|
2
1
|
import { HttpRequest, HttpResponse } from '../http';
|
|
2
|
+
import { ValidationSchema } from './schema-interface';
|
|
3
|
+
declare let z: any;
|
|
3
4
|
export interface ValidationConfig {
|
|
4
|
-
body?:
|
|
5
|
-
query?:
|
|
6
|
-
params?:
|
|
7
|
-
headers?:
|
|
5
|
+
body?: ValidationSchema;
|
|
6
|
+
query?: ValidationSchema;
|
|
7
|
+
params?: ValidationSchema;
|
|
8
|
+
headers?: ValidationSchema;
|
|
8
9
|
}
|
|
9
10
|
export interface ValidationResult<T = any> {
|
|
10
11
|
success: boolean;
|
|
11
12
|
data?: T;
|
|
12
|
-
errors?:
|
|
13
|
+
errors?: ValidationErrorDetail[];
|
|
13
14
|
}
|
|
14
|
-
export interface
|
|
15
|
+
export interface ValidationErrorDetail {
|
|
15
16
|
field: string;
|
|
16
17
|
message: string;
|
|
17
18
|
code: string;
|
|
@@ -23,8 +24,10 @@ export interface ValidatedRequest<T = any> extends HttpRequest {
|
|
|
23
24
|
validatedHeaders?: any;
|
|
24
25
|
}
|
|
25
26
|
export declare function validate<TBody = any, TQuery = any, TParams = any>(config: ValidationConfig, handler: (req: ValidatedRequest<TBody>, res: HttpResponse) => any | Promise<any>): (req: HttpRequest, res: HttpResponse) => Promise<any>;
|
|
26
|
-
export declare function body<T>(schema:
|
|
27
|
-
export declare function query<T>(schema:
|
|
28
|
-
export declare function params<T>(schema:
|
|
27
|
+
export declare function body<T>(schema: ValidationSchema<T>): (handler: (req: ValidatedRequest<T>, res: HttpResponse) => any | Promise<any>) => (req: HttpRequest, res: HttpResponse) => Promise<any>;
|
|
28
|
+
export declare function query<T>(schema: ValidationSchema<T>): (handler: (req: ValidatedRequest<any>, res: HttpResponse) => any | Promise<any>) => (req: HttpRequest, res: HttpResponse) => Promise<any>;
|
|
29
|
+
export declare function params<T>(schema: ValidationSchema<T>): (handler: (req: ValidatedRequest<any>, res: HttpResponse) => any | Promise<any>) => (req: HttpRequest, res: HttpResponse) => Promise<any>;
|
|
29
30
|
export declare function combineSchemas(schemas: ValidationConfig): ValidationConfig;
|
|
30
|
-
export {
|
|
31
|
+
export { ValidationSchema, ValidationError, normalizeValidationError, InferSchemaType, } from './schema-interface';
|
|
32
|
+
export { joi, yup, fn as customValidator, classValidator } from './adapters';
|
|
33
|
+
export { z };
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// Universal Validation System for Moro Framework
|
|
3
|
+
// Works with Zod, Joi, Yup, and any validation library via adapters
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.z = void 0;
|
|
5
|
+
exports.z = exports.classValidator = exports.customValidator = exports.yup = exports.joi = exports.normalizeValidationError = exports.ValidationError = void 0;
|
|
6
6
|
exports.validate = validate;
|
|
7
7
|
exports.body = body;
|
|
8
8
|
exports.query = query;
|
|
9
9
|
exports.params = params;
|
|
10
10
|
exports.combineSchemas = combineSchemas;
|
|
11
|
-
const zod_1 = require("zod");
|
|
12
11
|
const logger_1 = require("../logger");
|
|
12
|
+
const schema_interface_1 = require("./schema-interface");
|
|
13
|
+
// Re-export zod if available (for backward compatibility)
|
|
14
|
+
let z;
|
|
15
|
+
try {
|
|
16
|
+
exports.z = z = require('zod').z;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Zod not available - that's fine!
|
|
20
|
+
}
|
|
13
21
|
const logger = (0, logger_1.createFrameworkLogger)('Validation');
|
|
14
22
|
// Main validation wrapper function
|
|
15
23
|
function validate(config, handler) {
|
|
@@ -75,7 +83,7 @@ function validate(config, handler) {
|
|
|
75
83
|
}
|
|
76
84
|
};
|
|
77
85
|
}
|
|
78
|
-
// Validate individual field
|
|
86
|
+
// Validate individual field using universal schema interface
|
|
79
87
|
async function validateField(schema, data, fieldName) {
|
|
80
88
|
try {
|
|
81
89
|
const validated = await schema.parseAsync(data);
|
|
@@ -85,24 +93,21 @@ async function validateField(schema, data, fieldName) {
|
|
|
85
93
|
};
|
|
86
94
|
}
|
|
87
95
|
catch (error) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
// Re-throw unexpected errors
|
|
105
|
-
throw error;
|
|
96
|
+
const normalizedError = (0, schema_interface_1.normalizeValidationError)(error);
|
|
97
|
+
const errors = normalizedError.issues.map(issue => ({
|
|
98
|
+
field: issue.path.length > 0 ? issue.path.join('.') : fieldName,
|
|
99
|
+
message: issue.message,
|
|
100
|
+
code: issue.code,
|
|
101
|
+
}));
|
|
102
|
+
logger.debug('Field validation failed', 'ValidationFailed', {
|
|
103
|
+
field: fieldName,
|
|
104
|
+
errors: errors.length,
|
|
105
|
+
details: errors,
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
success: false,
|
|
109
|
+
errors,
|
|
110
|
+
};
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
113
|
// Send validation error response
|
|
@@ -138,7 +143,13 @@ function params(schema) {
|
|
|
138
143
|
function combineSchemas(schemas) {
|
|
139
144
|
return schemas;
|
|
140
145
|
}
|
|
141
|
-
// Re-export
|
|
142
|
-
var
|
|
143
|
-
Object.defineProperty(exports, "
|
|
146
|
+
// Re-export common validation tools
|
|
147
|
+
var schema_interface_2 = require("./schema-interface");
|
|
148
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return schema_interface_2.ValidationError; } });
|
|
149
|
+
Object.defineProperty(exports, "normalizeValidationError", { enumerable: true, get: function () { return schema_interface_2.normalizeValidationError; } });
|
|
150
|
+
var adapters_1 = require("./adapters");
|
|
151
|
+
Object.defineProperty(exports, "joi", { enumerable: true, get: function () { return adapters_1.joi; } });
|
|
152
|
+
Object.defineProperty(exports, "yup", { enumerable: true, get: function () { return adapters_1.yup; } });
|
|
153
|
+
Object.defineProperty(exports, "customValidator", { enumerable: true, get: function () { return adapters_1.fn; } });
|
|
154
|
+
Object.defineProperty(exports, "classValidator", { enumerable: true, get: function () { return adapters_1.classValidator; } });
|
|
144
155
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/validation/index.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/validation/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oEAAoE;;;AAmDpE,4BAuEC;AAuDD,oBAIC;AAED,sBAIC;AAED,wBAIC;AAGD,wCAEC;AAnMD,sCAAkD;AAClD,yDAK4B;AAE5B,0DAA0D;AAC1D,IAAI,CAAM,CAAC;AACX,IAAI,CAAC;IACH,YAAA,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAAC,MAAM,CAAC;IACP,mCAAmC;AACrC,CAAC;AAED,MAAM,MAAM,GAAG,IAAA,8BAAqB,EAAC,YAAY,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AmB;AAAE,0GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard validation error structure
|
|
3
|
+
*/
|
|
4
|
+
export interface ValidationIssue {
|
|
5
|
+
path: (string | number)[];
|
|
6
|
+
message: string;
|
|
7
|
+
code: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Standard validation error class
|
|
11
|
+
* Compatible with ZodError structure
|
|
12
|
+
*/
|
|
13
|
+
export declare class ValidationError extends Error {
|
|
14
|
+
readonly issues: ValidationIssue[];
|
|
15
|
+
constructor(issues: ValidationIssue[]);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Universal validation schema interface
|
|
19
|
+
* This is what Zod naturally implements! No breaking changes needed.
|
|
20
|
+
*/
|
|
21
|
+
export interface ValidationSchema<T = any> {
|
|
22
|
+
/**
|
|
23
|
+
* Parse data asynchronously and return validated result
|
|
24
|
+
* Throws ValidationError on validation failure
|
|
25
|
+
*/
|
|
26
|
+
parseAsync(data: unknown): Promise<T>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if an object implements the ValidationSchema interface
|
|
30
|
+
*/
|
|
31
|
+
export declare function isValidationSchema(obj: any): obj is ValidationSchema;
|
|
32
|
+
/**
|
|
33
|
+
* Convert various error formats to our standard ValidationError
|
|
34
|
+
*/
|
|
35
|
+
export declare function normalizeValidationError(error: any): ValidationError;
|
|
36
|
+
export type InferSchemaType<T> = T extends ValidationSchema<infer U> ? U : never;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Universal Validation Schema Interface for Moro Framework
|
|
3
|
+
// Allows Zod, Joi, Yup, and other validation libraries to work seamlessly
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ValidationError = void 0;
|
|
6
|
+
exports.isValidationSchema = isValidationSchema;
|
|
7
|
+
exports.normalizeValidationError = normalizeValidationError;
|
|
8
|
+
/**
|
|
9
|
+
* Standard validation error class
|
|
10
|
+
* Compatible with ZodError structure
|
|
11
|
+
*/
|
|
12
|
+
class ValidationError extends Error {
|
|
13
|
+
constructor(issues) {
|
|
14
|
+
const message = `Validation failed: ${issues.map(i => i.message).join(', ')}`;
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'ValidationError';
|
|
17
|
+
this.issues = issues;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ValidationError = ValidationError;
|
|
21
|
+
/**
|
|
22
|
+
* Check if an object implements the ValidationSchema interface
|
|
23
|
+
*/
|
|
24
|
+
function isValidationSchema(obj) {
|
|
25
|
+
return obj && typeof obj.parseAsync === 'function';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Convert various error formats to our standard ValidationError
|
|
29
|
+
*/
|
|
30
|
+
function normalizeValidationError(error) {
|
|
31
|
+
// Already our format
|
|
32
|
+
if (error instanceof ValidationError) {
|
|
33
|
+
return error;
|
|
34
|
+
}
|
|
35
|
+
// Zod error format
|
|
36
|
+
if (error && error.issues && Array.isArray(error.issues)) {
|
|
37
|
+
return new ValidationError(error.issues.map((issue) => ({
|
|
38
|
+
path: issue.path || [],
|
|
39
|
+
message: issue.message || 'Validation failed',
|
|
40
|
+
code: issue.code || 'invalid',
|
|
41
|
+
})));
|
|
42
|
+
}
|
|
43
|
+
// Joi error format
|
|
44
|
+
if (error && error.details && Array.isArray(error.details)) {
|
|
45
|
+
return new ValidationError(error.details.map((detail) => ({
|
|
46
|
+
path: detail.path || [],
|
|
47
|
+
message: detail.message || 'Validation failed',
|
|
48
|
+
code: detail.type || 'invalid',
|
|
49
|
+
})));
|
|
50
|
+
}
|
|
51
|
+
// Yup error format
|
|
52
|
+
if (error && error.errors && Array.isArray(error.errors)) {
|
|
53
|
+
return new ValidationError(error.errors.map((msg, index) => ({
|
|
54
|
+
path: error.path ? [error.path] : [index],
|
|
55
|
+
message: msg,
|
|
56
|
+
code: error.type || 'invalid',
|
|
57
|
+
})));
|
|
58
|
+
}
|
|
59
|
+
// Generic error
|
|
60
|
+
return new ValidationError([
|
|
61
|
+
{
|
|
62
|
+
path: [],
|
|
63
|
+
message: error.message || String(error),
|
|
64
|
+
code: 'unknown',
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=schema-interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-interface.js","sourceRoot":"","sources":["../../../src/core/validation/schema-interface.ts"],"names":[],"mappings":";AAAA,2DAA2D;AAC3D,0EAA0E;;;AAyC1E,gDAEC;AAKD,4DA+CC;AApFD;;;GAGG;AACH,MAAa,eAAgB,SAAQ,KAAK;IAGxC,YAAY,MAAyB;QACnC,MAAM,OAAO,GAAG,sBAAsB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AATD,0CASC;AAcD;;GAEG;AACH,SAAgB,kBAAkB,CAAC,GAAQ;IACzC,OAAO,GAAG,IAAI,OAAO,GAAG,CAAC,UAAU,KAAK,UAAU,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,SAAgB,wBAAwB,CAAC,KAAU;IACjD,qBAAqB;IACrB,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,mBAAmB;IACnB,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACzD,OAAO,IAAI,eAAe,CACxB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KA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KAAK,CAAC;YACvC,IAAI,EAAE,SAAS;SAChB;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -15,9 +15,14 @@ export { MoroEventBus } from './core/events';
|
|
|
15
15
|
export type { EventContext, EventPayload, EventBusOptions, ModuleEventBus, GlobalEventBus, EventMetrics, SystemEvents, EventHandler, } from './types/events';
|
|
16
16
|
export { createFrameworkLogger, logger } from './core/logger';
|
|
17
17
|
export { validate, body, query, params, combineSchemas, z } from './core/validation';
|
|
18
|
-
export type { ValidationConfig, ValidationResult,
|
|
18
|
+
export type { ValidationConfig, ValidationResult, ValidationErrorDetail, ValidatedRequest, } from './core/validation';
|
|
19
|
+
export type { ValidationSchema, ValidationError, InferSchemaType, } from './core/validation/schema-interface';
|
|
20
|
+
export { normalizeValidationError } from './core/validation/schema-interface';
|
|
21
|
+
export { joi, yup, fn as customValidator, classValidator } from './core/validation/adapters';
|
|
19
22
|
export { defineModule, ModuleLoader, ModuleDiscovery, autoDiscoverModuleDirectories, } from './core/modules';
|
|
20
23
|
export type { ModuleDefinition, ModuleRoute, ModuleSocket, ModuleConfig } from './types/module';
|
|
24
|
+
export type { WebSocketAdapter, WebSocketAdapterOptions, WebSocketNamespace, WebSocketConnection, WebSocketEmitter, WebSocketMiddleware, WebSocketEventHandler, } from './core/networking/websocket-adapter';
|
|
25
|
+
export { SocketIOAdapter, WSAdapter } from './core/networking/adapters';
|
|
21
26
|
export { createRoute, defineRoute, EXECUTION_PHASES } from './core/routing';
|
|
22
27
|
export { IntelligentRoutingManager, RouteRegistry } from './core/routing/app-integration';
|
|
23
28
|
export type { RouteBuilder, RouteSchema, CompiledRoute, HttpMethod, AuthConfig, RateLimitConfig, CacheConfig, MiddlewarePhases, ExecutionPhase, } from './core/routing';
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
exports.MiddlewareManager = exports.resetConfig = exports.isConfigInitialized = exports.getGlobalConfig = exports.initializeConfig = exports.getConfigValue = exports.envVar = exports.requireEnvVars = exports.isStaging = exports.isProduction = exports.isDevelopment = exports.getEnvJson = exports.getEnvArray = exports.getEnvVar = exports.createModuleConfig = exports.getConfig = exports.generateDocsFromIntelligentRoutes = exports.createDocumentationSystem = exports.AppDocumentationManager = exports.DocumentationSystem = exports.RouteRegistry = exports.IntelligentRoutingManager = exports.EXECUTION_PHASES = exports.defineRoute = exports.createRoute = exports.autoDiscoverModuleDirectories = void 0;
|
|
17
|
+
exports.yup = exports.joi = exports.normalizeValidationError = exports.z = exports.combineSchemas = exports.params = exports.query = exports.body = exports.validate = exports.logger = exports.createFrameworkLogger = exports.MoroEventBus = exports.middleware = exports.HOOK_EVENTS = exports.HookManager = exports.CircuitBreaker = exports.withTimeout = exports.withRetry = exports.withCaching = exports.withLogging = exports.ServiceLifecycle = exports.ServiceScope = exports.FunctionalContainer = exports.Container = exports.ServiceRegistry = exports.WebSocketManager = exports.simpleMiddleware = exports.builtInMiddleware = exports.httpMiddleware = exports.MoroHttpServer = exports.createWorkerHandler = exports.createLambdaHandler = exports.createEdgeHandler = exports.createNodeHandler = exports.createRuntimeAdapter = exports.CloudflareWorkersAdapter = exports.AWSLambdaAdapter = exports.VercelEdgeAdapter = exports.NodeRuntimeAdapter = exports.providers = exports.auth = exports.MoroJSAuth = exports.createAuthMiddleware = exports.createAppWorker = exports.createAppLambda = exports.createAppEdge = exports.createAppNode = exports.createApp = exports.MoroCore = exports.Moro = void 0;
|
|
18
|
+
exports.MiddlewareManager = exports.resetConfig = exports.isConfigInitialized = exports.getGlobalConfig = exports.initializeConfig = exports.getConfigValue = exports.envVar = exports.requireEnvVars = exports.isStaging = exports.isProduction = exports.isDevelopment = exports.getEnvJson = exports.getEnvArray = exports.getEnvVar = exports.createModuleConfig = exports.getConfig = exports.generateDocsFromIntelligentRoutes = exports.createDocumentationSystem = exports.AppDocumentationManager = exports.DocumentationSystem = exports.RouteRegistry = exports.IntelligentRoutingManager = exports.EXECUTION_PHASES = exports.defineRoute = exports.createRoute = exports.WSAdapter = exports.SocketIOAdapter = exports.autoDiscoverModuleDirectories = exports.ModuleDiscovery = exports.ModuleLoader = exports.defineModule = exports.classValidator = exports.customValidator = void 0;
|
|
19
19
|
// MoroJS Framework - Main Entry Point
|
|
20
20
|
var moro_1 = require("./moro");
|
|
21
21
|
Object.defineProperty(exports, "Moro", { enumerable: true, get: function () { return moro_1.Moro; } });
|
|
@@ -75,7 +75,7 @@ Object.defineProperty(exports, "MoroEventBus", { enumerable: true, get: function
|
|
|
75
75
|
var logger_1 = require("./core/logger");
|
|
76
76
|
Object.defineProperty(exports, "createFrameworkLogger", { enumerable: true, get: function () { return logger_1.createFrameworkLogger; } });
|
|
77
77
|
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
78
|
-
// Validation System
|
|
78
|
+
// Universal Validation System
|
|
79
79
|
var validation_1 = require("./core/validation");
|
|
80
80
|
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return validation_1.validate; } });
|
|
81
81
|
Object.defineProperty(exports, "body", { enumerable: true, get: function () { return validation_1.body; } });
|
|
@@ -83,12 +83,23 @@ Object.defineProperty(exports, "query", { enumerable: true, get: function () { r
|
|
|
83
83
|
Object.defineProperty(exports, "params", { enumerable: true, get: function () { return validation_1.params; } });
|
|
84
84
|
Object.defineProperty(exports, "combineSchemas", { enumerable: true, get: function () { return validation_1.combineSchemas; } });
|
|
85
85
|
Object.defineProperty(exports, "z", { enumerable: true, get: function () { return validation_1.z; } });
|
|
86
|
+
var schema_interface_1 = require("./core/validation/schema-interface");
|
|
87
|
+
Object.defineProperty(exports, "normalizeValidationError", { enumerable: true, get: function () { return schema_interface_1.normalizeValidationError; } });
|
|
88
|
+
var adapters_1 = require("./core/validation/adapters");
|
|
89
|
+
Object.defineProperty(exports, "joi", { enumerable: true, get: function () { return adapters_1.joi; } });
|
|
90
|
+
Object.defineProperty(exports, "yup", { enumerable: true, get: function () { return adapters_1.yup; } });
|
|
91
|
+
Object.defineProperty(exports, "customValidator", { enumerable: true, get: function () { return adapters_1.fn; } });
|
|
92
|
+
Object.defineProperty(exports, "classValidator", { enumerable: true, get: function () { return adapters_1.classValidator; } });
|
|
86
93
|
// Module System
|
|
87
94
|
var modules_1 = require("./core/modules");
|
|
88
95
|
Object.defineProperty(exports, "defineModule", { enumerable: true, get: function () { return modules_1.defineModule; } });
|
|
89
96
|
Object.defineProperty(exports, "ModuleLoader", { enumerable: true, get: function () { return modules_1.ModuleLoader; } });
|
|
90
97
|
Object.defineProperty(exports, "ModuleDiscovery", { enumerable: true, get: function () { return modules_1.ModuleDiscovery; } });
|
|
91
98
|
Object.defineProperty(exports, "autoDiscoverModuleDirectories", { enumerable: true, get: function () { return modules_1.autoDiscoverModuleDirectories; } });
|
|
99
|
+
// Built-in WebSocket Adapters
|
|
100
|
+
var adapters_2 = require("./core/networking/adapters");
|
|
101
|
+
Object.defineProperty(exports, "SocketIOAdapter", { enumerable: true, get: function () { return adapters_2.SocketIOAdapter; } });
|
|
102
|
+
Object.defineProperty(exports, "WSAdapter", { enumerable: true, get: function () { return adapters_2.WSAdapter; } });
|
|
92
103
|
// Intelligent Routing System
|
|
93
104
|
var routing_1 = require("./core/routing");
|
|
94
105
|
Object.defineProperty(exports, "createRoute", { enumerable: true, get: function () { return routing_1.createRoute; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,sCAAsC;AACtC,+BAQgB;AAPd,4FAAA,IAAI,OAAA;AACJ,gGAAA,IAAI,OAAY;AAChB,iGAAA,SAAS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AA;AACV,sGAAA,aAAa,OAAA;AACb,qGAAA,YAAY,OAAA;AACZ,kGAAA,SAAS,OAAA;AACT,uGAAA,cAAc,OAAA;AACd,+FAAA,MAAM,OAAA;AACN,uGAAA,cAAc,OAAA;AAGhB,wCAAoG;AAA3F,0GAAA,gBAAgB,OAAA;AAAE,yGAAA,eAAe,OAAA;AAAE,6GAAA,mBAAmB,OAAA;AAAE,qGAAA,WAAW,OAAA;AAK5E,oBAAoB;AACpB,gDAAsD;AAA7C,+GAAA,iBAAiB,OAAA;AAc1B,WAAW;AACX,sEAAoD;AACpD,2DAAyC"}
|
package/dist/moro.d.ts
CHANGED
|
@@ -60,21 +60,29 @@ export declare class Moro extends EventEmitter {
|
|
|
60
60
|
loadModule(moduleOrPath: ModuleConfig | string): Promise<this>;
|
|
61
61
|
database(adapter: any): this;
|
|
62
62
|
websocket(namespace: string, handlers: Record<string, Function>): this;
|
|
63
|
+
listen(callback?: () => void): void;
|
|
63
64
|
listen(port: number, callback?: () => void): void;
|
|
64
65
|
listen(port: number, host: string, callback?: () => void): void;
|
|
65
66
|
getHandler(): any;
|
|
66
67
|
private handleDirectRoutes;
|
|
68
|
+
private routeCache;
|
|
69
|
+
private staticRouteMap;
|
|
70
|
+
private dynamicRoutesBySegments;
|
|
67
71
|
private findMatchingRoute;
|
|
68
72
|
private pathToRegex;
|
|
69
73
|
get events(): MoroEventBus;
|
|
70
74
|
get core(): MoroCore;
|
|
71
75
|
private addRoute;
|
|
76
|
+
private organizeRouteForLookup;
|
|
72
77
|
private registerDirectRoutes;
|
|
73
78
|
private rateLimitStore;
|
|
74
79
|
private checkRateLimit;
|
|
75
80
|
private setupDefaultMiddleware;
|
|
76
81
|
private autoDiscoverModules;
|
|
77
82
|
private importModule;
|
|
83
|
+
private clusterWorkers;
|
|
84
|
+
private startWithClustering;
|
|
85
|
+
private handleWorkerMessage;
|
|
78
86
|
}
|
|
79
87
|
export declare function createApp(options?: MoroOptions): Moro;
|
|
80
88
|
export declare function createAppNode(options?: Omit<MoroOptions, 'runtime'>): Moro;
|