vortez 4.1.1

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 (86) hide show
  1. package/.gitignore +13 -0
  2. package/LICENSE +201 -0
  3. package/Notes.md +12 -0
  4. package/README.md +372 -0
  5. package/build/Beta/JwtManager.d.ts +114 -0
  6. package/build/Beta/JwtManager.js +249 -0
  7. package/build/Beta/JwtManager.js.map +1 -0
  8. package/build/Beta/Mail.d.ts +60 -0
  9. package/build/Beta/Mail.js +192 -0
  10. package/build/Beta/Mail.js.map +1 -0
  11. package/build/Config.d.ts +39 -0
  12. package/build/Config.js +33 -0
  13. package/build/Config.js.map +1 -0
  14. package/build/ConsoleUI.d.ts +57 -0
  15. package/build/ConsoleUI.js +110 -0
  16. package/build/ConsoleUI.js.map +1 -0
  17. package/build/Debug.d.ts +154 -0
  18. package/build/Debug.js +256 -0
  19. package/build/Debug.js.map +1 -0
  20. package/build/LoggerManager/Logger.d.ts +23 -0
  21. package/build/LoggerManager/Logger.js +23 -0
  22. package/build/LoggerManager/Logger.js.map +1 -0
  23. package/build/LoggerManager/LoggerManager.d.ts +18 -0
  24. package/build/LoggerManager/LoggerManager.js +30 -0
  25. package/build/LoggerManager/LoggerManager.js.map +1 -0
  26. package/build/Server/BodyParser.d.ts +125 -0
  27. package/build/Server/BodyParser.js +162 -0
  28. package/build/Server/BodyParser.js.map +1 -0
  29. package/build/Server/Cookie.d.ts +72 -0
  30. package/build/Server/Cookie.js +102 -0
  31. package/build/Server/Cookie.js.map +1 -0
  32. package/build/Server/Request.d.ts +61 -0
  33. package/build/Server/Request.js +79 -0
  34. package/build/Server/Request.js.map +1 -0
  35. package/build/Server/Response.d.ts +90 -0
  36. package/build/Server/Response.js +241 -0
  37. package/build/Server/Response.js.map +1 -0
  38. package/build/Server/Rule.d.ts +81 -0
  39. package/build/Server/Rule.js +146 -0
  40. package/build/Server/Rule.js.map +1 -0
  41. package/build/Server/Server.d.ts +157 -0
  42. package/build/Server/Server.js +330 -0
  43. package/build/Server/Server.js.map +1 -0
  44. package/build/Server/Session.d.ts +66 -0
  45. package/build/Server/Session.js +97 -0
  46. package/build/Server/Session.js.map +1 -0
  47. package/build/Server/WebSocket/Chunk.d.ts +36 -0
  48. package/build/Server/WebSocket/Chunk.js +81 -0
  49. package/build/Server/WebSocket/Chunk.js.map +1 -0
  50. package/build/Server/WebSocket/WebSocket.d.ts +70 -0
  51. package/build/Server/WebSocket/WebSocket.js +184 -0
  52. package/build/Server/WebSocket/WebSocket.js.map +1 -0
  53. package/build/Template.d.ts +32 -0
  54. package/build/Template.js +69 -0
  55. package/build/Template.js.map +1 -0
  56. package/build/Utilities/Env.d.ts +75 -0
  57. package/build/Utilities/Env.js +123 -0
  58. package/build/Utilities/Env.js.map +1 -0
  59. package/build/Utilities/Path.d.ts +18 -0
  60. package/build/Utilities/Path.js +27 -0
  61. package/build/Utilities/Path.js.map +1 -0
  62. package/build/Utilities/Utilities.d.ts +147 -0
  63. package/build/Utilities/Utilities.js +110 -0
  64. package/build/Utilities/Utilities.js.map +1 -0
  65. package/build/Vortez.d.ts +20 -0
  66. package/build/Vortez.js +22 -0
  67. package/build/Vortez.js.map +1 -0
  68. package/changes.md +89 -0
  69. package/examples/in-docs.js +96 -0
  70. package/global/Source/Logo_960.png +0 -0
  71. package/global/Source/Logo_SM_960.png +0 -0
  72. package/global/Style/Template/Error.css +30 -0
  73. package/global/Style/Template/Folder.css +77 -0
  74. package/global/Style/Template/Template.css +128 -0
  75. package/global/Template/Error.vhtml +29 -0
  76. package/global/Template/Folder.vhtml +41 -0
  77. package/package.json +47 -0
  78. package/tests/Template/template.js +18 -0
  79. package/tests/Template/template.txt +13 -0
  80. package/tests/Template/template.vhtml +23 -0
  81. package/tests/debug.js +28 -0
  82. package/tests/jwtManager/jwtManager.js +110 -0
  83. package/tests/test.js +129 -0
  84. package/tests/test.vhtml +14 -0
  85. package/tests/utilities.js +28 -0
  86. package/tests/websocket.vhtml +86 -0
@@ -0,0 +1,123 @@
1
+ import FS, { promises as FSPromises } from "fs";
2
+ import PATH from "path";
3
+ import Debug from "../Debug.js";
4
+ export class Env {
5
+ static get variables() { return process.env; }
6
+ /**
7
+ * Check if a file exists
8
+ * @param path - The path to the file
9
+ * @returns A promise that resolves to true if the file exists, false otherwise
10
+ */
11
+ static async fileExists(path) {
12
+ return FSPromises.access(path).then(() => true).catch(() => false);
13
+ }
14
+ /**
15
+ * Load the environment variables from the given path
16
+ * @param path - The path to the environment variables file
17
+ * @param options - Options to load the environment variables
18
+ * @returns The loaded environment variables as an object
19
+ * @throws Error if the environment variables file does not exist and cannot be created
20
+ * @throws Error if the environment variables file is not readable
21
+ */
22
+ static async load(path, options = {}) {
23
+ Debug.log(`loading environment variables from &C6[${path}]`);
24
+ const defaultEnv = options.defaultEnv ?? {};
25
+ const setEnv = options.setEnv ?? true;
26
+ if (!await this.fileExists(path)) {
27
+ await FSPromises.mkdir(PATH.dirname(path), { recursive: true });
28
+ const env = this.toEnv(defaultEnv);
29
+ await FSPromises.writeFile(path, env, 'utf-8');
30
+ Debug.log(`environment variables file &C6[${path}]&R does not exist, creating it`);
31
+ }
32
+ const env = await FSPromises.readFile(path, 'utf-8');
33
+ const result = this.extractEnv(env, defaultEnv);
34
+ if (setEnv)
35
+ this.setMany(result);
36
+ Debug.log(`environment variables loaded from &C6[${path}]`);
37
+ return result;
38
+ }
39
+ static loadSync(path, options = {}) {
40
+ Debug.log(`loading environment variables from &C6[${path}]`);
41
+ const defaultEnv = options.defaultEnv ?? {};
42
+ const setEnv = options.setEnv ?? true;
43
+ if (!FS.existsSync(path)) {
44
+ FS.mkdirSync(PATH.dirname(path), { recursive: true });
45
+ const env = this.toEnv(defaultEnv);
46
+ FS.writeFileSync(path, env, 'utf-8');
47
+ Debug.log(`environment variables file &C6[${path}]&R does not exist, creating it`);
48
+ }
49
+ const env = FS.readFileSync(path, 'utf-8');
50
+ const result = this.extractEnv(env, defaultEnv);
51
+ if (setEnv)
52
+ this.setMany(result);
53
+ Debug.log(`environment variables loaded from &C6[${path}]`);
54
+ return result;
55
+ }
56
+ /**
57
+ * Extract the environment variables from the given content
58
+ * @param content - The content to extract the environment variables from
59
+ * @param defaultEnv - The default environment variables to use if none are found
60
+ * @returns The extracted environment variables as an object
61
+ */
62
+ static extractEnv(content, defaultEnv = {}) {
63
+ const lines = content.split('\n');
64
+ const result = { ...defaultEnv };
65
+ for (const line of lines) {
66
+ const trimmedLine = line.trim();
67
+ if (!trimmedLine || trimmedLine.startsWith('#'))
68
+ continue;
69
+ const index = trimmedLine.indexOf('=');
70
+ if (index === -1)
71
+ continue;
72
+ const key = trimmedLine.substring(0, index).trim();
73
+ const value = trimmedLine.substring(index + 1).trim();
74
+ if (!key)
75
+ continue;
76
+ result[key] = value;
77
+ }
78
+ return result;
79
+ }
80
+ static get(key, options = {}) {
81
+ const value = process.env[key];
82
+ if (value)
83
+ return value;
84
+ const { default: defaultVal, warning = false } = options;
85
+ if (warning)
86
+ Debug.log(`&B3[warn]:&R &C6${key} &C3is not defined${defaultVal ? `, &C2using: &C6${defaultVal}` : ''}`);
87
+ return defaultVal;
88
+ }
89
+ /**
90
+ * Set an environment variable
91
+ * @param key - The environment variable key
92
+ * @param value - The value to set
93
+ */
94
+ static set(key, value) {
95
+ process.env[key] = value;
96
+ }
97
+ /**
98
+ * Set multiple environment variables at once
99
+ * @param env - An object containing key-value pairs of environment variables
100
+ */
101
+ static setMany(env) {
102
+ for (const key in env)
103
+ process.env[key] = env[key] ?? '';
104
+ }
105
+ /**
106
+ * Delete an environment variable
107
+ * @param key - The environment variable key to delete
108
+ */
109
+ static delete(key) {
110
+ delete process.env[key];
111
+ }
112
+ /**
113
+ * Convert an EnvList to a .env-formatted string
114
+ * @param env - The environment variables object
115
+ * @returns A string in .env format
116
+ */
117
+ static toEnv(env) {
118
+ const filtered = Object.entries(env).filter(([key, value]) => typeof key === 'string' && typeof value === 'string');
119
+ return filtered.map(([key, value]) => `${key}=${value}`).join('\n');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G,CAAC,mBAAmB,GAAG,qBAAqB,UAAU,CAAC,CAAC,CAAC,kBAAkB,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtH,OAAO,UAAU,CAAC;IACtB,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,GAAG,CAAC,GAAW,EAAE,KAAa;QACxC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC7B,CAAC;IACD;;;OAGG;IACI,MAAM,CAAC,OAAO,CAAC,GAAgB;QAClC,KAAK,MAAM,GAAG,IAAI,GAAG;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC7D,CAAC;IACD;;;OAGG;IACI,MAAM,CAAC,MAAM,CAAC,GAAW;QAC5B,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,GAAgB;QAChC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC;QACpH,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC;CACJ;AAeD,eAAe,GAAG,CAAC"}
@@ -0,0 +1,18 @@
1
+ export declare class Path {
2
+ static readonly moduleDir: string;
3
+ static readonly moduleMain: string;
4
+ /**
5
+ * Clean a path by replacing all backslashes with the system-specific separator.
6
+ * @param path - The path to clean
7
+ * @returns The cleaned path
8
+ */
9
+ static normalize(path: string): string;
10
+ /**
11
+ * Convert a relative path to an absolute one, relative to the module root.
12
+ * @param path - The relative path
13
+ * @returns The absolute path
14
+ */
15
+ static relative(path: string): string;
16
+ }
17
+ export declare namespace Path { }
18
+ export default Path;
@@ -0,0 +1,27 @@
1
+ import PATH from 'path';
2
+ import URL from 'url';
3
+ export class Path {
4
+ static moduleDir = PATH.dirname(PATH.dirname(PATH.dirname(URL.fileURLToPath(import.meta.url))));
5
+ static moduleMain = PATH.join(this.moduleDir, 'build/Vortez.js');
6
+ /**
7
+ * Clean a path by replacing all backslashes with the system-specific separator.
8
+ * @param path - The path to clean
9
+ * @returns The cleaned path
10
+ */
11
+ static normalize(path) {
12
+ path = path.replace(/[\\/]/gi, PATH.sep);
13
+ return path;
14
+ }
15
+ /**
16
+ * Convert a relative path to an absolute one, relative to the module root.
17
+ * @param path - The relative path
18
+ * @returns The absolute path
19
+ */
20
+ static relative(path) {
21
+ path = this.normalize(path);
22
+ path = PATH.join(this.moduleDir, path);
23
+ return PATH.normalize(path);
24
+ }
25
+ }
26
+ export default Path;
27
+ //# sourceMappingURL=Path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Path.js","sourceRoot":"","sources":["../../src/Utilities/Path.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,OAAO,IAAI;IACN,MAAM,CAAU,SAAS,GAAW,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACjH,MAAM,CAAU,UAAU,GAAW,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;IACzF;;;;OAIG;IACI,MAAM,CAAC,SAAS,CAAC,IAAY;QAChC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IAChB,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,IAAY;QAC/B,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;;AAGL,eAAe,IAAI,CAAC"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * @author NetFeez <codefeez.dev@gmail.com>
3
+ * @description add useful functions to the Vortez.
4
+ * @license Apache-2.0
5
+ */
6
+ import _Path from './Path.js';
7
+ import _Env from './Env.js';
8
+ export declare class Utilities {
9
+ /**
10
+ * Deeply compares two objects.
11
+ * @param obj1 - The first object to compare
12
+ * @param obj2 - The second object to compare
13
+ * @returns True if the objects are equal, false otherwise
14
+ */
15
+ static deepEqual(obj1: any, obj2: any): boolean;
16
+ /**
17
+ * Flattens an object into a single-level object.
18
+ * @param object - The object to flatten
19
+ * @param depth - Maximum depth to flatten (default: 10)
20
+ * @returns The flattened object
21
+ */
22
+ static flattenObject<T extends object, D extends number = 10>(object: T, depth?: D): Utilities.Flatten.Object<T, D>;
23
+ protected static flattenCore(object: any, depth?: number, prefix?: string): any;
24
+ /**
25
+ * Reconstructs a nested object from a flattened one.
26
+ * @template Result - The type of the unflattened object
27
+ * @param obj - The object to unflatten
28
+ * @returns The unflattened object
29
+ */
30
+ static unFlattenObject<Result extends any = any>(obj: any): Result;
31
+ /**
32
+ * Delays execution for the specified number of milliseconds.
33
+ * @param ms - The number of milliseconds to wait
34
+ * @returns A promise that resolves after the given time
35
+ */
36
+ static sleep(ms: number): Promise<void>;
37
+ /**
38
+ * Encodes a string to base64url format.
39
+ * @param data - The string to encode
40
+ * @returns The base64url-encoded string
41
+ */
42
+ static base64UrlEncode(data: string): string;
43
+ /**
44
+ * Decodes a base64url-encoded string.
45
+ * @param data - The base64url-encoded string to decode
46
+ * @returns The decoded string
47
+ */
48
+ static base64UrlDecode(data: string): string;
49
+ }
50
+ export declare namespace Utilities {
51
+ export import Path = _Path;
52
+ export import Env = _Env;
53
+ namespace Types {
54
+ type NumListAdd = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
55
+ type strToNum<str extends string> = str extends `${infer num extends number}` ? num : never;
56
+ /**
57
+ * add one to a number
58
+ * @template Number the number to add one to
59
+ * @returns the number added one
60
+ */
61
+ export type Inc<Number extends number | string> = (`${Number}` extends `${infer surPlus}${NumListAdd[number]}` ? `${Number}` extends `${surPlus}${infer unit extends number}` ? unit extends Exclude<NumListAdd[number], 9> ? strToNum<`${surPlus}${NumListAdd[unit]}`> : strToNum<`${surPlus extends `${infer Num extends number}` ? '' : '1'}${surPlus extends '' ? '' : Inc<surPlus>}${NumListAdd[unit]}`> : number : number);
62
+ /**
63
+ * union to intersection
64
+ * @template U the union to convert
65
+ * @returns the intersection of the union
66
+ */
67
+ export type UnionToIntersection<U extends object> = ((U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I extends object ? {
68
+ [K in keyof I]: I[K] extends object ? UnionToIntersection<I[K]> : I[K];
69
+ } : I : never);
70
+ /**
71
+ * convert the object property with undefined to optional
72
+ * @template T the object to convert
73
+ * @returns the converted object
74
+ */
75
+ export type undefinedToPartial<T extends object> = {
76
+ [K in keyof T as undefined extends T[K] ? never : K]: T[K];
77
+ } & {
78
+ [K in keyof T as undefined extends T[K] ? K : never]?: Exclude<T[K], undefined>;
79
+ };
80
+ export type Document = {
81
+ [key: string]: any;
82
+ };
83
+ export {};
84
+ }
85
+ namespace Flatten {
86
+ /**
87
+ * flatten an object into a single level and return an union of all the keys
88
+ * @template T the object to flatten
89
+ * @template depth the depth to flatten
90
+ * @template index the current index
91
+ * @returns the flattened object keys as a union
92
+ */
93
+ type ResourceKeys<T extends Types.Document, depth extends number = 5, index extends number = 1> = {
94
+ [K in keyof T]-?: depth extends index ? K & string : Exclude<T[K], undefined> extends infer U ? U extends any[] ? K & string : U extends object ? `${K & string}.${ResourceKeys<U, depth, Types.Inc<index>>}` : K & string : "fail_in_flatten_inference";
95
+ }[keyof T];
96
+ /**
97
+ * flatten an object into a single level and return an union of all the keys
98
+ * @template T the object to flatten
99
+ * @template depth the depth to flatten
100
+ * @template index the current index
101
+ * @returns the flattened object keys as a union
102
+ */
103
+ type RecurseObject<T extends Types.Document, Keys extends string> = (Keys extends `${infer K}.${infer Rest}` ? K extends keyof T ? undefined extends T[K] ? RecurseObject<Exclude<T[K], undefined>, Rest> | undefined : RecurseObject<T[K], Rest> : never : undefined extends T ? Keys extends keyof Exclude<T, undefined> ? Exclude<T, undefined>[Keys] | undefined : never : Keys extends keyof T ? T[Keys] : never);
104
+ /**
105
+ * flatten an object into a single level
106
+ * @template T the object to flatten
107
+ * @template depth the depth to flatten
108
+ * @template index the current index
109
+ * @returns the flattened object
110
+ */
111
+ export type Object<T extends Types.Document, depth extends number = 5, index extends number = 1> = Types.undefinedToPartial<{
112
+ [P in ResourceKeys<T, depth, index>]: RecurseObject<T, P>;
113
+ }>;
114
+ export {};
115
+ }
116
+ namespace UnFlatten {
117
+ /**
118
+ * split a string by a delimiter
119
+ * @template S the string to split
120
+ * @template Delimiter the delimiter to split by
121
+ * @returns the split string
122
+ */
123
+ type Split<S extends string, Delimiter extends string> = (S extends `${infer T}${Delimiter}${infer U}` ? [T, ...Split<U, Delimiter>] : [S]);
124
+ /**
125
+ * build a nested object from a string
126
+ * @template Path the path to build
127
+ * @template Value the value to build
128
+ * @returns the nested object
129
+ */
130
+ type BuildNestedObject<Path extends string[], Value> = (Path extends [infer Head extends string, ...infer Tail extends string[]] ? Types.undefinedToPartial<{
131
+ [K in Head]: BuildNestedObject<Tail, Value>;
132
+ }> : Value);
133
+ /**
134
+ * unFlatten an object into a single level
135
+ * @template T the object to unFlatten
136
+ * @returns the unFlattened object
137
+ */
138
+ export type Object<T extends Types.Document> = Types.UnionToIntersection<Types.undefinedToPartial<({
139
+ [K in keyof T]-?: BuildNestedObject<Split<Extract<K, string>, ".">, T[K]>;
140
+ }[keyof T])>>;
141
+ export {};
142
+ }
143
+ interface env {
144
+ [key: string]: string;
145
+ }
146
+ }
147
+ export default Utilities;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @author NetFeez <codefeez.dev@gmail.com>
3
+ * @description add useful functions to the Vortez.
4
+ * @license Apache-2.0
5
+ */
6
+ import _Path from './Path.js';
7
+ import _Env from './Env.js';
8
+ export class Utilities {
9
+ /**
10
+ * Deeply compares two objects.
11
+ * @param obj1 - The first object to compare
12
+ * @param obj2 - The second object to compare
13
+ * @returns True if the objects are equal, false otherwise
14
+ */
15
+ static deepEqual(obj1, obj2) {
16
+ if (obj1 === obj2)
17
+ return true;
18
+ if (typeof obj1 !== typeof obj2 ||
19
+ obj1 === null || obj2 === null)
20
+ return false;
21
+ const keys1 = Object.keys(obj1);
22
+ const keys2 = Object.keys(obj2);
23
+ if (keys1.length !== keys2.length)
24
+ return false;
25
+ for (const key of keys1)
26
+ if (!keys2.includes(key) ||
27
+ !this.deepEqual(obj1[key], obj2[key]))
28
+ return false;
29
+ return true;
30
+ }
31
+ /**
32
+ * Flattens an object into a single-level object.
33
+ * @param object - The object to flatten
34
+ * @param depth - Maximum depth to flatten (default: 10)
35
+ * @returns The flattened object
36
+ */
37
+ static flattenObject(object, depth = 10) {
38
+ return this.flattenCore(object, depth);
39
+ }
40
+ static flattenCore(object, depth = 10, prefix = '') {
41
+ const result = {};
42
+ for (const key in object) {
43
+ const newKey = prefix ? `${prefix}.${key}` : key;
44
+ const value = object[key];
45
+ if (typeof value === 'object' && !Array.isArray(value) && value !== null && depth > 0) {
46
+ Object.assign(result, Utilities.flattenCore(value, depth - 1, newKey));
47
+ }
48
+ else {
49
+ result[newKey] = value;
50
+ }
51
+ }
52
+ return result;
53
+ }
54
+ /**
55
+ * Reconstructs a nested object from a flattened one.
56
+ * @template Result - The type of the unflattened object
57
+ * @param obj - The object to unflatten
58
+ * @returns The unflattened object
59
+ */
60
+ static unFlattenObject(obj) {
61
+ const result = {};
62
+ for (const key in obj) {
63
+ const value = obj[key];
64
+ const [first, ...rest] = key.split('.');
65
+ if (rest.length === 0)
66
+ result[first] = value;
67
+ else {
68
+ const last = rest.pop();
69
+ const subObj = result[first] ?? {};
70
+ let current = subObj;
71
+ rest.forEach((k) => {
72
+ current = current[k] ?? (current[k] = {});
73
+ });
74
+ current[last] = value;
75
+ result[first] = subObj;
76
+ }
77
+ }
78
+ return result;
79
+ }
80
+ /**
81
+ * Delays execution for the specified number of milliseconds.
82
+ * @param ms - The number of milliseconds to wait
83
+ * @returns A promise that resolves after the given time
84
+ */
85
+ static sleep(ms) {
86
+ return new Promise(resolve => setTimeout(resolve, ms));
87
+ }
88
+ /**
89
+ * Encodes a string to base64url format.
90
+ * @param data - The string to encode
91
+ * @returns The base64url-encoded string
92
+ */
93
+ static base64UrlEncode(data) {
94
+ return Buffer.from(data).toString('base64url');
95
+ }
96
+ /**
97
+ * Decodes a base64url-encoded string.
98
+ * @param data - The base64url-encoded string to decode
99
+ * @returns The decoded string
100
+ */
101
+ static base64UrlDecode(data) {
102
+ return Buffer.from(data, 'base64url').toString('utf8');
103
+ }
104
+ }
105
+ (function (Utilities) {
106
+ Utilities.Path = _Path;
107
+ Utilities.Env = _Env;
108
+ })(Utilities || (Utilities = {}));
109
+ export default Utilities;
110
+ //# sourceMappingURL=Utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utilities.js","sourceRoot":"","sources":["../../src/Utilities/Utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,WAAW,CAAC;AAC9B,OAAO,IAAI,MAAM,UAAU,CAAC;AAE5B,MAAM,OAAO,SAAS;IAClB;;;;;OAKG;IACI,MAAM,CAAC,SAAS,CAAC,IAAS,EAA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;QAC1B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,eAAe,CAAC,IAAY;QACtC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,eAAe,CAAC,IAAY;QACtC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3D,CAAC;CACJ;AAED,WAAiB,SAAS;IACR,cAAI,GAAG,KAAK,CAAC;IACb,aAAG,GAAG,IAAI,CAAC;AAoJ7B,CAAC,EAtJgB,SAAS,KAAT,SAAS,QAsJzB;AACD,eAAe,SAAS,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @author NetFeez <codefeez.dev@gmail.com>
3
+ * @description Exports the main utilities of the Vortez module.
4
+ * @module NetFeez-Labs.Vortez
5
+ * @license Apache-2.0
6
+ */
7
+ import Config from "./Config.js";
8
+ import Debug from "./Debug.js";
9
+ import Logger from "./LoggerManager/Logger.js";
10
+ import Template from "./Template.js";
11
+ import Vortez from "./Server/Server.js";
12
+ import Utilities from "./Utilities/Utilities.js";
13
+ import JwtManager from "./Beta/JwtManager.js";
14
+ import Mail from "./Beta/Mail.js";
15
+ export declare const Beta: {
16
+ JwtManager: typeof JwtManager;
17
+ Mail: typeof Mail;
18
+ };
19
+ export { Debug, Logger, Utilities, Template, Config, };
20
+ export default Vortez;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @author NetFeez <codefeez.dev@gmail.com>
3
+ * @description Exports the main utilities of the Vortez module.
4
+ * @module NetFeez-Labs.Vortez
5
+ * @license Apache-2.0
6
+ */
7
+ // Imports the main utilities of the Vortez module.
8
+ import Config from "./Config.js";
9
+ import Debug from "./Debug.js";
10
+ import Logger from "./LoggerManager/Logger.js";
11
+ import Template from "./Template.js";
12
+ import Vortez from "./Server/Server.js";
13
+ import Utilities from "./Utilities/Utilities.js";
14
+ // Imports the beta utilities of the Vortez module.
15
+ import JwtManager from "./Beta/JwtManager.js";
16
+ import Mail from "./Beta/Mail.js";
17
+ // Exports the beta utilities of the Vortez module.
18
+ export const Beta = { JwtManager, Mail };
19
+ // Exports the main utilities of the Vortez module.
20
+ export { Debug, Logger, Utilities, Template, Config, };
21
+ export default Vortez;
22
+ //# sourceMappingURL=Vortez.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vortez.js","sourceRoot":"","sources":["../src/Vortez.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,mDAAmD;AACnD,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,SAAS,MAAM,0BAA0B,CAAC;AAEjD,mDAAmD;AACnD,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAC9C,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAElC,mDAAmD;AACnD,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAEzC,mDAAmD;AACnD,OAAO,EACN,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,QAAQ,EACnB,MAAM,GACN,CAAC;AACF,eAAe,MAAM,CAAC"}
package/changes.md ADDED
@@ -0,0 +1,89 @@
1
+
2
+ # version (4.1.0)
3
+ ## ➕ Added
4
+ - **(Logger)**: added to help in log with prefix.
5
+ - this was exported from `Vortez`
6
+ ```ts
7
+ import { Logger } from `vortez`
8
+ ```
9
+ - **(LoggerManager)**: added to manager the Vortez logs.
10
+ - this was exported from namespace `Vortez`
11
+ ```ts
12
+ import Vortez from `vortez`
13
+ Vortez.LoggerManager
14
+ ```
15
+ ## 🐞 Fixes
16
+ - The default templates now use absolute path to prevent errors
17
+ - Note: the user can use relative path`s
18
+ ## ✏️ Changes
19
+ - **(Debug)**: Debugging tools were added.
20
+ - Added methods to help in debug time: log, warn, info and error.
21
+ - The default value to show was changed to true.
22
+ - **(Server)**: The server startup was changed.
23
+ - Added methods: start, stop, restart
24
+ - Now the user should use the method start
25
+ ```ts
26
+ import Vortez from 'vortez';
27
+ const server = new Vortez();
28
+ server.start();
29
+ ```
30
+ - The server config can be provided in constructor or changed after start.
31
+ ```ts
32
+ // example 1;
33
+ const server = new Vortez({
34
+ port: 80, host: 'localhost', ssl: {
35
+ pubKey: 'public.pem',
36
+ privKey: 'private.pem'
37
+ port: 443
38
+ }
39
+ });
40
+ // example 2
41
+ const server = new Vortez();
42
+ server.config.port = 80;
43
+ server.config.host = 'localhost';
44
+ server.config.ssl = {
45
+ pubKey: 'public.pem',
46
+ privKey: 'private.pem'
47
+ port: 443
48
+ }
49
+ ```
50
+
51
+ # version (4.0.0)
52
+ ## 📒 Notes
53
+ - The project was migrated to TypeScript.
54
+ - Properties and methods now start with a camelcase.
55
+ - Skipped version 3.7.0 to make way for 4.0.0.
56
+ ## ✏️ Changes
57
+ - **(Template)**: The `load` method now works with async/await instead of directly returning a promise.
58
+ - **(Template)**: syntax of array changed.
59
+ ```text
60
+ // from
61
+ $(name) { the key is $key with value $value }
62
+ $(name, customKeyName, customValueName) { the key is $customKeyName with value $customValueName }
63
+ // to
64
+ $(name) { the key is %key% with value %value% }
65
+ $(name, customKeyName, customValueName) { the key is %customKeyName% with value %customValueName% }
66
+ ```
67
+ - **(Utilities)**: Added the functions `loadEnv`, `flattenObject`, and `sleep`.
68
+ - **(Utilities)**: Modified the `flattenObject` function to retain null and undefined values and provide better typing.
69
+ - **(Debug)**: Can now only be used from the `getInstance` method (subject to possible changes).
70
+ - **(Config)**: Converted to a singleton.
71
+ - **(Response)**: The `send` method is now limited to receiving `string|buffer`.
72
+ - **(Response)**: The `sendFile`, `sendFolder`, and `sendTemplate` methods now work with async/await.
73
+ - **(Response)**: The `POST.content` object will no longer be a `Map` when appropriate, but a `Request.POST.VarList` object.
74
+ - **(Response)**: The `POST.files` object will always have the type `Request.POST.FileList`.
75
+ - **(Request)**: The `GET` attribute is now `searchParams`.
76
+ - **(Request)**: Request body processing has been delegated to `BodyParser.ts`.
77
+ - **(Request)**: The type of search param is no longer a `Map`, but an object `{ [key: string]: string | undefined }`.
78
+ - **(WebSocket)**: The logic behind WebSocket reception was separated into `Chunk.ts`.
79
+ - **(WebSocket)**: `Chunk.ts` was optimized.
80
+ - **(Beta)**: `JsonWT` was converted to `JwtManager`.
81
+
82
+
83
+
84
+ # version (x.x.x)
85
+ ## 📒 Notes
86
+ ## ➕ Added
87
+ ## ❌ Removed
88
+ ## 🐞 Fixes
89
+ ## ✏️ Changes