azurajs 3.0.1 → 3.0.2

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 (106) hide show
  1. package/dist/config/index.js +128 -6
  2. package/dist/config/index.js.map +1 -1
  3. package/dist/config/index.mjs +130 -1
  4. package/dist/config/index.mjs.map +1 -1
  5. package/dist/core/index.js +1100 -11
  6. package/dist/core/index.js.map +1 -1
  7. package/dist/core/index.mjs +1102 -3
  8. package/dist/core/index.mjs.map +1 -1
  9. package/dist/decorators/index.js +117 -87
  10. package/dist/decorators/index.js.map +1 -1
  11. package/dist/decorators/index.mjs +98 -1
  12. package/dist/decorators/index.mjs.map +1 -1
  13. package/dist/index.js +2592 -236
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +2537 -9
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/middleware/index.js +16 -7
  18. package/dist/middleware/index.js.map +1 -1
  19. package/dist/middleware/index.mjs +17 -1
  20. package/dist/middleware/index.mjs.map +1 -1
  21. package/dist/plugins/index.js +1056 -73
  22. package/dist/plugins/index.js.map +1 -1
  23. package/dist/plugins/index.mjs +1042 -1
  24. package/dist/plugins/index.mjs.map +1 -1
  25. package/dist/types/index.js +49 -12
  26. package/dist/types/index.js.map +1 -1
  27. package/dist/types/index.mjs +49 -2
  28. package/dist/types/index.mjs.map +1 -1
  29. package/dist/utils/index.js +551 -50
  30. package/dist/utils/index.js.map +1 -1
  31. package/dist/utils/index.mjs +541 -3
  32. package/dist/utils/index.mjs.map +1 -1
  33. package/package.json +35 -17
  34. package/{dist/chunk-DR254CWJ.mjs → src/config/ConfigModule.ts} +169 -132
  35. package/src/config/index.ts +1 -0
  36. package/src/core/index.ts +2 -0
  37. package/src/core/router.ts +284 -0
  38. package/{dist/chunk-EYAHUNC7.mjs → src/core/server.ts} +590 -699
  39. package/src/decorators/Route.ts +110 -0
  40. package/src/decorators/index.ts +23 -0
  41. package/src/index.ts +12 -0
  42. package/src/middleware/LoggingMiddleware.ts +20 -0
  43. package/src/middleware/index.ts +1 -0
  44. package/src/plugins/CORSPlugin.ts +56 -0
  45. package/src/plugins/CircuitBreakerPlugin.ts +84 -0
  46. package/src/plugins/CompressionPlugin.ts +80 -0
  47. package/src/plugins/ETagPlugin.ts +31 -0
  48. package/src/plugins/HealthCheckPlugin.ts +57 -0
  49. package/src/plugins/HelmetPlugin.ts +89 -0
  50. package/src/plugins/JWTPlugin.ts +132 -0
  51. package/src/plugins/MultipartPlugin.ts +168 -0
  52. package/src/plugins/ProxyPlugin.ts +89 -0
  53. package/src/plugins/RateLimitPlugin.ts +96 -0
  54. package/src/plugins/RequestIdPlugin.ts +21 -0
  55. package/src/plugins/SSEPlugin.ts +114 -0
  56. package/src/plugins/SessionPlugin.ts +98 -0
  57. package/src/plugins/StaticPlugin.ts +152 -0
  58. package/src/plugins/TimeoutPlugin.ts +33 -0
  59. package/src/plugins/index.ts +18 -0
  60. package/src/types/common.type.ts +82 -0
  61. package/src/types/config.type.ts +57 -0
  62. package/{dist/chunk-OWUGAI5V.mjs → src/types/http/status.ts} +49 -51
  63. package/src/types/index.ts +55 -0
  64. package/src/types/plugins/plugin.type.ts +170 -0
  65. package/src/types/reflect.d.ts +14 -0
  66. package/src/types/routes.type.ts +70 -0
  67. package/src/utils/HttpError.ts +62 -0
  68. package/src/utils/IpResolver.ts +30 -0
  69. package/src/utils/Logger.ts +144 -0
  70. package/src/utils/Parser.ts +182 -0
  71. package/src/utils/cookies/CookieManager.ts +48 -0
  72. package/src/utils/index.ts +9 -0
  73. package/{dist/chunk-UWIFSGSQ.mjs → src/utils/validators/DTOValidator.ts} +145 -141
  74. package/src/utils/validators/SchemaValidator.ts +45 -0
  75. package/dist/chunk-3UFAWS2V.js +0 -392
  76. package/dist/chunk-3UFAWS2V.js.map +0 -1
  77. package/dist/chunk-4LSFAAZW.js +0 -4
  78. package/dist/chunk-4LSFAAZW.js.map +0 -1
  79. package/dist/chunk-7NSRIVZM.js +0 -54
  80. package/dist/chunk-7NSRIVZM.js.map +0 -1
  81. package/dist/chunk-AOG6NYAM.js +0 -144
  82. package/dist/chunk-AOG6NYAM.js.map +0 -1
  83. package/dist/chunk-DR254CWJ.mjs.map +0 -1
  84. package/dist/chunk-EYAHUNC7.mjs.map +0 -1
  85. package/dist/chunk-HHDQPIJN.mjs +0 -19
  86. package/dist/chunk-HHDQPIJN.mjs.map +0 -1
  87. package/dist/chunk-HHZNAGGI.js +0 -702
  88. package/dist/chunk-HHZNAGGI.js.map +0 -1
  89. package/dist/chunk-KJM5XCAY.js +0 -21
  90. package/dist/chunk-KJM5XCAY.js.map +0 -1
  91. package/dist/chunk-NLSZKAPA.mjs +0 -1044
  92. package/dist/chunk-NLSZKAPA.mjs.map +0 -1
  93. package/dist/chunk-OWUGAI5V.mjs.map +0 -1
  94. package/dist/chunk-POPNQEOK.js +0 -1063
  95. package/dist/chunk-POPNQEOK.js.map +0 -1
  96. package/dist/chunk-QPRW4YU4.js +0 -134
  97. package/dist/chunk-QPRW4YU4.js.map +0 -1
  98. package/dist/chunk-REJDZUZ5.mjs +0 -382
  99. package/dist/chunk-REJDZUZ5.mjs.map +0 -1
  100. package/dist/chunk-TC6N6TJZ.mjs +0 -100
  101. package/dist/chunk-TC6N6TJZ.mjs.map +0 -1
  102. package/dist/chunk-TEUXKMXP.js +0 -122
  103. package/dist/chunk-TEUXKMXP.js.map +0 -1
  104. package/dist/chunk-UWIFSGSQ.mjs.map +0 -1
  105. package/dist/chunk-YPBKY4KY.mjs +0 -3
  106. package/dist/chunk-YPBKY4KY.mjs.map +0 -1
@@ -0,0 +1,48 @@
1
+ import type { CookieOptions } from "../../types/common.type.js";
2
+
3
+ export function serializeCookie(
4
+ name: string,
5
+ value: string,
6
+ options: CookieOptions = {},
7
+ ): string {
8
+ let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
9
+
10
+ if (options.maxAge != null) {
11
+ cookie += `; Max-Age=${Math.floor(options.maxAge)}`;
12
+ }
13
+
14
+ if (options.expires) {
15
+ cookie += `; Expires=${options.expires.toUTCString()}`;
16
+ }
17
+
18
+ if (options.domain) {
19
+ cookie += `; Domain=${options.domain}`;
20
+ }
21
+
22
+ cookie += `; Path=${options.path ?? "/"}`;
23
+
24
+ if (options.secure) {
25
+ cookie += "; Secure";
26
+ }
27
+
28
+ if (options.httpOnly !== false) {
29
+ cookie += "; HttpOnly";
30
+ }
31
+
32
+ if (options.sameSite) {
33
+ cookie += `; SameSite=${options.sameSite}`;
34
+ }
35
+
36
+ return cookie;
37
+ }
38
+
39
+ export function clearCookieHeader(
40
+ name: string,
41
+ options: CookieOptions = {},
42
+ ): string {
43
+ return serializeCookie(name, "", {
44
+ ...options,
45
+ maxAge: 0,
46
+ expires: new Date(0),
47
+ });
48
+ }
@@ -0,0 +1,9 @@
1
+ export { Logger } from "./Logger.js";
2
+ export { HttpError } from "./HttpError.js";
3
+ export { resolveIp } from "./IpResolver.js";
4
+ export { parseQueryString, parseCookies, parseBody, parseUrl } from "./Parser.js";
5
+ export { serializeCookie, clearCookieHeader } from "./cookies/CookieManager.js";
6
+ export { DTOValidator } from "./validators/DTOValidator.js";
7
+ export type { Schema, ValidationResult, ValidationError } from "./validators/DTOValidator.js";
8
+ export { SchemaValidator } from "./validators/SchemaValidator.js";
9
+ export type { ExternalSchema, SchemaValidationResult } from "./validators/SchemaValidator.js";
@@ -1,141 +1,145 @@
1
- // src/utils/validators/DTOValidator.ts
2
- var DTOValidator = class {
3
- static validate(data, schema) {
4
- const errors = [];
5
- if (data == null || typeof data !== "object") {
6
- return {
7
- valid: false,
8
- errors: [{ field: "_root", message: "Request body must be an object" }]
9
- };
10
- }
11
- for (const [field, rule] of Object.entries(schema)) {
12
- const value = data[field];
13
- if (rule.required && (value === void 0 || value === null || value === "")) {
14
- errors.push({
15
- field,
16
- message: rule.message ?? `${field} is required`,
17
- value
18
- });
19
- continue;
20
- }
21
- if (value === void 0 || value === null) continue;
22
- if (rule.type) {
23
- const actualType = Array.isArray(value) ? "array" : typeof value;
24
- if (actualType !== rule.type) {
25
- errors.push({
26
- field,
27
- message: rule.message ?? `${field} must be of type ${rule.type}`,
28
- value
29
- });
30
- continue;
31
- }
32
- }
33
- if (rule.type === "string" || typeof value === "string") {
34
- if (rule.min !== void 0 && value.length < rule.min) {
35
- errors.push({
36
- field,
37
- message: rule.message ?? `${field} must be at least ${rule.min} characters`,
38
- value
39
- });
40
- }
41
- if (rule.max !== void 0 && value.length > rule.max) {
42
- errors.push({
43
- field,
44
- message: rule.message ?? `${field} must be at most ${rule.max} characters`,
45
- value
46
- });
47
- }
48
- if (rule.pattern && !rule.pattern.test(value)) {
49
- errors.push({
50
- field,
51
- message: rule.message ?? `${field} has invalid format`,
52
- value
53
- });
54
- }
55
- }
56
- if (rule.type === "number" || typeof value === "number") {
57
- if (rule.min !== void 0 && value < rule.min) {
58
- errors.push({
59
- field,
60
- message: rule.message ?? `${field} must be at least ${rule.min}`,
61
- value
62
- });
63
- }
64
- if (rule.max !== void 0 && value > rule.max) {
65
- errors.push({
66
- field,
67
- message: rule.message ?? `${field} must be at most ${rule.max}`,
68
- value
69
- });
70
- }
71
- }
72
- if (rule.type === "array" && Array.isArray(value)) {
73
- if (rule.min !== void 0 && value.length < rule.min) {
74
- errors.push({
75
- field,
76
- message: rule.message ?? `${field} must have at least ${rule.min} items`,
77
- value
78
- });
79
- }
80
- if (rule.max !== void 0 && value.length > rule.max) {
81
- errors.push({
82
- field,
83
- message: rule.message ?? `${field} must have at most ${rule.max} items`,
84
- value
85
- });
86
- }
87
- }
88
- if (rule.enum && !rule.enum.includes(value)) {
89
- errors.push({
90
- field,
91
- message: rule.message ?? `${field} must be one of: ${rule.enum.join(", ")}`,
92
- value
93
- });
94
- }
95
- if (rule.custom) {
96
- const customError = rule.custom(value);
97
- if (customError) {
98
- errors.push({ field, message: customError, value });
99
- }
100
- }
101
- }
102
- return {
103
- valid: errors.length === 0,
104
- errors,
105
- data: errors.length === 0 ? data : void 0
106
- };
107
- }
108
- };
109
-
110
- // src/utils/validators/SchemaValidator.ts
111
- var SchemaValidator = class {
112
- static validate(data, schema) {
113
- if (typeof schema.safeParse === "function") {
114
- const result = schema.safeParse(data);
115
- if (result.success) {
116
- return { valid: true, data: result.data };
117
- }
118
- return { valid: false, errors: result.error };
119
- }
120
- if (typeof schema.parse === "function") {
121
- try {
122
- const parsed = schema.parse(data);
123
- return { valid: true, data: parsed };
124
- } catch (err) {
125
- return { valid: false, errors: err };
126
- }
127
- }
128
- if (typeof schema.validate === "function") {
129
- const result = schema.validate(data);
130
- if (result.error) {
131
- return { valid: false, errors: result.error };
132
- }
133
- return { valid: true, data: result.value };
134
- }
135
- return { valid: true, data };
136
- }
137
- };
138
-
139
- export { DTOValidator, SchemaValidator };
140
- //# sourceMappingURL=chunk-UWIFSGSQ.mjs.map
141
- //# sourceMappingURL=chunk-UWIFSGSQ.mjs.map
1
+ export interface ValidationError {
2
+ field: string;
3
+ message: string;
4
+ value?: any;
5
+ }
6
+
7
+ export interface ValidationResult {
8
+ valid: boolean;
9
+ errors: ValidationError[];
10
+ data?: any;
11
+ }
12
+
13
+ type RuleType = "string" | "number" | "boolean" | "object" | "array";
14
+
15
+ interface FieldRule {
16
+ type?: RuleType;
17
+ required?: boolean;
18
+ min?: number;
19
+ max?: number;
20
+ pattern?: RegExp;
21
+ enum?: any[];
22
+ custom?: (value: any) => string | null;
23
+ message?: string;
24
+ }
25
+
26
+ export type Schema = Record<string, FieldRule>;
27
+
28
+ export class DTOValidator {
29
+ static validate(data: any, schema: Schema): ValidationResult {
30
+ const errors: ValidationError[] = [];
31
+
32
+ if (data == null || typeof data !== "object") {
33
+ return {
34
+ valid: false,
35
+ errors: [{ field: "_root", message: "Request body must be an object" }],
36
+ };
37
+ }
38
+
39
+ for (const [field, rule] of Object.entries(schema)) {
40
+ const value = data[field];
41
+
42
+ if (rule.required && (value === undefined || value === null || value === "")) {
43
+ errors.push({
44
+ field,
45
+ message: rule.message ?? `${field} is required`,
46
+ value,
47
+ });
48
+ continue;
49
+ }
50
+
51
+ if (value === undefined || value === null) continue;
52
+
53
+ if (rule.type) {
54
+ const actualType = Array.isArray(value) ? "array" : typeof value;
55
+ if (actualType !== rule.type) {
56
+ errors.push({
57
+ field,
58
+ message: rule.message ?? `${field} must be of type ${rule.type}`,
59
+ value,
60
+ });
61
+ continue;
62
+ }
63
+ }
64
+
65
+ if (rule.type === "string" || typeof value === "string") {
66
+ if (rule.min !== undefined && value.length < rule.min) {
67
+ errors.push({
68
+ field,
69
+ message: rule.message ?? `${field} must be at least ${rule.min} characters`,
70
+ value,
71
+ });
72
+ }
73
+ if (rule.max !== undefined && value.length > rule.max) {
74
+ errors.push({
75
+ field,
76
+ message: rule.message ?? `${field} must be at most ${rule.max} characters`,
77
+ value,
78
+ });
79
+ }
80
+ if (rule.pattern && !rule.pattern.test(value)) {
81
+ errors.push({
82
+ field,
83
+ message: rule.message ?? `${field} has invalid format`,
84
+ value,
85
+ });
86
+ }
87
+ }
88
+
89
+ if (rule.type === "number" || typeof value === "number") {
90
+ if (rule.min !== undefined && value < rule.min) {
91
+ errors.push({
92
+ field,
93
+ message: rule.message ?? `${field} must be at least ${rule.min}`,
94
+ value,
95
+ });
96
+ }
97
+ if (rule.max !== undefined && value > rule.max) {
98
+ errors.push({
99
+ field,
100
+ message: rule.message ?? `${field} must be at most ${rule.max}`,
101
+ value,
102
+ });
103
+ }
104
+ }
105
+
106
+ if (rule.type === "array" && Array.isArray(value)) {
107
+ if (rule.min !== undefined && value.length < rule.min) {
108
+ errors.push({
109
+ field,
110
+ message: rule.message ?? `${field} must have at least ${rule.min} items`,
111
+ value,
112
+ });
113
+ }
114
+ if (rule.max !== undefined && value.length > rule.max) {
115
+ errors.push({
116
+ field,
117
+ message: rule.message ?? `${field} must have at most ${rule.max} items`,
118
+ value,
119
+ });
120
+ }
121
+ }
122
+
123
+ if (rule.enum && !rule.enum.includes(value)) {
124
+ errors.push({
125
+ field,
126
+ message: rule.message ?? `${field} must be one of: ${rule.enum.join(", ")}`,
127
+ value,
128
+ });
129
+ }
130
+
131
+ if (rule.custom) {
132
+ const customError = rule.custom(value);
133
+ if (customError) {
134
+ errors.push({ field, message: customError, value });
135
+ }
136
+ }
137
+ }
138
+
139
+ return {
140
+ valid: errors.length === 0,
141
+ errors,
142
+ data: errors.length === 0 ? data : undefined,
143
+ };
144
+ }
145
+ }
@@ -0,0 +1,45 @@
1
+ export interface ExternalSchema {
2
+ parse?: (data: any) => any;
3
+ safeParse?: (data: any) => { success: boolean; data?: any; error?: any };
4
+ validate?: (data: any) => { value?: any; error?: any };
5
+ }
6
+
7
+ export interface SchemaValidationResult {
8
+ valid: boolean;
9
+ data?: any;
10
+ errors?: any;
11
+ }
12
+
13
+ export class SchemaValidator {
14
+ static validate(data: any, schema: ExternalSchema): SchemaValidationResult {
15
+ // Zod-style schema
16
+ if (typeof schema.safeParse === "function") {
17
+ const result = schema.safeParse(data);
18
+ if (result.success) {
19
+ return { valid: true, data: result.data };
20
+ }
21
+ return { valid: false, errors: result.error };
22
+ }
23
+
24
+ // Zod parse (throws on error)
25
+ if (typeof schema.parse === "function") {
26
+ try {
27
+ const parsed = schema.parse(data);
28
+ return { valid: true, data: parsed };
29
+ } catch (err) {
30
+ return { valid: false, errors: err };
31
+ }
32
+ }
33
+
34
+ // Joi-style schema
35
+ if (typeof schema.validate === "function") {
36
+ const result = schema.validate(data);
37
+ if (result.error) {
38
+ return { valid: false, errors: result.error };
39
+ }
40
+ return { valid: true, data: result.value };
41
+ }
42
+
43
+ return { valid: true, data };
44
+ }
45
+ }