vortez 4.1.3 → 5.0.0-dev.15
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/.gitignore +0 -0
- package/LICENSE +0 -0
- package/README.md +235 -289
- package/build/Template.d.ts +16 -2
- package/build/Template.js +20 -8
- package/build/Template.js.map +1 -1
- package/build/Vortez.d.ts +8 -15
- package/build/Vortez.js +8 -16
- package/build/Vortez.js.map +1 -1
- package/build/beta/Beta.d.ts +8 -0
- package/build/beta/Beta.js +9 -0
- package/build/beta/Beta.js.map +1 -0
- package/build/{Beta → beta}/JwtManager.d.ts +0 -0
- package/build/{Beta → beta}/JwtManager.js +1 -1
- package/build/{Beta → beta}/JwtManager.js.map +1 -1
- package/build/{Beta → beta}/Mail.d.ts +1 -1
- package/build/{Beta → beta}/Mail.js +1 -1
- package/build/beta/Mail.js.map +1 -0
- package/build/logger/Debug.d.ts +174 -0
- package/build/logger/Debug.js +295 -0
- package/build/logger/Debug.js.map +1 -0
- package/build/logger/Logger.d.ts +38 -0
- package/build/logger/Logger.js +48 -0
- package/build/logger/Logger.js.map +1 -0
- package/build/{Server → server}/BodyParser.d.ts +0 -0
- package/build/{Server → server}/BodyParser.js +0 -0
- package/build/{Server → server}/BodyParser.js.map +1 -1
- package/build/{Server → server}/Cookie.d.ts +0 -0
- package/build/{Server → server}/Cookie.js +0 -0
- package/build/{Server → server}/Cookie.js.map +1 -1
- package/build/server/LoggerManager.d.ts +21 -0
- package/build/server/LoggerManager.js +30 -0
- package/build/server/LoggerManager.js.map +1 -0
- package/build/{Server → server}/Request.d.ts +4 -2
- package/build/{Server → server}/Request.js +2 -1
- package/build/server/Request.js.map +1 -0
- package/build/{Server → server}/Response.d.ts +4 -1
- package/build/{Server → server}/Response.js +24 -8
- package/build/server/Response.js.map +1 -0
- package/build/{Server → server}/Server.d.ts +20 -67
- package/build/server/Server.js +211 -0
- package/build/server/Server.js.map +1 -0
- package/build/server/ServerDebug.d.ts +17 -0
- package/build/server/ServerDebug.js +67 -0
- package/build/server/ServerDebug.js.map +1 -0
- package/build/server/ServerError.d.ts +18 -0
- package/build/server/ServerError.js +15 -0
- package/build/server/ServerError.js.map +1 -0
- package/build/{Server → server}/Session.d.ts +9 -13
- package/build/{Server → server}/Session.js +34 -35
- package/build/server/Session.js.map +1 -0
- package/build/{Config.d.ts → server/config/Config.d.ts} +19 -3
- package/build/server/config/Config.js +60 -0
- package/build/server/config/Config.js.map +1 -0
- package/build/server/config/ConfigLoader.d.ts +24 -0
- package/build/server/config/ConfigLoader.js +53 -0
- package/build/server/config/ConfigLoader.js.map +1 -0
- package/build/server/config/ConfigValidator.d.ts +71 -0
- package/build/server/config/ConfigValidator.js +131 -0
- package/build/server/config/ConfigValidator.js.map +1 -0
- package/build/server/router/HttpRule.d.ts +69 -0
- package/build/server/router/HttpRule.js +96 -0
- package/build/server/router/HttpRule.js.map +1 -0
- package/build/server/router/Router.d.ts +127 -0
- package/build/server/router/Router.js +211 -0
- package/build/server/router/Router.js.map +1 -0
- package/build/server/router/Rule.d.ts +71 -0
- package/build/server/router/Rule.js +113 -0
- package/build/server/router/Rule.js.map +1 -0
- package/build/server/router/WsRule.d.ts +25 -0
- package/build/server/router/WsRule.js +34 -0
- package/build/server/router/WsRule.js.map +1 -0
- package/build/server/router/middleware/HttpMiddleware.d.ts +35 -0
- package/build/server/router/middleware/HttpMiddleware.js +90 -0
- package/build/server/router/middleware/HttpMiddleware.js.map +1 -0
- package/build/server/router/middleware/Middleware.d.ts +77 -0
- package/build/server/router/middleware/Middleware.js +69 -0
- package/build/server/router/middleware/Middleware.js.map +1 -0
- package/build/server/router/middleware/WsMiddleware.d.ts +24 -0
- package/build/server/router/middleware/WsMiddleware.js +90 -0
- package/build/server/router/middleware/WsMiddleware.js.map +1 -0
- package/build/{Server/WebSocket → server/websocket}/Chunk.d.ts +0 -0
- package/build/{Server/WebSocket → server/websocket}/Chunk.js +0 -0
- package/build/{Server/WebSocket → server/websocket}/Chunk.js.map +1 -1
- package/build/server/websocket/Websocket.d.ts +88 -0
- package/build/{Server/WebSocket/WebSocket.js → server/websocket/Websocket.js} +91 -53
- package/build/server/websocket/Websocket.js.map +1 -0
- package/build/utilities/ConsoleUI.d.ts +88 -0
- package/build/utilities/ConsoleUI.js +141 -0
- package/build/utilities/ConsoleUI.js.map +1 -0
- package/build/utilities/DebugUI.d.ts +66 -0
- package/build/utilities/DebugUI.js +98 -0
- package/build/utilities/DebugUI.js.map +1 -0
- package/build/utilities/Env.d.ts +81 -0
- package/build/{Utilities → utilities}/Env.js +47 -35
- package/build/utilities/Env.js.map +1 -0
- package/build/utilities/Path.d.ts +24 -0
- package/build/utilities/Path.js +36 -0
- package/build/{Utilities → utilities}/Path.js.map +1 -1
- package/build/{Utilities → utilities}/Utilities.d.ts +68 -55
- package/build/{Utilities → utilities}/Utilities.js +36 -19
- package/build/utilities/Utilities.js.map +1 -0
- package/changes.md +122 -88
- package/examples/in-docs.js +0 -0
- package/global/Source/Logo_960.png +0 -0
- package/global/Source/Logo_SM_960.png +0 -0
- package/global/Style/Template/Error.css +0 -0
- package/global/Style/Template/Folder.css +0 -0
- package/global/Style/Template/Template.css +0 -0
- package/global/Template/Error.vhtml +0 -0
- package/global/Template/Folder.vhtml +0 -0
- package/package.json +10 -13
- package/tests/Template/template.js +0 -0
- package/tests/Template/template.txt +0 -0
- package/tests/Template/template.vhtml +0 -0
- package/tests/debug.js +9 -3
- package/tests/jwtManager/jwtManager.js +0 -0
- package/tests/test.env +0 -0
- package/tests/test.js +50 -48
- package/tests/test.vhtml +0 -0
- package/tests/utilities.js +1 -1
- package/tests/websocket.vhtml +0 -0
- package/Notes.md +0 -12
- package/build/Beta/Mail.js.map +0 -1
- package/build/Config.js +0 -33
- package/build/Config.js.map +0 -1
- package/build/ConsoleUI.d.ts +0 -57
- package/build/ConsoleUI.js +0 -110
- package/build/ConsoleUI.js.map +0 -1
- package/build/Debug.d.ts +0 -154
- package/build/Debug.js +0 -256
- package/build/Debug.js.map +0 -1
- package/build/LoggerManager/Logger.d.ts +0 -23
- package/build/LoggerManager/Logger.js +0 -23
- package/build/LoggerManager/Logger.js.map +0 -1
- package/build/LoggerManager/LoggerManager.d.ts +0 -18
- package/build/LoggerManager/LoggerManager.js +0 -30
- package/build/LoggerManager/LoggerManager.js.map +0 -1
- package/build/Server/Request.js.map +0 -1
- package/build/Server/Response.js.map +0 -1
- package/build/Server/Rule.d.ts +0 -81
- package/build/Server/Rule.js +0 -146
- package/build/Server/Rule.js.map +0 -1
- package/build/Server/Server.js +0 -330
- package/build/Server/Server.js.map +0 -1
- package/build/Server/Session.js.map +0 -1
- package/build/Server/WebSocket/WebSocket.d.ts +0 -70
- package/build/Server/WebSocket/WebSocket.js.map +0 -1
- package/build/Utilities/Env.d.ts +0 -75
- package/build/Utilities/Env.js.map +0 -1
- package/build/Utilities/Path.d.ts +0 -18
- package/build/Utilities/Path.js +0 -27
- package/build/Utilities/Utilities.js.map +0 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export declare class Env {
|
|
2
|
+
/**
|
|
3
|
+
* Gets all current environment variables.
|
|
4
|
+
* @returns An object containing key-value pairs of environment variables.
|
|
5
|
+
*/
|
|
6
|
+
static get data(): Env.EnvList;
|
|
7
|
+
/**
|
|
8
|
+
* Load the environment variables from the given path.
|
|
9
|
+
* @param path - The path to the environment variables file.
|
|
10
|
+
* @param options - Options to load the environment variables.
|
|
11
|
+
* @returns A promise that resolves with the loaded environment variables as an object.
|
|
12
|
+
* @throws Error if the environment variables file does not exist and cannot be created.
|
|
13
|
+
* @throws Error if the environment variables file is not readable.
|
|
14
|
+
*/
|
|
15
|
+
static load(path: string, options?: Env.LoadOptions): Promise<Env.EnvList>;
|
|
16
|
+
/**
|
|
17
|
+
* Load the environment variables from the given path synchronously.
|
|
18
|
+
* @param path - The path to the environment variables file.
|
|
19
|
+
* @param options - Options to load the environment variables.
|
|
20
|
+
* @returns The loaded environment variables as an object.
|
|
21
|
+
* @throws Error if the environment variables file does not exist and cannot be created.
|
|
22
|
+
* @throws Error if the environment variables file is not readable.
|
|
23
|
+
*/
|
|
24
|
+
static loadSync(path: string, options?: Env.LoadOptions): Env.EnvList;
|
|
25
|
+
/**
|
|
26
|
+
* Extract the environment variables from the given content.
|
|
27
|
+
* @param content - The content to extract the environment variables from.
|
|
28
|
+
* @param defaultEnv - An optional object of default environment variables to include if not present in the content.
|
|
29
|
+
* @returns An object containing the extracted environment variables merged with defaults.
|
|
30
|
+
*/
|
|
31
|
+
private static extractEnv;
|
|
32
|
+
/**
|
|
33
|
+
* Get the value of an environment variable.
|
|
34
|
+
* @param key - The key of the environment variable to get.
|
|
35
|
+
* @param options - Options to get the environment variable.
|
|
36
|
+
* @param options.default - The default value to return if the environment variable is not set.
|
|
37
|
+
* @param options.warning - If `true`, a warning will be logged if the environment variable is not set.
|
|
38
|
+
* @returns The value of the environment variable or undefined if not set.
|
|
39
|
+
*/
|
|
40
|
+
static get(key: string, options: Env.getOptionsGranted): string;
|
|
41
|
+
static get(key: string, options: Env.getOptions): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Set an environment variable.
|
|
44
|
+
* @param key - The key of the environment variable to set.
|
|
45
|
+
* @param value - The value to set for the environment variable.
|
|
46
|
+
*/
|
|
47
|
+
static set(key: string, value: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Sets multiple environment variables from an object.
|
|
50
|
+
* @param env - An object containing key-value pairs of environment variables to set.
|
|
51
|
+
*/
|
|
52
|
+
static setMany(env: Env.EnvList): void;
|
|
53
|
+
/**
|
|
54
|
+
* Delete an environment variable.
|
|
55
|
+
* @param key - The key of the environment variable to delete.
|
|
56
|
+
*/
|
|
57
|
+
static delete(key: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Convert an EnvList to a .env-formatted string.
|
|
60
|
+
* @param env - The environment variables object.
|
|
61
|
+
* @returns A string in .env format.
|
|
62
|
+
*/
|
|
63
|
+
static toEnv(env: Env.EnvList): string;
|
|
64
|
+
}
|
|
65
|
+
export declare namespace Env {
|
|
66
|
+
interface EnvList {
|
|
67
|
+
[key: string]: string | undefined;
|
|
68
|
+
}
|
|
69
|
+
interface LoadOptions {
|
|
70
|
+
setEnv?: boolean;
|
|
71
|
+
defaultEnv?: EnvList;
|
|
72
|
+
}
|
|
73
|
+
interface getOptions {
|
|
74
|
+
default?: string;
|
|
75
|
+
warning?: boolean;
|
|
76
|
+
}
|
|
77
|
+
type getOptionsGranted = getOptions & {
|
|
78
|
+
default: string;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export default Env;
|
|
@@ -1,41 +1,53 @@
|
|
|
1
|
-
import FS, { promises as
|
|
1
|
+
import FS, { promises as FSP } from "fs";
|
|
2
2
|
import PATH from "path";
|
|
3
|
-
import Debug from "../Debug.js";
|
|
3
|
+
import Debug from "../logger/Debug.js";
|
|
4
|
+
import Utilities from "./Utilities.js";
|
|
4
5
|
export class Env {
|
|
5
|
-
static get variables() { return process.env; }
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
* @returns A promise that resolves to true if the file exists, false otherwise
|
|
7
|
+
* Gets all current environment variables.
|
|
8
|
+
* @returns An object containing key-value pairs of environment variables.
|
|
10
9
|
*/
|
|
11
|
-
static
|
|
12
|
-
return FSPromises.access(path).then(() => true).catch(() => false);
|
|
13
|
-
}
|
|
10
|
+
static get data() { return process.env; }
|
|
14
11
|
/**
|
|
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
|
|
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
|
|
12
|
+
* Load the environment variables from the given path.
|
|
13
|
+
* @param path - The path to the environment variables file.
|
|
14
|
+
* @param options - Options to load the environment variables.
|
|
15
|
+
* @returns A promise that resolves with the loaded environment variables as an object.
|
|
16
|
+
* @throws Error if the environment variables file does not exist and cannot be created.
|
|
17
|
+
* @throws Error if the environment variables file is not readable.
|
|
21
18
|
*/
|
|
22
19
|
static async load(path, options = {}) {
|
|
23
20
|
Debug.log(`loading environment variables from &C6[${path}]`);
|
|
24
21
|
const defaultEnv = options.defaultEnv ?? {};
|
|
25
22
|
const setEnv = options.setEnv ?? true;
|
|
26
|
-
if (!await
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
if (!await Utilities.fileExists(path)) {
|
|
24
|
+
try {
|
|
25
|
+
Debug.log(`environment variables file &C6[${path}]&R does not exist, creating it`);
|
|
26
|
+
await FSP.mkdir(PATH.dirname(path), { recursive: true });
|
|
27
|
+
const env = this.toEnv(defaultEnv);
|
|
28
|
+
await FSP.writeFile(path, env, 'utf-8');
|
|
29
|
+
Debug.log(`environment variables file &C6[${path}]&R &C2was created successfully`);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
Debug.log(`environment variables file &C6[${path}]&R &C1could not be created`);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
31
35
|
}
|
|
32
|
-
const env = await
|
|
36
|
+
const env = await FSP.readFile(path, 'utf-8');
|
|
33
37
|
const result = this.extractEnv(env, defaultEnv);
|
|
34
38
|
if (setEnv)
|
|
35
39
|
this.setMany(result);
|
|
36
40
|
Debug.log(`environment variables loaded from &C6[${path}]`);
|
|
37
41
|
return result;
|
|
38
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Load the environment variables from the given path synchronously.
|
|
45
|
+
* @param path - The path to the environment variables file.
|
|
46
|
+
* @param options - Options to load the environment variables.
|
|
47
|
+
* @returns The loaded environment variables as an object.
|
|
48
|
+
* @throws Error if the environment variables file does not exist and cannot be created.
|
|
49
|
+
* @throws Error if the environment variables file is not readable.
|
|
50
|
+
*/
|
|
39
51
|
static loadSync(path, options = {}) {
|
|
40
52
|
Debug.log(`loading environment variables from &C6[${path}]`);
|
|
41
53
|
const defaultEnv = options.defaultEnv ?? {};
|
|
@@ -54,10 +66,10 @@ export class Env {
|
|
|
54
66
|
return result;
|
|
55
67
|
}
|
|
56
68
|
/**
|
|
57
|
-
* Extract the environment variables from the given content
|
|
58
|
-
* @param content - The content to extract the environment variables from
|
|
59
|
-
* @param defaultEnv -
|
|
60
|
-
* @returns
|
|
69
|
+
* Extract the environment variables from the given content.
|
|
70
|
+
* @param content - The content to extract the environment variables from.
|
|
71
|
+
* @param defaultEnv - An optional object of default environment variables to include if not present in the content.
|
|
72
|
+
* @returns An object containing the extracted environment variables merged with defaults.
|
|
61
73
|
*/
|
|
62
74
|
static extractEnv(content, defaultEnv = {}) {
|
|
63
75
|
const lines = content.split('\n');
|
|
@@ -87,32 +99,32 @@ export class Env {
|
|
|
87
99
|
return defaultVal;
|
|
88
100
|
}
|
|
89
101
|
/**
|
|
90
|
-
* Set an environment variable
|
|
91
|
-
* @param key - The environment variable
|
|
92
|
-
* @param value - The value to set
|
|
102
|
+
* Set an environment variable.
|
|
103
|
+
* @param key - The key of the environment variable to set.
|
|
104
|
+
* @param value - The value to set for the environment variable.
|
|
93
105
|
*/
|
|
94
106
|
static set(key, value) {
|
|
95
107
|
process.env[key] = value;
|
|
96
108
|
}
|
|
97
109
|
/**
|
|
98
|
-
*
|
|
99
|
-
* @param env - An object containing key-value pairs of environment variables
|
|
110
|
+
* Sets multiple environment variables from an object.
|
|
111
|
+
* @param env - An object containing key-value pairs of environment variables to set.
|
|
100
112
|
*/
|
|
101
113
|
static setMany(env) {
|
|
102
114
|
for (const key in env)
|
|
103
115
|
process.env[key] = env[key] ?? '';
|
|
104
116
|
}
|
|
105
117
|
/**
|
|
106
|
-
* Delete an environment variable
|
|
107
|
-
* @param key - The environment variable
|
|
118
|
+
* Delete an environment variable.
|
|
119
|
+
* @param key - The key of the environment variable to delete.
|
|
108
120
|
*/
|
|
109
121
|
static delete(key) {
|
|
110
122
|
delete process.env[key];
|
|
111
123
|
}
|
|
112
124
|
/**
|
|
113
|
-
* Convert an EnvList to a .env-formatted string
|
|
114
|
-
* @param env - The environment variables object
|
|
115
|
-
* @returns A string in .env format
|
|
125
|
+
* Convert an EnvList to a .env-formatted string.
|
|
126
|
+
* @param env - The environment variables object.
|
|
127
|
+
* @returns A string in .env format.
|
|
116
128
|
*/
|
|
117
129
|
static toEnv(env) {
|
|
118
130
|
const filtered = Object.entries(env).filter(([key, value]) => typeof key === 'string' && typeof value === 'string');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Env.js","sourceRoot":"","sources":["../../src/utilities/Env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,IAAI,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,KAAK,MAAM,oBAAoB,CAAC;AACvC,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,MAAM,OAAO,GAAG;IACZ;;;OAGG;IACI,MAAM,KAAK,IAAI,KAAkB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,UAA2B,EAAE;QAChE,KAAK,CAAC,GAAG,CAAC,0CAA0C,IAAI,GAAG,CAAC,CAAC;QAC7D,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;QAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC;QAEtC,IAAI,CAAC,MAAM,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC;gBACD,KAAK,CAAC,GAAG,CAAC,kCAAkC,IAAI,iCAAiC,CAAC,CAAC;gBACnF,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBACzD,MAAM,GAAG,GAAG,IAAI,CA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G,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxE,CAAC;CACJ;AAeD,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class Path {
|
|
2
|
+
static readonly moduleDir: string;
|
|
3
|
+
static readonly moduleMain: string;
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes a path by replacing all backslashes with the system-specific separator.
|
|
6
|
+
* @param path - The path to clean.
|
|
7
|
+
* @returns The normalized path.
|
|
8
|
+
*/
|
|
9
|
+
static normalize(path: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a relative path to an absolute one, relative to the module root directory.
|
|
12
|
+
* @param path - The relative path.
|
|
13
|
+
* @returns The absolute path.
|
|
14
|
+
*/
|
|
15
|
+
static relative(path: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the directory name of a path.
|
|
18
|
+
* @param path - The path to get the directory name from.
|
|
19
|
+
* @returns The directory name.
|
|
20
|
+
*/
|
|
21
|
+
static dirname(path: string): string;
|
|
22
|
+
}
|
|
23
|
+
export declare namespace Path { }
|
|
24
|
+
export default Path;
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
* Normalizes a path by replacing all backslashes with the system-specific separator.
|
|
8
|
+
* @param path - The path to clean.
|
|
9
|
+
* @returns The normalized path.
|
|
10
|
+
*/
|
|
11
|
+
static normalize(path) {
|
|
12
|
+
path = path.replace(/[\\/]/gi, PATH.sep);
|
|
13
|
+
return path;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Converts a relative path to an absolute one, relative to the module root directory.
|
|
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
|
+
* Gets the directory name of a path.
|
|
27
|
+
* @param path - The path to get the directory name from.
|
|
28
|
+
* @returns The directory name.
|
|
29
|
+
*/
|
|
30
|
+
static dirname(path) {
|
|
31
|
+
path = this.normalize(path);
|
|
32
|
+
return PATH.dirname(path);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export default Path;
|
|
36
|
+
//# sourceMappingURL=Path.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Path.js","sourceRoot":"","sources":["../../src/
|
|
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;IACD;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAC,IAAY;QAC9B,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;;AAGL,eAAe,IAAI,CAAC"}
|
|
@@ -5,72 +5,86 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import _Path from './Path.js';
|
|
7
7
|
import _Env from './Env.js';
|
|
8
|
+
import _ConsoleUI from './ConsoleUI.js';
|
|
9
|
+
import _DebugUI from './DebugUI.js';
|
|
10
|
+
export { Path } from './Path.js';
|
|
11
|
+
export { Env } from './Env.js';
|
|
12
|
+
export { ConsoleUI } from './ConsoleUI.js';
|
|
13
|
+
export { DebugUI } from './DebugUI.js';
|
|
8
14
|
export declare class Utilities {
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
12
|
-
* @
|
|
13
|
-
|
|
16
|
+
* Checks if a file exists asynchronously.
|
|
17
|
+
* @param path - The path to the file.
|
|
18
|
+
* @returns A promise that resolves to `true` if the file exists, `false` otherwise.
|
|
19
|
+
*/
|
|
20
|
+
static fileExists(path: string): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Compares two objects recursively for deep equality.
|
|
23
|
+
* @param obj1 - The first object to compare.
|
|
24
|
+
* @param obj2 - The second object to compare.
|
|
25
|
+
* @returns A boolean indicating whether the objects are deeply equal or not.
|
|
14
26
|
*/
|
|
15
27
|
static deepEqual(obj1: any, obj2: any): boolean;
|
|
16
28
|
/**
|
|
17
|
-
* Flattens
|
|
18
|
-
* @param object - The object to flatten
|
|
19
|
-
* @param depth -
|
|
20
|
-
* @returns The flattened object
|
|
29
|
+
* Flattens a nested object into a single-level object with dot notation keys.
|
|
30
|
+
* @param object - The object to flatten.
|
|
31
|
+
* @param depth - The maximum depth to which the object should be flattened.
|
|
32
|
+
* @returns The flattened object.
|
|
21
33
|
*/
|
|
22
34
|
static flattenObject<T extends object, D extends number = 10>(object: T, depth?: D): Utilities.Flatten.Object<T, D>;
|
|
23
|
-
|
|
35
|
+
private static flattenCore;
|
|
24
36
|
/**
|
|
25
|
-
* Reconstructs a nested object from a flattened
|
|
26
|
-
* @template Result - The type of the unflattened object
|
|
27
|
-
* @param obj - The object to
|
|
28
|
-
* @returns The unflattened object
|
|
37
|
+
* Reconstructs a nested object from a flattened object with dot notation keys.
|
|
38
|
+
* @template Result - The type of the unflattened object.
|
|
39
|
+
* @param obj - The flattened object to un flatten.
|
|
40
|
+
* @returns The unflattened object.
|
|
29
41
|
*/
|
|
30
42
|
static unFlattenObject<Result extends any = any>(obj: any): Result;
|
|
31
43
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @param ms - The number of milliseconds to
|
|
34
|
-
* @returns A promise that resolves after the given time
|
|
44
|
+
* Pauses the execution of the program for a specified duration.
|
|
45
|
+
* @param ms - The number of milliseconds to sleep.
|
|
46
|
+
* @returns A promise that resolves after the given time.
|
|
35
47
|
*/
|
|
36
48
|
static sleep(ms: number): Promise<void>;
|
|
37
49
|
/**
|
|
38
50
|
* Encodes a string to base64url format.
|
|
39
|
-
* @param data - The string to
|
|
40
|
-
* @returns The base64url-encoded string
|
|
51
|
+
* @param data - The string that needs to be encoded.
|
|
52
|
+
* @returns The base64url-encoded string.
|
|
41
53
|
*/
|
|
42
54
|
static base64UrlEncode(data: string): string;
|
|
43
55
|
/**
|
|
44
56
|
* Decodes a base64url-encoded string.
|
|
45
|
-
* @param data - The base64url-encoded string to
|
|
46
|
-
* @returns The decoded string
|
|
57
|
+
* @param data - The base64url-encoded string that needs to be decoded.
|
|
58
|
+
* @returns The decoded string.
|
|
47
59
|
*/
|
|
48
60
|
static base64UrlDecode(data: string): string;
|
|
49
61
|
}
|
|
50
62
|
export declare namespace Utilities {
|
|
51
63
|
export import Path = _Path;
|
|
52
64
|
export import Env = _Env;
|
|
65
|
+
export import ConsoleUI = _ConsoleUI;
|
|
66
|
+
export import DebugUI = _DebugUI;
|
|
53
67
|
namespace Types {
|
|
54
68
|
type NumListAdd = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
|
|
55
69
|
type strToNum<str extends string> = str extends `${infer num extends number}` ? num : never;
|
|
56
70
|
/**
|
|
57
|
-
*
|
|
58
|
-
* @template Number the number to add one to
|
|
59
|
-
* @returns
|
|
71
|
+
* Adds one to a number type.
|
|
72
|
+
* @template Number the number to add one to.
|
|
73
|
+
* @returns The number incremented by one.
|
|
60
74
|
*/
|
|
61
75
|
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
76
|
/**
|
|
63
|
-
* union
|
|
64
|
-
* @template U the union to convert
|
|
65
|
-
* @returns
|
|
77
|
+
* Converts a union of object types into an intersection type.
|
|
78
|
+
* @template U the union to convert.
|
|
79
|
+
* @returns The intersection type of the given union.
|
|
66
80
|
*/
|
|
67
81
|
export type UnionToIntersection<U extends object> = ((U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I extends object ? {
|
|
68
82
|
[K in keyof I]: I[K] extends object ? UnionToIntersection<I[K]> : I[K];
|
|
69
83
|
} : I : never);
|
|
70
84
|
/**
|
|
71
|
-
*
|
|
72
|
-
* @template T the object to convert
|
|
73
|
-
* @returns
|
|
85
|
+
* Converts properties with `undefined` in an object type to optional properties.
|
|
86
|
+
* @template T the object to convert.
|
|
87
|
+
* @returns The object type with properties containing `undefined` marked as optional.
|
|
74
88
|
*/
|
|
75
89
|
export type undefinedToPartial<T extends object> = {
|
|
76
90
|
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
@@ -84,29 +98,28 @@ export declare namespace Utilities {
|
|
|
84
98
|
}
|
|
85
99
|
namespace Flatten {
|
|
86
100
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @template T the object to flatten
|
|
89
|
-
* @template depth
|
|
90
|
-
* @template index
|
|
91
|
-
* @returns
|
|
101
|
+
* Generates a union of all possible flattened keys for a given object type and depth.
|
|
102
|
+
* @template T the object to flatten.
|
|
103
|
+
* @template depth - The maximum depth to flatten.
|
|
104
|
+
* @template index - The current recursion index (internal use).
|
|
105
|
+
* @returns A union type of the flattened keys.
|
|
92
106
|
*/
|
|
93
107
|
type ResourceKeys<T extends Types.Document, depth extends number = 5, index extends number = 1> = {
|
|
94
108
|
[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
109
|
}[keyof T];
|
|
96
110
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @template T the object to flatten
|
|
99
|
-
* @template
|
|
100
|
-
* @
|
|
101
|
-
* @returns the flattened object keys as a union
|
|
111
|
+
* Recursively retrieves the type of a value based on a flattened key path.
|
|
112
|
+
* @template T the object to flatten.
|
|
113
|
+
* @template Keys - The flattened key path string.
|
|
114
|
+
* @returns The type of the value at the specified key path, or `never` if the path is invalid.
|
|
102
115
|
*/
|
|
103
116
|
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
117
|
/**
|
|
105
|
-
*
|
|
106
|
-
* @template T the object to flatten
|
|
107
|
-
* @template depth
|
|
108
|
-
* @template index the current index
|
|
109
|
-
* @returns the flattened object
|
|
118
|
+
* Represents the type of a flattened object up to a specified depth.
|
|
119
|
+
* @template T the object to flatten.
|
|
120
|
+
* @template depth - The maximum depth of flattening.
|
|
121
|
+
* @template index the current index.
|
|
122
|
+
* @returns the flattened object.
|
|
110
123
|
*/
|
|
111
124
|
export type Object<T extends Types.Document, depth extends number = 5, index extends number = 1> = Types.undefinedToPartial<{
|
|
112
125
|
[P in ResourceKeys<T, depth, index>]: RecurseObject<T, P>;
|
|
@@ -115,25 +128,25 @@ export declare namespace Utilities {
|
|
|
115
128
|
}
|
|
116
129
|
namespace UnFlatten {
|
|
117
130
|
/**
|
|
118
|
-
*
|
|
119
|
-
* @template S
|
|
120
|
-
* @template Delimiter
|
|
121
|
-
* @returns the split string
|
|
131
|
+
* Splits a string into a tuple of strings based on a delimiter.
|
|
132
|
+
* @template S - The string to split.
|
|
133
|
+
* @template Delimiter - The delimiter to split by.
|
|
134
|
+
* @returns the split string.
|
|
122
135
|
*/
|
|
123
136
|
type Split<S extends string, Delimiter extends string> = (S extends `${infer T}${Delimiter}${infer U}` ? [T, ...Split<U, Delimiter>] : [S]);
|
|
124
137
|
/**
|
|
125
|
-
*
|
|
126
|
-
* @template Path
|
|
127
|
-
* @template Value the value
|
|
128
|
-
* @returns the nested object
|
|
138
|
+
* Builds a nested object type from a string path and a value type.
|
|
139
|
+
* @template Path - The path of keys as a string array.
|
|
140
|
+
* @template Value - The type of the value at the end of the path.
|
|
141
|
+
* @returns the nested object.
|
|
129
142
|
*/
|
|
130
143
|
type BuildNestedObject<Path extends string[], Value> = (Path extends [infer Head extends string, ...infer Tail extends string[]] ? Types.undefinedToPartial<{
|
|
131
144
|
[K in Head]: BuildNestedObject<Tail, Value>;
|
|
132
145
|
}> : Value);
|
|
133
146
|
/**
|
|
134
|
-
*
|
|
135
|
-
* @template T the object
|
|
136
|
-
* @returns the unFlattened object
|
|
147
|
+
* Represents the type of a nested object reconstructed from a flattened object.
|
|
148
|
+
* @template T - The type of the flattened object.
|
|
149
|
+
* @returns the unFlattened object.
|
|
137
150
|
*/
|
|
138
151
|
export type Object<T extends Types.Document> = Types.UnionToIntersection<Types.undefinedToPartial<({
|
|
139
152
|
[K in keyof T]-?: BuildNestedObject<Split<Extract<K, string>, ".">, T[K]>;
|
|
@@ -3,14 +3,29 @@
|
|
|
3
3
|
* @description add useful functions to the Vortez.
|
|
4
4
|
* @license Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { promises as FSP } from "fs";
|
|
6
7
|
import _Path from './Path.js';
|
|
7
8
|
import _Env from './Env.js';
|
|
9
|
+
import _ConsoleUI from './ConsoleUI.js';
|
|
10
|
+
import _DebugUI from './DebugUI.js';
|
|
11
|
+
export { Path } from './Path.js';
|
|
12
|
+
export { Env } from './Env.js';
|
|
13
|
+
export { ConsoleUI } from './ConsoleUI.js';
|
|
14
|
+
export { DebugUI } from './DebugUI.js';
|
|
8
15
|
export class Utilities {
|
|
9
16
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
12
|
-
* @
|
|
13
|
-
|
|
17
|
+
* Checks if a file exists asynchronously.
|
|
18
|
+
* @param path - The path to the file.
|
|
19
|
+
* @returns A promise that resolves to `true` if the file exists, `false` otherwise.
|
|
20
|
+
*/
|
|
21
|
+
static async fileExists(path) {
|
|
22
|
+
return FSP.access(path).then(() => true).catch(() => false);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Compares two objects recursively for deep equality.
|
|
26
|
+
* @param obj1 - The first object to compare.
|
|
27
|
+
* @param obj2 - The second object to compare.
|
|
28
|
+
* @returns A boolean indicating whether the objects are deeply equal or not.
|
|
14
29
|
*/
|
|
15
30
|
static deepEqual(obj1, obj2) {
|
|
16
31
|
if (obj1 === obj2)
|
|
@@ -29,10 +44,10 @@ export class Utilities {
|
|
|
29
44
|
return true;
|
|
30
45
|
}
|
|
31
46
|
/**
|
|
32
|
-
* Flattens
|
|
33
|
-
* @param object - The object to flatten
|
|
34
|
-
* @param depth -
|
|
35
|
-
* @returns The flattened object
|
|
47
|
+
* Flattens a nested object into a single-level object with dot notation keys.
|
|
48
|
+
* @param object - The object to flatten.
|
|
49
|
+
* @param depth - The maximum depth to which the object should be flattened.
|
|
50
|
+
* @returns The flattened object.
|
|
36
51
|
*/
|
|
37
52
|
static flattenObject(object, depth = 10) {
|
|
38
53
|
return this.flattenCore(object, depth);
|
|
@@ -52,10 +67,10 @@ export class Utilities {
|
|
|
52
67
|
return result;
|
|
53
68
|
}
|
|
54
69
|
/**
|
|
55
|
-
* Reconstructs a nested object from a flattened
|
|
56
|
-
* @template Result - The type of the unflattened object
|
|
57
|
-
* @param obj - The object to
|
|
58
|
-
* @returns The unflattened object
|
|
70
|
+
* Reconstructs a nested object from a flattened object with dot notation keys.
|
|
71
|
+
* @template Result - The type of the unflattened object.
|
|
72
|
+
* @param obj - The flattened object to un flatten.
|
|
73
|
+
* @returns The unflattened object.
|
|
59
74
|
*/
|
|
60
75
|
static unFlattenObject(obj) {
|
|
61
76
|
const result = {};
|
|
@@ -78,25 +93,25 @@ export class Utilities {
|
|
|
78
93
|
return result;
|
|
79
94
|
}
|
|
80
95
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @param ms - The number of milliseconds to
|
|
83
|
-
* @returns A promise that resolves after the given time
|
|
96
|
+
* Pauses the execution of the program for a specified duration.
|
|
97
|
+
* @param ms - The number of milliseconds to sleep.
|
|
98
|
+
* @returns A promise that resolves after the given time.
|
|
84
99
|
*/
|
|
85
100
|
static sleep(ms) {
|
|
86
101
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
87
102
|
}
|
|
88
103
|
/**
|
|
89
104
|
* Encodes a string to base64url format.
|
|
90
|
-
* @param data - The string to
|
|
91
|
-
* @returns The base64url-encoded string
|
|
105
|
+
* @param data - The string that needs to be encoded.
|
|
106
|
+
* @returns The base64url-encoded string.
|
|
92
107
|
*/
|
|
93
108
|
static base64UrlEncode(data) {
|
|
94
109
|
return Buffer.from(data).toString('base64url');
|
|
95
110
|
}
|
|
96
111
|
/**
|
|
97
112
|
* Decodes a base64url-encoded string.
|
|
98
|
-
* @param data - The base64url-encoded string to
|
|
99
|
-
* @returns The decoded string
|
|
113
|
+
* @param data - The base64url-encoded string that needs to be decoded.
|
|
114
|
+
* @returns The decoded string.
|
|
100
115
|
*/
|
|
101
116
|
static base64UrlDecode(data) {
|
|
102
117
|
return Buffer.from(data, 'base64url').toString('utf8');
|
|
@@ -105,6 +120,8 @@ export class Utilities {
|
|
|
105
120
|
(function (Utilities) {
|
|
106
121
|
Utilities.Path = _Path;
|
|
107
122
|
Utilities.Env = _Env;
|
|
123
|
+
Utilities.ConsoleUI = _ConsoleUI;
|
|
124
|
+
Utilities.DebugUI = _DebugUI;
|
|
108
125
|
})(Utilities || (Utilities = {}));
|
|
109
126
|
export default Utilities;
|
|
110
127
|
//# sourceMappingURL=Utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Utilities.js","sourceRoot":"","sources":["../../src/utilities/Utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,IAAI,CAAC;AAErC,OAAO,KAAK,MAAM,WAAW,CAAC;AAC9B,OAAO,IAAI,MAAM,UAAU,CAAC;AAC5B,OAAO,UAAU,MAAM,gBAAgB,CAAC;AACxC,OAAO,QAAQ,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,OAAO,SAAS;IAClB;;;;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