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.
Files changed (37) hide show
  1. package/README.md +252 -55
  2. package/dist/database.d.ts +1 -1
  3. package/dist/database.js +1 -1
  4. package/dist/decorators/exception.advanced.d.ts +286 -18
  5. package/dist/decorators/exception.advanced.d.ts.map +1 -1
  6. package/dist/decorators/exception.advanced.js +410 -17
  7. package/dist/decorators/exception.decorators.d.ts +92 -2
  8. package/dist/decorators/exception.decorators.d.ts.map +1 -1
  9. package/dist/decorators/exception.decorators.js +120 -5
  10. package/dist/decorators/formatter.decorators.d.ts +93 -0
  11. package/dist/decorators/formatter.decorators.d.ts.map +1 -0
  12. package/dist/decorators/formatter.decorators.js +131 -0
  13. package/dist/decorators/guard.decorators.d.ts +2 -2
  14. package/dist/decorators/http.decorators.d.ts +3 -2
  15. package/dist/decorators/http.decorators.d.ts.map +1 -1
  16. package/dist/decorators/pipe.decorators.d.ts +2 -2
  17. package/dist/decorators/pipe.decorators.d.ts.map +1 -1
  18. package/dist/decorators/pipe.decorators.js +2 -2
  19. package/dist/dto.js +1 -1
  20. package/dist/factory.d.ts +1 -1
  21. package/dist/factory.d.ts.map +1 -1
  22. package/dist/factory.js +55 -6
  23. package/dist/filters/exception.filters.d.ts +124 -0
  24. package/dist/filters/exception.filters.d.ts.map +1 -0
  25. package/dist/filters/exception.filters.js +208 -0
  26. package/dist/index.d.ts +3 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +4 -1
  29. package/dist/pipes/validation.pipe.d.ts +3 -3
  30. package/dist/pipes/validation.pipe.d.ts.map +1 -1
  31. package/dist/pipes/validation.pipe.js +39 -11
  32. package/dist/schema-registry.d.ts +51 -0
  33. package/dist/schema-registry.d.ts.map +1 -0
  34. package/dist/schema-registry.js +134 -0
  35. package/dist/testing/index.d.ts +2 -2
  36. package/dist/testing/index.js +2 -2
  37. 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();
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WynkJS Testing Module
3
- * Provides utilities for testing WynkJS applications
4
- * Similar to @nestjs/testing
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WynkJS Testing Module
3
- * Provides utilities for testing WynkJS applications
4
- * Similar to @nestjs/testing
3
+ * Built-in testing utilities for WynkJS applications
4
+ * Works with Bun's native test runner
5
5
  */
6
6
  import { container } from "tsyringe";
7
7
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wynkjs",
3
- "version": "1.0.3",
4
- "description": "A high-performance TypeScript framework built on Elysia for Bun with NestJS-style decorators - 20x faster than Express",
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
- "nestjs-alternative",
25
+ "bun-framework",
26
+ "typescript-decorators",
22
27
  "dependency-injection",
23
28
  "rest-api",
24
29
  "backend",