wynkjs 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +252 -55
- package/dist/database.d.ts +1 -1
- package/dist/database.js +1 -1
- package/dist/decorators/exception.advanced.d.ts +286 -18
- package/dist/decorators/exception.advanced.d.ts.map +1 -1
- package/dist/decorators/exception.advanced.js +410 -17
- package/dist/decorators/exception.decorators.d.ts +92 -2
- package/dist/decorators/exception.decorators.d.ts.map +1 -1
- package/dist/decorators/exception.decorators.js +120 -5
- package/dist/decorators/formatter.decorators.d.ts +93 -0
- package/dist/decorators/formatter.decorators.d.ts.map +1 -0
- package/dist/decorators/formatter.decorators.js +131 -0
- package/dist/decorators/guard.decorators.d.ts +2 -2
- package/dist/decorators/http.decorators.d.ts +3 -2
- package/dist/decorators/http.decorators.d.ts.map +1 -1
- package/dist/decorators/pipe.decorators.d.ts +2 -2
- package/dist/decorators/pipe.decorators.d.ts.map +1 -1
- package/dist/decorators/pipe.decorators.js +2 -2
- package/dist/dto.js +1 -1
- package/dist/factory.d.ts +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +55 -6
- package/dist/filters/exception.filters.d.ts +124 -0
- package/dist/filters/exception.filters.d.ts.map +1 -0
- package/dist/filters/exception.filters.js +208 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/pipes/validation.pipe.d.ts +3 -3
- package/dist/pipes/validation.pipe.d.ts.map +1 -1
- package/dist/pipes/validation.pipe.js +39 -11
- package/dist/schema-registry.d.ts +51 -0
- package/dist/schema-registry.d.ts.map +1 -0
- package/dist/schema-registry.js +134 -0
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/package.json +8 -3
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Registry for storing and retrieving custom error messages
|
|
3
|
+
* This allows validation pipes to look up custom error messages from schemas
|
|
4
|
+
*/
|
|
5
|
+
class SchemaRegistry {
|
|
6
|
+
static instance;
|
|
7
|
+
errorMessages = {};
|
|
8
|
+
routeSchemas = {};
|
|
9
|
+
constructor() { }
|
|
10
|
+
static getInstance() {
|
|
11
|
+
if (!SchemaRegistry.instance) {
|
|
12
|
+
SchemaRegistry.instance = new SchemaRegistry();
|
|
13
|
+
}
|
|
14
|
+
return SchemaRegistry.instance;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Register custom error messages for a schema
|
|
18
|
+
* @param schemaKey Unique key for the schema (e.g., class name + method)
|
|
19
|
+
* @param schema The TypeBox schema object
|
|
20
|
+
*/
|
|
21
|
+
registerSchema(schemaKey, schema) {
|
|
22
|
+
if (!schema || typeof schema !== "object")
|
|
23
|
+
return;
|
|
24
|
+
const messages = {};
|
|
25
|
+
this.extractErrorMessages(schema, "", messages);
|
|
26
|
+
if (Object.keys(messages).length > 0) {
|
|
27
|
+
this.errorMessages[schemaKey] = messages;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Register route-to-schema mapping
|
|
32
|
+
* @param method HTTP method (GET, POST, etc.)
|
|
33
|
+
* @param path Route path
|
|
34
|
+
* @param schemaKey The schema key
|
|
35
|
+
* @param validationType Type of validation (body, query, params)
|
|
36
|
+
*/
|
|
37
|
+
registerRoute(method, path, schemaKey, validationType) {
|
|
38
|
+
const routeKey = `${method.toUpperCase()}:${path}`;
|
|
39
|
+
if (!this.routeSchemas[routeKey]) {
|
|
40
|
+
this.routeSchemas[routeKey] = [];
|
|
41
|
+
}
|
|
42
|
+
this.routeSchemas[routeKey].push({ schemaKey, validationType });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get schema key for a route and validation type
|
|
46
|
+
* @param method HTTP method
|
|
47
|
+
* @param path Route path (actual request path with values)
|
|
48
|
+
* @param validationType Type of validation
|
|
49
|
+
* @returns Schema key or undefined
|
|
50
|
+
*/
|
|
51
|
+
getSchemaKeyForRoute(method, path, validationType) {
|
|
52
|
+
// First try exact match
|
|
53
|
+
const exactKey = `${method.toUpperCase()}:${path}`;
|
|
54
|
+
if (this.routeSchemas[exactKey]) {
|
|
55
|
+
const found = this.routeSchemas[exactKey].find((s) => s.validationType === validationType);
|
|
56
|
+
if (found)
|
|
57
|
+
return found.schemaKey;
|
|
58
|
+
}
|
|
59
|
+
// If no exact match, try to match patterns
|
|
60
|
+
// e.g., request path "/users/10/100" should match pattern "/users/:id1/:id2"
|
|
61
|
+
for (const [routeKey, schemas] of Object.entries(this.routeSchemas)) {
|
|
62
|
+
// Split only on the first colon to separate method from path
|
|
63
|
+
const colonIndex = routeKey.indexOf(":");
|
|
64
|
+
const routeMethod = routeKey.substring(0, colonIndex);
|
|
65
|
+
const routePath = routeKey.substring(colonIndex + 1);
|
|
66
|
+
if (routeMethod !== method.toUpperCase())
|
|
67
|
+
continue;
|
|
68
|
+
// Check if the routePath is a pattern (contains :param)
|
|
69
|
+
if (routePath.includes(":")) {
|
|
70
|
+
// Convert pattern to regex
|
|
71
|
+
const pattern = routePath
|
|
72
|
+
.replace(/:[^/]+/g, "([^/]+)") // Replace :param with regex group
|
|
73
|
+
.replace(/\//g, "\\/"); // Escape slashes
|
|
74
|
+
const regex = new RegExp(`^${pattern}$`);
|
|
75
|
+
if (regex.test(path)) {
|
|
76
|
+
const found = schemas.find((s) => s.validationType === validationType);
|
|
77
|
+
if (found)
|
|
78
|
+
return found.schemaKey;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Recursively extract error messages from schema
|
|
86
|
+
*/
|
|
87
|
+
extractErrorMessages(schema, path, messages) {
|
|
88
|
+
// Check for custom error message at current level
|
|
89
|
+
if (schema.error || schema.errorMessage) {
|
|
90
|
+
messages[path || "root"] = schema.error || schema.errorMessage;
|
|
91
|
+
}
|
|
92
|
+
// Recurse into object properties
|
|
93
|
+
if (schema.type === "object" && schema.properties) {
|
|
94
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
95
|
+
const newPath = path ? `${path}.${key}` : key;
|
|
96
|
+
this.extractErrorMessages(value, newPath, messages);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Recurse into array items
|
|
100
|
+
if (schema.type === "array" && schema.items) {
|
|
101
|
+
const newPath = path ? `${path}[]` : "[]";
|
|
102
|
+
this.extractErrorMessages(schema.items, newPath, messages);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get custom error message for a field path
|
|
107
|
+
* @param schemaKey The schema key
|
|
108
|
+
* @param fieldPath The field path (e.g., "user.email")
|
|
109
|
+
* @returns Custom error message or undefined
|
|
110
|
+
*/
|
|
111
|
+
getErrorMessage(schemaKey, fieldPath) {
|
|
112
|
+
const schemaMessages = this.errorMessages[schemaKey];
|
|
113
|
+
if (!schemaMessages)
|
|
114
|
+
return undefined;
|
|
115
|
+
// Try exact match first
|
|
116
|
+
if (schemaMessages[fieldPath]) {
|
|
117
|
+
return schemaMessages[fieldPath];
|
|
118
|
+
}
|
|
119
|
+
// Try without array indices (e.g., "items.0.name" -> "items[].name")
|
|
120
|
+
const normalizedPath = fieldPath.replace(/\.\d+\./g, "[].");
|
|
121
|
+
if (schemaMessages[normalizedPath]) {
|
|
122
|
+
return schemaMessages[normalizedPath];
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Clear all registered schemas (useful for testing)
|
|
128
|
+
*/
|
|
129
|
+
clear() {
|
|
130
|
+
this.errorMessages = {};
|
|
131
|
+
this.routeSchemas = {};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export const schemaRegistry = SchemaRegistry.getInstance();
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WynkJS Testing Module
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Built-in testing utilities for WynkJS applications
|
|
4
|
+
* Works with Bun's native test runner
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* Test class for creating isolated testing modules
|
package/dist/testing/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wynkjs",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A high-performance TypeScript framework built on Elysia for Bun with
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "A high-performance TypeScript framework built on Elysia for Bun with elegant decorator-based architecture - 10x faster than Express/NestJS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"wynk",
|
|
11
11
|
"wynkjs",
|
|
12
12
|
"elysia",
|
|
13
|
+
"nestjs",
|
|
14
|
+
"nestjs alternative",
|
|
15
|
+
"express",
|
|
16
|
+
"expressjs alternative",
|
|
13
17
|
"bun",
|
|
14
18
|
"framework",
|
|
15
19
|
"typescript",
|
|
@@ -18,7 +22,8 @@
|
|
|
18
22
|
"web-framework",
|
|
19
23
|
"http",
|
|
20
24
|
"api",
|
|
21
|
-
"
|
|
25
|
+
"bun-framework",
|
|
26
|
+
"typescript-decorators",
|
|
22
27
|
"dependency-injection",
|
|
23
28
|
"rest-api",
|
|
24
29
|
"backend",
|