vortez 5.0.0-dev.19 → 5.0.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 (106) hide show
  1. package/.gitignore +2 -0
  2. package/README.md +33 -9
  3. package/build/Template/Compiler.d.ts +70 -0
  4. package/build/Template/Compiler.js +135 -0
  5. package/build/Template/Compiler.js.map +1 -0
  6. package/build/Template/StreamCompiler.d.ts +16 -0
  7. package/build/Template/StreamCompiler.js +54 -0
  8. package/build/Template/StreamCompiler.js.map +1 -0
  9. package/build/Template/Template.d.ts +49 -0
  10. package/build/Template/Template.js +77 -0
  11. package/build/Template/Template.js.map +1 -0
  12. package/build/Vortez.d.ts +1 -1
  13. package/build/Vortez.js +1 -1
  14. package/build/Vortez.js.map +1 -1
  15. package/build/beta/JwtManager/JwtError.d.ts +8 -0
  16. package/build/beta/JwtManager/JwtError.js +10 -0
  17. package/build/beta/JwtManager/JwtError.js.map +1 -0
  18. package/build/beta/JwtManager/JwtManager.d.ts +4 -0
  19. package/build/beta/JwtManager/JwtManager.js +27 -7
  20. package/build/beta/JwtManager/JwtManager.js.map +1 -1
  21. package/build/server/BodyParser.d.ts +6 -0
  22. package/build/server/BodyParser.js +18 -3
  23. package/build/server/BodyParser.js.map +1 -1
  24. package/build/server/Request.d.ts +6 -4
  25. package/build/server/Request.js +15 -10
  26. package/build/server/Request.js.map +1 -1
  27. package/build/server/Response.d.ts +56 -10
  28. package/build/server/Response.js +204 -92
  29. package/build/server/Response.js.map +1 -1
  30. package/build/server/Server.js +29 -6
  31. package/build/server/Server.js.map +1 -1
  32. package/build/server/config/Config.d.ts +15 -13
  33. package/build/server/config/Config.js +8 -6
  34. package/build/server/config/Config.js.map +1 -1
  35. package/build/server/config/Loader.js +1 -1
  36. package/build/server/config/Loader.js.map +1 -1
  37. package/build/server/router/Router.d.ts +1 -1
  38. package/build/server/router/Router.js +4 -4
  39. package/build/server/router/Router.js.map +1 -1
  40. package/build/server/router/middleware/HttpMiddleware.js +5 -5
  41. package/build/server/router/middleware/HttpMiddleware.js.map +1 -1
  42. package/build/server/router/middleware/WsMiddleware.js +1 -1
  43. package/build/server/router/middleware/WsMiddleware.js.map +1 -1
  44. package/build/server/security/PathSecurity.d.ts +45 -0
  45. package/build/server/security/PathSecurity.js +108 -0
  46. package/build/server/security/PathSecurity.js.map +1 -0
  47. package/build/server/websocket/Websocket.js +4 -1
  48. package/build/server/websocket/Websocket.js.map +1 -1
  49. package/build/utilities/ConsoleUI.d.ts +2 -1
  50. package/build/utilities/ConsoleUI.js +2 -1
  51. package/build/utilities/ConsoleUI.js.map +1 -1
  52. package/build/utilities/DebugUI.d.ts +1 -1
  53. package/build/utilities/DebugUI.js +1 -1
  54. package/build/utilities/Encoding.d.ts +22 -0
  55. package/build/utilities/Encoding.js +26 -0
  56. package/build/utilities/Encoding.js.map +1 -0
  57. package/build/utilities/Env.js +7 -2
  58. package/build/utilities/Env.js.map +1 -1
  59. package/build/utilities/File.d.ts +10 -0
  60. package/build/utilities/File.js +19 -0
  61. package/build/utilities/File.js.map +1 -0
  62. package/build/utilities/Flatten.d.ts +18 -1
  63. package/build/utilities/Flatten.js +18 -1
  64. package/build/utilities/Flatten.js.map +1 -1
  65. package/build/utilities/Object.d.ts +16 -0
  66. package/build/utilities/Object.js +48 -0
  67. package/build/utilities/Object.js.map +1 -0
  68. package/build/utilities/Path.d.ts +31 -11
  69. package/build/utilities/Path.js +48 -15
  70. package/build/utilities/Path.js.map +1 -1
  71. package/build/utilities/Time.d.ts +21 -0
  72. package/build/utilities/Time.js +25 -0
  73. package/build/utilities/Time.js.map +1 -0
  74. package/build/utilities/Utilities.d.ts +43 -34
  75. package/build/utilities/Utilities.js +48 -38
  76. package/build/utilities/Utilities.js.map +1 -1
  77. package/changes.md +5 -0
  78. package/docs/ARCHITECTURE.md +142 -0
  79. package/global/style/template/error.css +29 -0
  80. package/global/style/template/folder.css +79 -0
  81. package/global/{Style/Template/Template.css → style/template/template.css} +60 -68
  82. package/global/template/error.vhtml +29 -0
  83. package/global/template/folder.vhtml +54 -0
  84. package/package.json +2 -2
  85. package/build/Template.d.ts +0 -46
  86. package/build/Template.js +0 -81
  87. package/build/Template.js.map +0 -1
  88. package/global/Style/Template/Error.css +0 -30
  89. package/global/Style/Template/Folder.css +0 -77
  90. package/global/Template/Error.vhtml +0 -29
  91. package/global/Template/Folder.vhtml +0 -41
  92. package/tests/Template/template.js +0 -18
  93. package/tests/Template/template.txt +0 -13
  94. package/tests/Template/template.vhtml +0 -23
  95. package/tests/config/config.js +0 -233
  96. package/tests/debug.js +0 -34
  97. package/tests/jwtManager/jwtManager.js +0 -342
  98. package/tests/router.js +0 -596
  99. package/tests/schema/schema.js +0 -368
  100. package/tests/test.env +0 -0
  101. package/tests/test.js +0 -131
  102. package/tests/test.vhtml +0 -14
  103. package/tests/utilities.js +0 -28
  104. package/tests/websocket.vhtml +0 -86
  105. /package/global/{Source/Logo_960.png → source/logo_960.png} +0 -0
  106. /package/global/{Source/Logo_SM_960.png → source/logo_SM_960.png} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vortez",
3
- "version": "5.0.0-dev.19",
3
+ "version": "5.0.1",
4
4
  "description": "a module for web server creation",
5
5
  "type": "module",
6
6
  "main": "build/Vortez.js",
@@ -25,7 +25,7 @@
25
25
  "build/",
26
26
  "examples/",
27
27
  "global/",
28
- "tests/",
28
+ "docs/",
29
29
  ".gitignore",
30
30
  "changes.md",
31
31
  "LICENSE",
@@ -1,46 +0,0 @@
1
- /**
2
- * @author NetFeez <netfeez.dev@gmail.com>
3
- * @description Add the HNetFeez-Labs template engine to the Vortez.
4
- * @license Apache-2.0
5
- */
6
- export declare class Template {
7
- /** Regular expressions used for parsing and processing the template. */
8
- private static expressions;
9
- /**
10
- * Load and compile a template.
11
- * This method reads a template file from the specified path,
12
- * checks if it's a valid file, and then compiles its content
13
- * using the provided data object.
14
- *
15
- * @example `Template.load('./templates/myTemplate.html', { username: 'John Doe' });`
16
- * @param path - The path to the template file.
17
- * @param data - The data used to compile the template.
18
- * @returns The compiled template.
19
- * @throws Error if the path is not a file.
20
- * @throws Error if the file does not exist.
21
- */
22
- static load(path: string, data: Template.dataObject): Promise<string>;
23
- /**
24
- * Compile a template.
25
- * This internal method takes the raw template content and the data object
26
- * and performs the actual compilation, replacing variables and processing
27
- * object/array blocks according to the defined syntax.
28
- *
29
- * @example `Template.compile('Hello, ${name}!', { name: 'Alice' });`
30
- * @param content - The content of the template.
31
- * @param data - The data used to compile the template.
32
- * @returns The compiled template.
33
- * @throws Error if key and value names are equal in object blocks.
34
- */
35
- private static compile;
36
- }
37
- export declare namespace Template {
38
- /**
39
- * Represents the structure of the data object used for template compilation.
40
- * It is a key-value store where keys are strings and values can be of any type.
41
- */
42
- interface dataObject {
43
- [key: string]: any;
44
- }
45
- }
46
- export default Template;
package/build/Template.js DELETED
@@ -1,81 +0,0 @@
1
- /**
2
- * @author NetFeez <netfeez.dev@gmail.com>
3
- * @description Add the HNetFeez-Labs template engine to the Vortez.
4
- * @license Apache-2.0
5
- */
6
- import FS from 'fs';
7
- import Utilities from './utilities/Utilities.js';
8
- export class Template {
9
- /** Regular expressions used for parsing and processing the template. */
10
- static expressions = {
11
- /** Regular expression for matching variables (e.g., `${variableName}`). */
12
- variable: /\$\{(.+?)\}/ig,
13
- object: {
14
- /** Regular expression for matching object/array blocks (e.g., `$(objectName) { ... }`). */
15
- block: /\$ ?\((.+)\) ?\{([^]+?)\}/g,
16
- /** Regular expression for matching placeholders within object/array blocks (e.g., `%key%`, `%value%`). */
17
- replaces: /\%(.+?)%/g
18
- }
19
- };
20
- /**
21
- * Load and compile a template.
22
- * This method reads a template file from the specified path,
23
- * checks if it's a valid file, and then compiles its content
24
- * using the provided data object.
25
- *
26
- * @example `Template.load('./templates/myTemplate.html', { username: 'John Doe' });`
27
- * @param path - The path to the template file.
28
- * @param data - The data used to compile the template.
29
- * @returns The compiled template.
30
- * @throws Error if the path is not a file.
31
- * @throws Error if the file does not exist.
32
- */
33
- static async load(path, data) {
34
- path = Utilities.Path.normalize(path);
35
- const details = await FS.promises.stat(path);
36
- if (!details.isFile())
37
- throw new Error('the path is not a template file');
38
- const template = await FS.promises.readFile(path);
39
- return this.compile(template.toString('utf-8'), data);
40
- }
41
- /**
42
- * Compile a template.
43
- * This internal method takes the raw template content and the data object
44
- * and performs the actual compilation, replacing variables and processing
45
- * object/array blocks according to the defined syntax.
46
- *
47
- * @example `Template.compile('Hello, ${name}!', { name: 'Alice' });`
48
- * @param content - The content of the template.
49
- * @param data - The data used to compile the template.
50
- * @returns The compiled template.
51
- * @throws Error if key and value names are equal in object blocks.
52
- */
53
- static compile(content, data) {
54
- content = content.replace(this.expressions.variable, (text, name) => {
55
- return name && name in data ? data[name] : text;
56
- });
57
- content = content.replace(this.expressions.object.block, (block, sentence, loop) => {
58
- const [name, keyName = 'key', valueName = 'value'] = sentence.split(/, ?/gi);
59
- if (keyName === valueName)
60
- throw new Error('the key and value names must be different in block: ' + block);
61
- return name && name in data && data[name] instanceof Object ? Object.keys(data[name]).map((key) => {
62
- return loop.replace(this.expressions.object.replaces, (SubText, varName) => {
63
- if (keyName == varName)
64
- return key;
65
- else if (valueName == varName)
66
- return data[name][key];
67
- });
68
- }).join('') : block;
69
- });
70
- return content;
71
- }
72
- }
73
- export default Template;
74
- /*
75
- Variables: ${name}
76
- Objects/Arrays: $(name) { the key is %key% and value %value% }
77
- Objects/Arrays: $(name, customKeyName, customValueName) {
78
- the key is %customKeyName% and value %customValueName%
79
- }
80
- */
81
- //# sourceMappingURL=Template.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Template.js","sourceRoot":"","sources":["../src/Template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,SAAS,MAAM,0BAA0B,CAAC;AAEjD,MAAM,OAAO,QAAQ;IACpB,wEAAwE;IAChE,MAAM,CAAC,WAAW,GAAG;QAC5B,2EAA2E;QAC3E,QAAQ,EAAE,eAAe;QACzB,MAAM,EAAE;YACP,2FAA2F;YAC3F,KAAK,EAAE,4BAA4B;YACnC,0GAA0G;YAC1G,QAAQ,EAAE,WAAW;SACrB;KACD,CAAC;IACF;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,IAAyB;QAC/D,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAC1E,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;;;;OAWG;IACK,MAAM,CAAC,OAAO,CAAC,OAAe,EAAE,IAAyB;QAChE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;YACnE,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAa,EAAE,QAAgB,EAAE,IAAY,EAAE,EAAE;YAC1G,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7E,IAAI,OAAO,KAAK,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,sDAAsD,GAAG,KAAK,CAAC,CAAC;YAC3G,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;gBACjG,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;oBAC1E,IAAI,OAAO,IAAI,OAAO;wBAAE,OAAO,GAAG,CAAA;yBAC7B,IAAI,SAAS,IAAI,OAAO;wBAAE,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;gBACvD,CAAC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACrB,CAAC,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IAChB,CAAC;;AAaF,eAAe,QAAQ,CAAC;AACxB;;;;;;EAME"}
@@ -1,30 +0,0 @@
1
- #Error {
2
- --Color_Fondo: rgb(255,180,220);
3
- --Color_Código: rgb(255,0,0);
4
- --Color_Mensaje: rgb(0,0,0);
5
- --Color_Fondo_Imagen: rgba(255,0,0,0.1);
6
- }
7
- #Error {
8
- background: var(--Color_Fondo);
9
- height: 100%;
10
- position: fixed;
11
- width: 100%;
12
- overflow: visible;
13
- }
14
- #Error .Información {
15
- text-align: center;
16
- width: 90%;
17
- overflow: visible;
18
- }
19
- #Error .Código {
20
- color: var(--Color_Código);
21
- font-size: 3em;
22
- }
23
- #Error .Mensaje {
24
- color: var(--Color_Mensaje);
25
- font-size: 1em;
26
- margin-bottom: 1em;
27
- }
28
- #Error .Carga {
29
- width: 30%;
30
- }
@@ -1,77 +0,0 @@
1
- #Carpeta {
2
- --Color_Fondo: rgb(255,180,220);
3
- --Color_Fondo_Contenido: rgba(255,0,0,0.1);
4
- --Color_Fondo_Atrás: rgba(180,220,255,0.5);
5
- --Color_Fondo_Atrás_Acción: rgba(180,220,255,0.75);
6
- --Color_Fondo_Búsqueda: rgba(255,180,220,0.5);
7
- --Color_Fondo_Búsqueda_Acción: rgba(255,180,220,0.75);
8
- --Color_Fondo_Elemento: rgba(220,255,180,0.25);
9
- --Color_Fondo_Elemento_Acción: rgba(220,255,180,0.5);
10
- --Color_Borde_Búsqueda_Acción: rgb(180,220,255);
11
- }
12
- #Carpeta {
13
- align-items: center;
14
- background: var(--Color_Fondo);
15
- height: 100%;
16
- overflow: visible scroll;
17
- position: fixed;
18
- width: 100%;
19
- }
20
- #Carpeta .Contenido {
21
- background: var(--Color_Fondo_Contenido);
22
- border-radius: 2em;
23
- margin-top: 2em;
24
- padding: 2em;
25
- text-align: center;
26
- width: 70%;
27
- }
28
- #Carpeta .Opciones {
29
- display: flex;
30
- text-align: start;
31
- }
32
- #Carpeta #Carpeta_Cambiar {
33
- cursor: pointer;
34
- }
35
- #Carpeta .Atrás,
36
- #Carpeta #Carpeta_Ruta,
37
- #Carpeta #Carpeta_Cambiar {
38
- background: var(--Color_Fondo_Atrás);
39
- border-radius: 1em;
40
- color: rgb(0,0,0);
41
- display: inline-block;
42
- margin: 0.5em;
43
- padding: 1em;
44
- text-decoration: none;
45
- }
46
- #Carpeta #Carpeta_Ruta,
47
- #Carpeta #Carpeta_Cambiar {
48
- background: var(--Color_Fondo_Búsqueda);
49
- border: none;
50
- }
51
- #Carpeta .Lista {
52
- list-style: none;
53
- }
54
- #Carpeta .Elemento {
55
- background: var(--Color_Fondo_Elemento);
56
- border-radius: 1em;
57
- color: rgb(0,0,0);
58
- display: block;
59
- margin: 0.25em;
60
- padding: 1em;
61
- text-decoration: none;
62
- }
63
- #Carpeta .Atrás:hover {
64
- background: var(--Color_Fondo_Atrás_Acción);
65
- }
66
- #Carpeta #Carpeta_Ruta:focus {
67
- border: var(--Color_Borde_Búsqueda_Acción) 3px double;
68
- margin: calc(0.5em - 3px);
69
- outline: none;
70
- }
71
- #Carpeta #Carpeta_Ruta:focus,
72
- #Carpeta #Carpeta_Cambiar:hover {
73
- background: var(--Color_Fondo_Búsqueda_Acción);
74
- }
75
- #Carpeta .Elemento:hover {
76
- background: var(--Color_Fondo_Elemento_Acción);
77
- }
@@ -1,29 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="es">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <link rel="stylesheet" href="/NetFeez-Labs:Global/Style/Template/Template.css">
8
- <title>[SV-C] - ${status}</title>
9
- </head>
10
- <body>
11
- <div id="Error" class="Centrar-X Centrar-Y">
12
- <div class="Información">
13
- <h1 class="Código">Error: ${status}</h1>
14
- <p class="Mensaje">${message}</p>
15
- <div class="Centrar-X Centrar-Y">
16
- <div class="Carga">
17
- <div class="C_Fondo"></div>
18
- <div class="C_Fondo2"></div>
19
- <picture>
20
- <source srcset="/NetFeez-Labs:Global/Source/Logo_SM_960.png"/>
21
- <source srcset="/favicon.ico"/>
22
- <img class="C_Logo">
23
- </picture>
24
- </div>
25
- </div>
26
- </div>
27
- </div>
28
- </body>
29
- </html>
@@ -1,41 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="es">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <link rel="stylesheet" href="/NetFeez-Labs:Global/Style/Template/Template.css">
8
- <title>[SA-ML] - Dir</title>
9
- </head>
10
- <body>
11
- <div id="Carpeta" class="Centrar-X">
12
- <div class="Contenido">
13
- <h1 class="Ruta">Carpeta: ${Url}</h1>
14
- <div class="Opciones">
15
- <a class="Atrás" href="${Url}../">Atrás</a>
16
- <input id="Carpeta_Ruta" type="search" placeholder="Cambiar de ruta... ${Url}" value="${Url}"/>
17
- <input id="Carpeta_Cambiar"type="button" value="Cambiar Ruta"/>
18
- </div>
19
- <ul class="Lista">
20
- $(folder,, name) {
21
- <li>
22
- <a class="Elemento" href="${Url}%name%">%name%</a>
23
- </li>
24
- }
25
- </ul>
26
- </div>
27
- <script>
28
- const Carpeta_Cambiar = document.querySelector('#Carpeta_Cambiar');
29
- const Carpeta_Ruta = document.querySelector('#Carpeta_Ruta');
30
- Carpeta_Cambiar.addEventListener('click', () => {
31
- window.location.href = Carpeta_Ruta.value;
32
- });
33
- Carpeta_Ruta.addEventListener('keydown', (Evento) => {
34
- Carpeta_Ruta.value.length <= '${Url}'.length && Evento.key == 'Backspace'
35
- ? Evento.preventDefault()
36
- : false;
37
- })
38
- </script>
39
- </div>
40
- </body>
41
- </html>
@@ -1,18 +0,0 @@
1
- import Template from "../../build/Template.js";
2
-
3
- console.log(await Template.load('tests/Template/template.txt', {
4
- tittle: "Hola mundo",
5
- users: {
6
- diego: true,
7
- juan: false,
8
- pedro: true,
9
- maria: false,
10
- jorge: true
11
- }
12
- }))
13
- console.log('----------------------------------------')
14
- console.log(await Template.load('tests/Template/template.vhtml', {
15
- Titulo: 'Titulo de la prueba',
16
- Des: 'Descripción xD',
17
- Tests: ["algo", "algo2"]
18
- }));
@@ -1,13 +0,0 @@
1
- <h1>${tittle}<h1>
2
- <table>
3
- <tr>
4
- <th>user</th>
5
- <th>isInvited</th>
6
- </tr>
7
- $(users, user, isInvited) {
8
- <tr>
9
- <td>%user%</td>
10
- <td>%isInvited%</td>
11
- </tr>
12
- }
13
- </table>
@@ -1,23 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>${Titulo}</title>
7
- </head>
8
- <body>
9
- ${Des}
10
- <table>
11
- <tr>
12
- <th>Test</th>
13
- <th>Enlace</th>
14
- </tr>
15
- $(Tests) {
16
- <tr>
17
- <td>%key%</td>
18
- <td><a href="%value%">%value%</a></td>
19
- </tr>
20
- }
21
- </table>
22
- </body>
23
- </html>
@@ -1,233 +0,0 @@
1
- // @ts-check
2
- import { strict as assert } from 'assert';
3
- import { promises as FSP } from 'fs';
4
-
5
- import { Logger } from '../../build/Vortez.js';
6
- import { Config } from '../../build/server/config/Config.js';
7
- import { Loader } from '../../build/server/config/Loader.js';
8
- import { SchemaError } from '../../build/utilities/schema/SchemaError.js';
9
-
10
- const logger = new Logger({ prefix: 'CONFIG' });
11
-
12
- let testsPassed = 0;
13
- let testsFailed = 0;
14
-
15
- const TMP_DIR = 'tests/.tmp/config-suite';
16
- const CONFIG_PATH = `${TMP_DIR}/config.json`;
17
- const BAD_CONFIG_PATH = `${TMP_DIR}/bad.json`;
18
-
19
- /**
20
- * Logs test results.
21
- * @param { string } testName The test name.
22
- * @param { boolean } passed Whether the test passed.
23
- * @param { unknown | null } error Optional error object for failures.
24
- */
25
- function logTestResult(testName, passed, error = null) {
26
- if (passed) {
27
- logger.log(`&C2✓ ${testName}`);
28
- testsPassed++;
29
- } else {
30
- const message = error instanceof Error ? error.message : String(error);
31
- logger.error(`&C1✗ ${testName}${error ? ': ' + message : ''}`);
32
- testsFailed++;
33
- }
34
- }
35
-
36
- async function resetTmpDir() {
37
- await FSP.rm(TMP_DIR, { recursive: true, force: true });
38
- await FSP.mkdir(TMP_DIR, { recursive: true });
39
- }
40
-
41
- /**
42
- * Ensures constructor applies default values for missing config keys.
43
- */
44
- function testDefaultConfigValues() {
45
- try {
46
- const config = new Config({});
47
-
48
- assert.equal(config.get('host'), 'localhost');
49
- assert.equal(config.get('port'), 80);
50
- assert.equal(config.get('ssl'), null);
51
- assert.equal(config.get('templates.folder'), './global/Template/Folder.vhtml');
52
- assert.equal(config.get('templates.error'), './global/Template/Error.vhtml');
53
- assert.equal(config.get('routing.algorithm'), 'FIFO');
54
- assert.equal(config.get('logger.showAll'), false);
55
- assert.equal(config.get('logger.server.show'), true);
56
- assert.equal(config.get('logger.server.save'), true);
57
-
58
- logTestResult('constructor - Applies defaults', true);
59
- } catch (error) {
60
- logTestResult('constructor - Applies defaults', false, error);
61
- }
62
- }
63
-
64
- /**
65
- * Ensures nested object defaults are filled when object is partially provided.
66
- */
67
- function testNestedSslDefaultPort() {
68
- try {
69
- const config = new Config({
70
- ssl: {
71
- cert: 'cert-path',
72
- key: 'key-path'
73
- }
74
- });
75
-
76
- assert.equal(config.get('ssl.cert'), 'cert-path');
77
- assert.equal(config.get('ssl.key'), 'key-path');
78
- assert.equal(config.get('ssl.port'), 443);
79
-
80
- logTestResult('constructor - Nested defaults inside ssl', true);
81
- } catch (error) {
82
- logTestResult('constructor - Nested defaults inside ssl', false, error);
83
- }
84
- }
85
-
86
- /**
87
- * Ensures enum constraints are validated.
88
- */
89
- function testRoutingEnumValidation() {
90
- try {
91
- assert.throws(
92
- // @ts-expect-error Runtime validation test with invalid enum on purpose.
93
- () => new Config({ routing: { algorithm: 'BreadthFirst' } }),
94
- SchemaError
95
- );
96
-
97
- logTestResult('validation - Reject invalid routing algorithm', true);
98
- } catch (error) {
99
- logTestResult('validation - Reject invalid routing algorithm', false, error);
100
- }
101
- }
102
-
103
- /**
104
- * Ensures get/set use flattened dot-path keys.
105
- */
106
- function testGetSetFlattenedPaths() {
107
- try {
108
- const config = new Config({});
109
-
110
- config.set('host', '127.0.0.1');
111
- config.set('routing.algorithm', 'Tree');
112
- config.set('logger.server.show', false);
113
-
114
- assert.equal(config.get('host'), '127.0.0.1');
115
- assert.equal(config.get('routing.algorithm'), 'Tree');
116
- assert.equal(config.get('logger.server.show'), false);
117
-
118
- logTestResult('api - Get/Set flattened paths', true);
119
- } catch (error) {
120
- logTestResult('api - Get/Set flattened paths', false, error);
121
- }
122
- }
123
-
124
- /**
125
- * Ensures save writes nested JSON and creates missing folders.
126
- */
127
- async function testSaveCreatesFileAndNestedData() {
128
- try {
129
- await resetTmpDir();
130
-
131
- const config = new Config({});
132
- config.set('host', '0.0.0.0');
133
- config.set('logger.request.save', false);
134
- await config.save(CONFIG_PATH);
135
-
136
- const content = await FSP.readFile(CONFIG_PATH, 'utf8');
137
- const data = JSON.parse(content);
138
-
139
- assert.equal(data.host, '0.0.0.0');
140
- assert.equal(data.logger.request.save, false);
141
-
142
- logTestResult('save - Writes file and nested json', true);
143
- } catch (error) {
144
- logTestResult('save - Writes file and nested json', false, error);
145
- }
146
- }
147
-
148
- /**
149
- * Ensures Loader creates a new file when it does not exist.
150
- */
151
- async function testLoaderCreatesMissingFile() {
152
- try {
153
- await resetTmpDir();
154
-
155
- const loaded = await Loader.load(CONFIG_PATH);
156
-
157
- assert.ok(loaded instanceof Config);
158
- assert.equal(loaded.get('host'), 'localhost');
159
-
160
- const content = await FSP.readFile(CONFIG_PATH, 'utf8');
161
- const data = JSON.parse(content);
162
- assert.equal(data.port, 80);
163
-
164
- logTestResult('loader - Creates missing file with defaults', true);
165
- } catch (error) {
166
- logTestResult('loader - Creates missing file with defaults', false, error);
167
- }
168
- }
169
-
170
- /**
171
- * Ensures Loader reads and validates existing config files.
172
- */
173
- async function testLoaderReadsExistingFile() {
174
- try {
175
- await resetTmpDir();
176
-
177
- await FSP.writeFile(
178
- CONFIG_PATH,
179
- JSON.stringify({ host: 'example.com', routing: { algorithm: 'Tree' } }, null, 4),
180
- 'utf8'
181
- );
182
-
183
- const loaded = await Loader.load(CONFIG_PATH);
184
-
185
- assert.equal(loaded.get('host'), 'example.com');
186
- assert.equal(loaded.get('routing.algorithm'), 'Tree');
187
-
188
- logTestResult('loader - Loads existing file', true);
189
- } catch (error) {
190
- logTestResult('loader - Loads existing file', false, error);
191
- }
192
- }
193
-
194
- /**
195
- * Ensures Loader throws when the file contains invalid JSON.
196
- */
197
- async function testLoaderRejectsInvalidJson() {
198
- try {
199
- await resetTmpDir();
200
- await FSP.writeFile(BAD_CONFIG_PATH, '{ "host": "localhost", ', 'utf8');
201
-
202
- await assert.rejects(() => Loader.load(BAD_CONFIG_PATH));
203
-
204
- logTestResult('loader - Rejects invalid json file', true);
205
- } catch (error) {
206
- logTestResult('loader - Rejects invalid json file', false, error);
207
- }
208
- }
209
-
210
- async function runTests() {
211
- logger.log('\n&C6=== Config Test Suite ===\n');
212
-
213
- testDefaultConfigValues();
214
- testNestedSslDefaultPort();
215
- testRoutingEnumValidation();
216
- testGetSetFlattenedPaths();
217
-
218
- await testSaveCreatesFileAndNestedData();
219
- await testLoaderCreatesMissingFile();
220
- await testLoaderReadsExistingFile();
221
- await testLoaderRejectsInvalidJson();
222
-
223
- await FSP.rm(TMP_DIR, { recursive: true, force: true });
224
-
225
- logger.log('\n&C6=== Results ===');
226
- logger.log(`&C2✓ Passed: ${testsPassed}`);
227
- logger.log(`&C1✗ Failed: ${testsFailed}`);
228
- logger.log(`&C3Total: ${testsPassed + testsFailed}\n`);
229
-
230
- process.exit(testsFailed > 0 ? 1 : 0);
231
- }
232
-
233
- runTests();
package/tests/debug.js DELETED
@@ -1,34 +0,0 @@
1
- /// @ts-check
2
-
3
- import { Logger } from "../build/Vortez.js";
4
-
5
- const Debug = Logger.Debug;
6
-
7
- Debug.log('Hello world');
8
- Debug.log([
9
- 'Prueba de envió de multiples datos',
10
- 'Para saber el comportamiento'
11
- ]);
12
-
13
- const X = Debug.getInstance('_Debug');
14
-
15
- X.log('Prueba para ver si creando una instancia con una ID existente se devuelve la instancia con dicha ID');
16
- X.log('Prueba para ver si no se crea un archivo diferente con ID igual');
17
-
18
- const Y = Debug.getInstance('SEA', {
19
- show: false
20
- });
21
-
22
- Y.log('Prueba para verificar que no se muestra en consola si se inicializa con EnConsola = false');
23
-
24
- Debug.showAll = true;
25
-
26
- Y.log('Prueba para verificar que al cambiar el atributo MostrarTodo a true se muestran incluso los Debug con EnConsola = false');
27
-
28
- Debug.showAll = false;
29
-
30
- Y.log('Prueba para ver si vuelven a ocultarse los mensajes en consola de los EnConsola = false después de poner MostrarTodo nuevamente en false');
31
-
32
- Debug.log('Fin de la prueba');
33
-
34
- export default true;