vortez 5.0.0-dev.19 → 5.0.0
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 +2 -0
- package/README.md +26 -9
- package/build/Template/Compiler.d.ts +70 -0
- package/build/Template/Compiler.js +135 -0
- package/build/Template/Compiler.js.map +1 -0
- package/build/Template/StreamCompiler.d.ts +16 -0
- package/build/Template/StreamCompiler.js +54 -0
- package/build/Template/StreamCompiler.js.map +1 -0
- package/build/Template/Template.d.ts +49 -0
- package/build/Template/Template.js +77 -0
- package/build/Template/Template.js.map +1 -0
- package/build/Vortez.d.ts +1 -1
- package/build/Vortez.js +1 -1
- package/build/Vortez.js.map +1 -1
- package/build/beta/JwtManager/JwtError.d.ts +8 -0
- package/build/beta/JwtManager/JwtError.js +10 -0
- package/build/beta/JwtManager/JwtError.js.map +1 -0
- package/build/beta/JwtManager/JwtManager.d.ts +3 -0
- package/build/beta/JwtManager/JwtManager.js +24 -7
- package/build/beta/JwtManager/JwtManager.js.map +1 -1
- package/build/server/BodyParser.d.ts +6 -0
- package/build/server/BodyParser.js +18 -3
- package/build/server/BodyParser.js.map +1 -1
- package/build/server/Request.d.ts +6 -4
- package/build/server/Request.js +15 -10
- package/build/server/Request.js.map +1 -1
- package/build/server/Response.d.ts +24 -9
- package/build/server/Response.js +160 -74
- package/build/server/Response.js.map +1 -1
- package/build/server/Server.js +29 -6
- package/build/server/Server.js.map +1 -1
- package/build/server/config/Config.d.ts +15 -13
- package/build/server/config/Config.js +8 -6
- package/build/server/config/Config.js.map +1 -1
- package/build/server/config/Loader.js +1 -1
- package/build/server/config/Loader.js.map +1 -1
- package/build/server/router/Router.d.ts +1 -1
- package/build/server/router/Router.js +3 -3
- package/build/server/router/Router.js.map +1 -1
- package/build/server/router/middleware/HttpMiddleware.js +1 -1
- package/build/server/router/middleware/HttpMiddleware.js.map +1 -1
- package/build/server/router/middleware/WsMiddleware.js +1 -1
- package/build/server/router/middleware/WsMiddleware.js.map +1 -1
- package/build/server/security/PathSecurity.d.ts +45 -0
- package/build/server/security/PathSecurity.js +108 -0
- package/build/server/security/PathSecurity.js.map +1 -0
- package/build/server/websocket/Websocket.js +4 -1
- package/build/server/websocket/Websocket.js.map +1 -1
- package/build/utilities/ConsoleUI.d.ts +2 -1
- package/build/utilities/ConsoleUI.js +2 -1
- package/build/utilities/ConsoleUI.js.map +1 -1
- package/build/utilities/DebugUI.d.ts +1 -1
- package/build/utilities/DebugUI.js +1 -1
- package/build/utilities/Encoding.d.ts +22 -0
- package/build/utilities/Encoding.js +26 -0
- package/build/utilities/Encoding.js.map +1 -0
- package/build/utilities/Env.js +7 -2
- package/build/utilities/Env.js.map +1 -1
- package/build/utilities/File.d.ts +10 -0
- package/build/utilities/File.js +19 -0
- package/build/utilities/File.js.map +1 -0
- package/build/utilities/Flatten.d.ts +18 -1
- package/build/utilities/Flatten.js +18 -1
- package/build/utilities/Flatten.js.map +1 -1
- package/build/utilities/Object.d.ts +16 -0
- package/build/utilities/Object.js +48 -0
- package/build/utilities/Object.js.map +1 -0
- package/build/utilities/Path.d.ts +31 -11
- package/build/utilities/Path.js +48 -15
- package/build/utilities/Path.js.map +1 -1
- package/build/utilities/Time.d.ts +21 -0
- package/build/utilities/Time.js +25 -0
- package/build/utilities/Time.js.map +1 -0
- package/build/utilities/Utilities.d.ts +43 -34
- package/build/utilities/Utilities.js +48 -38
- package/build/utilities/Utilities.js.map +1 -1
- package/changes.md +4 -0
- package/docs/ARCHITECTURE.md +142 -0
- package/global/style/template/error.css +29 -0
- package/global/style/template/folder.css +79 -0
- package/global/{Style/Template/Template.css → style/template/template.css} +60 -68
- package/global/template/error.vhtml +29 -0
- package/global/template/folder.vhtml +54 -0
- package/package.json +2 -2
- package/build/Template.d.ts +0 -46
- package/build/Template.js +0 -81
- package/build/Template.js.map +0 -1
- package/global/Style/Template/Error.css +0 -30
- package/global/Style/Template/Folder.css +0 -77
- package/global/Template/Error.vhtml +0 -29
- package/global/Template/Folder.vhtml +0 -41
- package/tests/Template/template.js +0 -18
- package/tests/Template/template.txt +0 -13
- package/tests/Template/template.vhtml +0 -23
- package/tests/config/config.js +0 -233
- package/tests/debug.js +0 -34
- package/tests/jwtManager/jwtManager.js +0 -342
- package/tests/router.js +0 -596
- package/tests/schema/schema.js +0 -368
- package/tests/test.env +0 -0
- package/tests/test.js +0 -131
- package/tests/test.vhtml +0 -14
- package/tests/utilities.js +0 -28
- package/tests/websocket.vhtml +0 -86
- /package/global/{Source/Logo_960.png → source/logo_960.png} +0 -0
- /package/global/{Source/Logo_SM_960.png → source/logo_SM_960.png} +0 -0
package/.gitignore
CHANGED
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ The package exports a default `Vortez` server class, plus named exports for `Rou
|
|
|
26
26
|
- [Installation](#installation)
|
|
27
27
|
- [Getting Started](#getting-started)
|
|
28
28
|
- [Configuration Files](#configuration-files)
|
|
29
|
+
- [Architecture Guide](#architecture-guide)
|
|
29
30
|
- [Examples Repository](#examples-repository)
|
|
30
31
|
- [Core Concepts](#core-concepts)
|
|
31
32
|
- [Routing Rules](#routing-rules)
|
|
@@ -162,8 +163,16 @@ const server = new Vortez(config);
|
|
|
162
163
|
await server.start();
|
|
163
164
|
```
|
|
164
165
|
|
|
166
|
+
> [!NOTE]
|
|
167
|
+
> Template defaults are absolute by design and point to this module's bundled `global/Template/*` files.
|
|
168
|
+
> If you set `templates.error` or `templates.folder` yourself, you can still use paths relative to your own project.
|
|
169
|
+
|
|
165
170
|
This workflow is also covered in the dedicated examples repository.
|
|
166
171
|
|
|
172
|
+
### Architecture Guide
|
|
173
|
+
|
|
174
|
+
For a comprehensive guide on Vortez's internal architecture, request lifecycle, performance considerations, and deployment patterns, see [Architecture Documentation](docs/ARCHITECTURE.md).
|
|
175
|
+
|
|
167
176
|
### Examples Repository
|
|
168
177
|
|
|
169
178
|
The runnable examples are being moved to a separate repository to keep this package focused.
|
|
@@ -217,24 +226,20 @@ server.router.addAction('GET', '/api/$action/$id', (request, response) => {
|
|
|
217
226
|
console.log(request.headers); // HTTP headers
|
|
218
227
|
// For body, use: const body = await request.post;
|
|
219
228
|
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
### Response Object
|
|
223
|
-
|
|
224
|
-
The `response` object provides methods to send data back to the client:
|
|
229
|
+
```. All methods are **async** and must be awaited:
|
|
225
230
|
|
|
226
231
|
```js
|
|
227
232
|
// Send JSON
|
|
228
|
-
response.sendJson({ key: 'value' });
|
|
233
|
+
await response.sendJson({ key: 'value' });
|
|
229
234
|
|
|
230
235
|
// Send HTML/text
|
|
231
|
-
response.send('Hello World');
|
|
236
|
+
await response.send('Hello World');
|
|
232
237
|
|
|
233
238
|
// Send file
|
|
234
|
-
response.sendFile('path/to/file.html');
|
|
239
|
+
await response.sendFile('path/to/file.html');
|
|
235
240
|
|
|
236
241
|
// Send with custom status and headers
|
|
237
|
-
response.sendJson({ id: 123 }, {
|
|
242
|
+
await response.sendJson({ id: 123 }, {
|
|
238
243
|
status: 201,
|
|
239
244
|
headers: {
|
|
240
245
|
'X-Test': 'TestHeader'
|
|
@@ -244,6 +249,12 @@ response.sendJson({ id: 123 }, {
|
|
|
244
249
|
// The same options shape is supported by send, sendJson, sendFile and sendTemplate
|
|
245
250
|
```
|
|
246
251
|
|
|
252
|
+
> **Breaking Change in 5.0.0**: All response methods are now async. Update your route handlers to use `await` when calling response methods.
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// The same options shape is supported by send, sendJson, sendFile and sendTemplate
|
|
256
|
+
```
|
|
257
|
+
|
|
247
258
|
### Middleware Execution Model
|
|
248
259
|
|
|
249
260
|
Vortez uses a **snapshot middleware composition model**:
|
|
@@ -563,6 +574,12 @@ server.config.set('ssl', {
|
|
|
563
574
|
|
|
564
575
|
The framework will automatically create an HTTPS server alongside the HTTP server.
|
|
565
576
|
|
|
577
|
+
### Template Path Behavior
|
|
578
|
+
|
|
579
|
+
- `templates.error` and `templates.folder` default to absolute module paths inside Vortez's own `global/Template` directory.
|
|
580
|
+
- This is intentional so defaults work consistently regardless of where your app is executed from.
|
|
581
|
+
- When you provide your own template paths, relative paths are allowed and resolved from your app/project context.
|
|
582
|
+
|
|
566
583
|
### Available Configuration Keys
|
|
567
584
|
|
|
568
585
|
```js
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Add the vhtml template compiler to the Vortez.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export declare const VARIABLE: RegExp;
|
|
7
|
+
export declare const VARIABLE_TAG: RegExp;
|
|
8
|
+
export declare const EACH_BLOCK: RegExp;
|
|
9
|
+
export declare const IF_BLOCK: RegExp;
|
|
10
|
+
export declare class Compiler {
|
|
11
|
+
/**
|
|
12
|
+
* Compile a template.
|
|
13
|
+
* This internal method takes the raw template content and the data object
|
|
14
|
+
* and performs the actual compilation, replacing variables and processing
|
|
15
|
+
* object/array blocks according to the defined syntax.
|
|
16
|
+
*
|
|
17
|
+
* @example `Template.compile('Hello, ${name}!', { name: 'Alice' });`
|
|
18
|
+
* @param content - The content of the template.
|
|
19
|
+
* @param data - The data used to compile the template.
|
|
20
|
+
* @returns The compiled template.
|
|
21
|
+
* @throws Error if key and value names are equal in object blocks.
|
|
22
|
+
*/
|
|
23
|
+
static compile(content: string, data: Compiler.Data): string;
|
|
24
|
+
/**
|
|
25
|
+
* Compile all the variables in the template content using the provided data object.
|
|
26
|
+
* @param content - The raw template content containing variable placeholders.
|
|
27
|
+
* @param data - The data object used for variable substitution.
|
|
28
|
+
* @returns The template content with all variables replaced by their corresponding values from the data object.
|
|
29
|
+
*/
|
|
30
|
+
private static compileVariables;
|
|
31
|
+
/**
|
|
32
|
+
* Finds the index of the closing tag corresponding to a given opening tag in the template content, accounting for nested tags of the same type.
|
|
33
|
+
* @param content - The raw template content containing the tags.
|
|
34
|
+
* @param openTag - The opening tag to match (e.g., '<vortez-each').
|
|
35
|
+
* @param closeTag - The closing tag to match (e.g., '</vortez-each>').
|
|
36
|
+
* @param startIndex - The index in the content where the search should begin (typically right after the opening tag).
|
|
37
|
+
* @returns The index of the closing tag that matches the opening tag, or -1 if no matching closing tag is found.
|
|
38
|
+
*/
|
|
39
|
+
private static findClosingTag;
|
|
40
|
+
/**
|
|
41
|
+
* Compile all the if/else blocks in the template content using the provided data object.
|
|
42
|
+
* @param content - The raw template content containing if/else block placeholders.
|
|
43
|
+
* @param data - The data object used for block processing.
|
|
44
|
+
* @returns The template content with all if/else blocks processed and replaced by their corresponding generated content based on the data object.
|
|
45
|
+
*/
|
|
46
|
+
static compileEachBlocks(content: string, data: Compiler.Data): string;
|
|
47
|
+
static compileIfBlocks(content: string, data: Compiler.Data): string;
|
|
48
|
+
}
|
|
49
|
+
export declare namespace Compiler {
|
|
50
|
+
interface VariableGroups {
|
|
51
|
+
name: string;
|
|
52
|
+
default?: string;
|
|
53
|
+
}
|
|
54
|
+
interface EachBlockGroups {
|
|
55
|
+
name: string;
|
|
56
|
+
keyName?: string;
|
|
57
|
+
valueName?: string;
|
|
58
|
+
loop: string;
|
|
59
|
+
}
|
|
60
|
+
interface IfBlockGroups {
|
|
61
|
+
name: string;
|
|
62
|
+
condition?: '==' | '!=';
|
|
63
|
+
expected?: string;
|
|
64
|
+
content: string;
|
|
65
|
+
}
|
|
66
|
+
interface Data {
|
|
67
|
+
[key: string]: any;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export default Compiler;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Add the vhtml template compiler to the Vortez.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export const VARIABLE = /\{\{\s*?(?<name>\w+)(?:\s*\|\|\s*(?<quote>["'])(?<default>.*?)\k<quote>)?\s*\}\}/g;
|
|
7
|
+
export const VARIABLE_TAG = /<vortez-var\s+name=["'](?<name>\w+)["'](?:\s+default=["'](?<default>.*?)["'])?\s*(?:\/>|>(?<content>.*?)<\/vortez-var>)/g;
|
|
8
|
+
export const EACH_BLOCK = /<vortez-each\s+name=["'](?<name>\w+)["'](?:\s+value=["'](?<valueName>\w+)["'])?(?:\s+key=["'](?<keyName>\w+)["'])?\s*>(?<loop>[^]+?)<\/vortez-each>/g;
|
|
9
|
+
export const IF_BLOCK = /<vortez-if\s+name=["'](?<name>\w+)["'](?:\s+condition=["'](?<condition>==|!=)["']\s+expected=["'](?<expected>.*?)["'])?\s*>(?<content>[^]+?)<\/vortez-if>/g;
|
|
10
|
+
export class Compiler {
|
|
11
|
+
/**
|
|
12
|
+
* Compile a template.
|
|
13
|
+
* This internal method takes the raw template content and the data object
|
|
14
|
+
* and performs the actual compilation, replacing variables and processing
|
|
15
|
+
* object/array blocks according to the defined syntax.
|
|
16
|
+
*
|
|
17
|
+
* @example `Template.compile('Hello, ${name}!', { name: 'Alice' });`
|
|
18
|
+
* @param content - The content of the template.
|
|
19
|
+
* @param data - The data used to compile the template.
|
|
20
|
+
* @returns The compiled template.
|
|
21
|
+
* @throws Error if key and value names are equal in object blocks.
|
|
22
|
+
*/
|
|
23
|
+
static compile(content, data) {
|
|
24
|
+
content = Compiler.compileEachBlocks(content, data);
|
|
25
|
+
content = Compiler.compileIfBlocks(content, data);
|
|
26
|
+
content = Compiler.compileVariables(content, data);
|
|
27
|
+
return content;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Compile all the variables in the template content using the provided data object.
|
|
31
|
+
* @param content - The raw template content containing variable placeholders.
|
|
32
|
+
* @param data - The data object used for variable substitution.
|
|
33
|
+
* @returns The template content with all variables replaced by their corresponding values from the data object.
|
|
34
|
+
*/
|
|
35
|
+
static compileVariables(content, data) {
|
|
36
|
+
content = content.replace(VARIABLE, (text, ...args) => {
|
|
37
|
+
const groups = args.pop();
|
|
38
|
+
const { name, default: defaultValue } = groups;
|
|
39
|
+
return name && name in data ? data[name] : defaultValue || text;
|
|
40
|
+
});
|
|
41
|
+
content = content.replace(VARIABLE_TAG, (text, ...args) => {
|
|
42
|
+
const groups = args.pop();
|
|
43
|
+
const { name, default: defaultValue, content: tagContent } = groups;
|
|
44
|
+
return name && name in data ? data[name] : defaultValue || tagContent || text;
|
|
45
|
+
});
|
|
46
|
+
return content;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Finds the index of the closing tag corresponding to a given opening tag in the template content, accounting for nested tags of the same type.
|
|
50
|
+
* @param content - The raw template content containing the tags.
|
|
51
|
+
* @param openTag - The opening tag to match (e.g., '<vortez-each').
|
|
52
|
+
* @param closeTag - The closing tag to match (e.g., '</vortez-each>').
|
|
53
|
+
* @param startIndex - The index in the content where the search should begin (typically right after the opening tag).
|
|
54
|
+
* @returns The index of the closing tag that matches the opening tag, or -1 if no matching closing tag is found.
|
|
55
|
+
*/
|
|
56
|
+
static findClosingTag(content, openTag, closeTag, startIndex) {
|
|
57
|
+
let depth = 0;
|
|
58
|
+
const tagRegex = new RegExp(`${openTag}|${closeTag}`, 'g');
|
|
59
|
+
tagRegex.lastIndex = startIndex;
|
|
60
|
+
let match;
|
|
61
|
+
while ((match = tagRegex.exec(content)) !== null) {
|
|
62
|
+
if (match[0].startsWith(openTag.substring(0, 3)))
|
|
63
|
+
depth++;
|
|
64
|
+
if (match[0] === closeTag)
|
|
65
|
+
depth--;
|
|
66
|
+
if (depth === 0)
|
|
67
|
+
return match.index;
|
|
68
|
+
}
|
|
69
|
+
return -1;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Compile all the if/else blocks in the template content using the provided data object.
|
|
73
|
+
* @param content - The raw template content containing if/else block placeholders.
|
|
74
|
+
* @param data - The data object used for block processing.
|
|
75
|
+
* @returns The template content with all if/else blocks processed and replaced by their corresponding generated content based on the data object.
|
|
76
|
+
*/
|
|
77
|
+
static compileEachBlocks(content, data) {
|
|
78
|
+
const openTagMatch = /<vortez-each\s+name=["'](?<name>\w+)["']/.exec(content);
|
|
79
|
+
if (!openTagMatch)
|
|
80
|
+
return content;
|
|
81
|
+
const startIdx = openTagMatch.index;
|
|
82
|
+
const endHeaderIdx = content.indexOf('>', startIdx);
|
|
83
|
+
const closingIdx = this.findClosingTag(content, '<vortez-each', '</vortez-each>', startIdx);
|
|
84
|
+
if (closingIdx === -1)
|
|
85
|
+
return `<p>the block is not closed: ${content.substring(startIdx, startIdx + 30)}...</p>`;
|
|
86
|
+
const fullBlock = content.substring(startIdx, closingIdx + 14);
|
|
87
|
+
const innerLoop = content.substring(endHeaderIdx + 1, closingIdx);
|
|
88
|
+
const header = content.substring(startIdx, endHeaderIdx);
|
|
89
|
+
const name = openTagMatch.groups?.name;
|
|
90
|
+
const valueName = /value=["'](?<v>\w+)["']/.exec(header)?.groups?.v || 'value';
|
|
91
|
+
const keyName = /key=["'](?<k>\w+)["']/.exec(header)?.groups?.k || 'key';
|
|
92
|
+
const iterable = data[name];
|
|
93
|
+
let result = "";
|
|
94
|
+
if (!iterable)
|
|
95
|
+
return `<p>the iterable "${name}" is not defined</p>`;
|
|
96
|
+
if (keyName === valueName)
|
|
97
|
+
return `<p>the key and value names must be different in block: ${fullBlock}</p>`;
|
|
98
|
+
if (iterable instanceof Object) {
|
|
99
|
+
result = Object.entries(iterable).map(([k, v]) => {
|
|
100
|
+
const context = { ...data, [keyName]: k, [valueName]: v };
|
|
101
|
+
return this.compile(innerLoop, context);
|
|
102
|
+
}).join('');
|
|
103
|
+
}
|
|
104
|
+
return this.compileEachBlocks(content.replace(fullBlock, result), data);
|
|
105
|
+
}
|
|
106
|
+
static compileIfBlocks(content, data) {
|
|
107
|
+
const openTagMatch = /<vortez-if\s+name=["'](?<name>\w+)["']/.exec(content);
|
|
108
|
+
if (!openTagMatch)
|
|
109
|
+
return content;
|
|
110
|
+
const startIdx = openTagMatch.index;
|
|
111
|
+
const endHeaderIdx = content.indexOf('>', startIdx);
|
|
112
|
+
const closingIdx = this.findClosingTag(content, '<vortez-if', '</vortez-if>', startIdx);
|
|
113
|
+
if (closingIdx === -1)
|
|
114
|
+
return `<p>the block is not closed: ${content.substring(startIdx, startIdx + 30)}...</p>`;
|
|
115
|
+
const fullBlock = content.substring(startIdx, closingIdx + 12);
|
|
116
|
+
const innerContent = content.substring(endHeaderIdx + 1, closingIdx);
|
|
117
|
+
const header = content.substring(startIdx, endHeaderIdx);
|
|
118
|
+
const name = openTagMatch.groups?.name;
|
|
119
|
+
const condition = /condition=["'](?<c>==|!=)["']/.exec(header)?.groups?.c;
|
|
120
|
+
const expected = /expected=["'](?<e>.*?)["']/.exec(header)?.groups?.e;
|
|
121
|
+
const [ifPart, elsePart] = innerContent.split(/<vortez-else\s*?\/>/);
|
|
122
|
+
const value = data[name];
|
|
123
|
+
let isTrue = false;
|
|
124
|
+
if (condition && expected !== undefined) {
|
|
125
|
+
const resExpected = expected.includes('{{') ? this.compileVariables(expected, data) : expected;
|
|
126
|
+
isTrue = (condition === '==') ? String(value) === String(resExpected) : String(value) !== String(resExpected);
|
|
127
|
+
}
|
|
128
|
+
else
|
|
129
|
+
isTrue = !!value;
|
|
130
|
+
const compiledPart = this.compile(isTrue ? ifPart : (elsePart || ""), data);
|
|
131
|
+
return this.compileIfBlocks(content.replace(fullBlock, compiledPart), data);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export default Compiler;
|
|
135
|
+
//# sourceMappingURL=Compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Compiler.js","sourceRoot":"","sources":["../../src/Template/Compiler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,mFAAmF,CAAC;AAC5G,MAAM,CAAC,MAAM,YAAY,GAAG,0HAA0H,CAAC;AACvJ,MAAM,CAAC,MAAM,UAAU,GAAG,sJAAsJ,CAAC;AACjL,MAAM,CAAC,MAAM,QAAQ,GAAG,4JAA4J,CAAC;AAErL,MAAM,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AC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACrE,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,MAAM,GAAG,KAAK,CAAC;QAEnB,IAAI,SAAS,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,WAAW,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YAC/F,MAAM,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,WAAW,CAAC,CAAC;QAClH,CAAC;;YAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC;QAExB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QAE5E,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC;IAChF,CAAC;CACJ;AAsBD,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Add the vhtml template stream compiler to the Vortez.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Transform, TransformCallback } from 'stream';
|
|
7
|
+
import { Compiler } from './Compiler.js';
|
|
8
|
+
export declare class StreamCompiler extends Transform {
|
|
9
|
+
private buffer;
|
|
10
|
+
private data;
|
|
11
|
+
constructor(data: Compiler.Data);
|
|
12
|
+
_transform(chunk: unknown, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
13
|
+
_flush(callback: TransformCallback): void;
|
|
14
|
+
}
|
|
15
|
+
export declare namespace StreamCompiler { }
|
|
16
|
+
export default StreamCompiler;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Add the vhtml template stream compiler to the Vortez.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Transform } from 'stream';
|
|
7
|
+
import { Compiler } from './Compiler.js';
|
|
8
|
+
export class StreamCompiler extends Transform {
|
|
9
|
+
buffer = '';
|
|
10
|
+
data;
|
|
11
|
+
constructor(data) {
|
|
12
|
+
super();
|
|
13
|
+
this.data = data;
|
|
14
|
+
}
|
|
15
|
+
_transform(chunk, encoding, callback) {
|
|
16
|
+
if (typeof chunk === 'string')
|
|
17
|
+
this.buffer += chunk;
|
|
18
|
+
else if (Buffer.isBuffer(chunk))
|
|
19
|
+
this.buffer += chunk.toString('utf-8');
|
|
20
|
+
else
|
|
21
|
+
return callback(new Error('Invalid chunk type. Expected string or Buffer.'));
|
|
22
|
+
const matches = Array.from(this.buffer.matchAll(/<(vortez-if|vortez-each)|<\/(vortez-if|vortez-each)>/g));
|
|
23
|
+
let depth = 0;
|
|
24
|
+
let lastBalancedIndex = -1;
|
|
25
|
+
if (matches.length > 0) {
|
|
26
|
+
for (const match of matches) {
|
|
27
|
+
if (match[0].startsWith('</'))
|
|
28
|
+
depth--;
|
|
29
|
+
else
|
|
30
|
+
depth++;
|
|
31
|
+
if (depth === 0)
|
|
32
|
+
lastBalancedIndex = match.index + match[0].length;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const lastVar = Math.max(this.buffer.lastIndexOf('}}'), this.buffer.lastIndexOf('/>'));
|
|
37
|
+
if (lastVar !== -1)
|
|
38
|
+
lastBalancedIndex = this.buffer.indexOf('>', lastVar) + 1 || lastVar + 2;
|
|
39
|
+
}
|
|
40
|
+
if (lastBalancedIndex !== -1) {
|
|
41
|
+
const completePart = this.buffer.substring(0, lastBalancedIndex);
|
|
42
|
+
this.buffer = this.buffer.substring(lastBalancedIndex);
|
|
43
|
+
this.push(Compiler.compile(completePart, this.data));
|
|
44
|
+
}
|
|
45
|
+
callback();
|
|
46
|
+
}
|
|
47
|
+
_flush(callback) {
|
|
48
|
+
if (this.buffer.trim())
|
|
49
|
+
this.push(Compiler.compile(this.buffer, this.data));
|
|
50
|
+
callback();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export default StreamCompiler;
|
|
54
|
+
//# sourceMappingURL=StreamCompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamCompiler.js","sourceRoot":"","sources":["../../src/Template/StreamCompiler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAqB,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,cAAe,SAAQ,SAAS;IACjC,MAAM,GAAW,EAAE,CAAC;IACpB,IAAI,CAAgB;IAE5B,YAAY,IAAmB;QAC3B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAEW,UAAU,CAAC,KAAc,EAAE,QAAwB,EAAE,QAA2B;QACxF,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC;aAC/C,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;;YACnE,OAAO,QAAQ,CAAC,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC,CAAC;QAElF,MAAM,OAAO,GAAG,K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Q,EAAE,CAAC;IACf,CAAC;IAEe,MAAM,CAAC,QAA2B;QAC9C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;YAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5E,QAAQ,EAAE,CAAC;IACf,CAAC;CACJ;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Add the vhtml template engine to the Vortez.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Readable } from 'stream';
|
|
7
|
+
import Compiler from './Compiler.js';
|
|
8
|
+
import { StreamCompiler } from './StreamCompiler.js';
|
|
9
|
+
export declare class Template {
|
|
10
|
+
/**
|
|
11
|
+
* Load and compile a template.
|
|
12
|
+
* This method reads a template file from the specified path,
|
|
13
|
+
* checks if it's a valid file, and then compiles its content
|
|
14
|
+
* using the provided data object.
|
|
15
|
+
*
|
|
16
|
+
* @example `Template.load('./templates/myTemplate.html', { username: 'John Doe' });`
|
|
17
|
+
* @param path - The path to the template file.
|
|
18
|
+
* @param data - The data used to compile the template.
|
|
19
|
+
* @returns The compiled template.
|
|
20
|
+
* @throws Error if the path is not a file.
|
|
21
|
+
* @throws Error if the file does not exist.
|
|
22
|
+
*/
|
|
23
|
+
static load(path: string, data: Compiler.Data): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Load and compile a template using streams.
|
|
26
|
+
* Ideal for large files or serving directly to a response.
|
|
27
|
+
* @example `Template.stream('./views/index.vhtml', data).pipe(res);`
|
|
28
|
+
* @param path - The path to the template file.
|
|
29
|
+
* @param data - The data used to compile the template.
|
|
30
|
+
* @returns A Readable stream with the compiled content.
|
|
31
|
+
*/
|
|
32
|
+
static stream(path: string, data: Compiler.Data): Promise<Readable>;
|
|
33
|
+
/**
|
|
34
|
+
* Compile a template string with the provided data.
|
|
35
|
+
* @param content - The template content to compile.
|
|
36
|
+
* @param data - The data used to compile the template.
|
|
37
|
+
* @returns The compiled template.
|
|
38
|
+
*/
|
|
39
|
+
static compile(content: string, data: Compiler.Data): string;
|
|
40
|
+
/**
|
|
41
|
+
* Compile a template from a stream with the provided data.
|
|
42
|
+
* @param stream - The Readable stream containing the template content.
|
|
43
|
+
* @param data - The data used to compile the template.
|
|
44
|
+
* @returns A StreamCompiler instance that can be piped to a Writable stream.
|
|
45
|
+
*/
|
|
46
|
+
static compileStream(stream: Readable, data: Compiler.Data): StreamCompiler;
|
|
47
|
+
}
|
|
48
|
+
export declare namespace Template { }
|
|
49
|
+
export default Template;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
3
|
+
* @description Add the vhtml template engine to the Vortez.
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { promises as FSP, createReadStream } from 'fs';
|
|
7
|
+
import Utilities from '../utilities/Utilities.js';
|
|
8
|
+
import Compiler from './Compiler.js';
|
|
9
|
+
import { StreamCompiler } from './StreamCompiler.js';
|
|
10
|
+
export class Template {
|
|
11
|
+
/**
|
|
12
|
+
* Load and compile a template.
|
|
13
|
+
* This method reads a template file from the specified path,
|
|
14
|
+
* checks if it's a valid file, and then compiles its content
|
|
15
|
+
* using the provided data object.
|
|
16
|
+
*
|
|
17
|
+
* @example `Template.load('./templates/myTemplate.html', { username: 'John Doe' });`
|
|
18
|
+
* @param path - The path to the template file.
|
|
19
|
+
* @param data - The data used to compile the template.
|
|
20
|
+
* @returns The compiled template.
|
|
21
|
+
* @throws Error if the path is not a file.
|
|
22
|
+
* @throws Error if the file does not exist.
|
|
23
|
+
*/
|
|
24
|
+
static async load(path, data) {
|
|
25
|
+
path = Utilities.Path.normalize(path);
|
|
26
|
+
if (!Utilities.File.exists(path))
|
|
27
|
+
throw new Error('template file does not exist');
|
|
28
|
+
const details = await FSP.stat(path);
|
|
29
|
+
if (!details.isFile())
|
|
30
|
+
throw new Error('the path is not a template file');
|
|
31
|
+
const template = await FSP.readFile(path);
|
|
32
|
+
return Compiler.compile(template.toString('utf-8'), data);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Load and compile a template using streams.
|
|
36
|
+
* Ideal for large files or serving directly to a response.
|
|
37
|
+
* @example `Template.stream('./views/index.vhtml', data).pipe(res);`
|
|
38
|
+
* @param path - The path to the template file.
|
|
39
|
+
* @param data - The data used to compile the template.
|
|
40
|
+
* @returns A Readable stream with the compiled content.
|
|
41
|
+
*/
|
|
42
|
+
static async stream(path, data) {
|
|
43
|
+
path = Utilities.Path.normalize(path);
|
|
44
|
+
if (!Utilities.File.exists(path))
|
|
45
|
+
throw new Error('template file does not exist');
|
|
46
|
+
const details = await FSP.stat(path);
|
|
47
|
+
if (!details.isFile())
|
|
48
|
+
throw new Error('the path is not a template file');
|
|
49
|
+
const readStream = createReadStream(path);
|
|
50
|
+
const compiler = new StreamCompiler(data);
|
|
51
|
+
readStream.on('error', (err) => compiler.emit('error', err));
|
|
52
|
+
return readStream.pipe(compiler);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Compile a template string with the provided data.
|
|
56
|
+
* @param content - The template content to compile.
|
|
57
|
+
* @param data - The data used to compile the template.
|
|
58
|
+
* @returns The compiled template.
|
|
59
|
+
*/
|
|
60
|
+
static compile(content, data) {
|
|
61
|
+
return Compiler.compile(content, data);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Compile a template from a stream with the provided data.
|
|
65
|
+
* @param stream - The Readable stream containing the template content.
|
|
66
|
+
* @param data - The data used to compile the template.
|
|
67
|
+
* @returns A StreamCompiler instance that can be piped to a Writable stream.
|
|
68
|
+
*/
|
|
69
|
+
static compileStream(stream, data) {
|
|
70
|
+
const compiler = new StreamCompiler(data);
|
|
71
|
+
stream.on('error', (err) => compiler.emit('error', err));
|
|
72
|
+
stream.pipe(compiler);
|
|
73
|
+
return compiler;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export default Template;
|
|
77
|
+
//# sourceMappingURL=Template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Template.js","sourceRoot":"","sources":["../../src/Template/Template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAC;AAGvD,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAClD,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,OAAO,QAAQ;IACjB;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,IAAmB;QACtD,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAC5E,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAC1E,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;IACD;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,IAAmB;QACxD,IAAI,GAAG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@
|
|
|
5
5
|
* @license Apache-2.0
|
|
6
6
|
*/
|
|
7
7
|
export { Logger } from "./logger/Logger.js";
|
|
8
|
-
export { Template } from "./Template.js";
|
|
8
|
+
export { Template } from "./Template/Template.js";
|
|
9
9
|
export { Utilities } from "./utilities/Utilities.js";
|
|
10
10
|
export * as Beta from "./beta/Beta.js";
|
|
11
11
|
export { ServerError } from "./server/ServerError.js";
|
package/build/Vortez.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @license Apache-2.0
|
|
6
6
|
*/
|
|
7
7
|
export { Logger } from "./logger/Logger.js";
|
|
8
|
-
export { Template } from "./Template.js";
|
|
8
|
+
export { Template } from "./Template/Template.js";
|
|
9
9
|
export { Utilities } from "./utilities/Utilities.js";
|
|
10
10
|
export * as Beta from "./beta/Beta.js";
|
|
11
11
|
export { ServerError } from "./server/ServerError.js";
|
package/build/Vortez.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vortez.js","sourceRoot":"","sources":["../src/Vortez.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Vortez.js","sourceRoot":"","sources":["../src/Vortez.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class JwtError extends Error {
|
|
2
|
+
readonly code: JwtError.Code;
|
|
3
|
+
constructor(code: JwtError.Code, message: string, options?: ErrorOptions);
|
|
4
|
+
}
|
|
5
|
+
export declare namespace JwtError {
|
|
6
|
+
type Code = ('TOKEN_INVALID' | 'KEY_NOT_FOUND' | 'INVALID_SIGNATURE' | 'TOKEN_EXPIRED' | 'SIGN_FAILED');
|
|
7
|
+
}
|
|
8
|
+
export default JwtError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JwtError.js","sourceRoot":"","sources":["../../../src/beta/JwtManager/JwtError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACf,IAAI,CAAgB;IAEpC,YAAmB,IAAmB,EAAE,OAAe,EAAE,UAAwB,EAAE;QAC/E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAYD,eAAe,QAAQ,CAAC"}
|
|
@@ -3,11 +3,13 @@ import _Algorithm from "./algorithm/Algorithm.js";
|
|
|
3
3
|
import _JwtUtils from "./JwtUtils.js";
|
|
4
4
|
import _KeyEntry from "./KeyEntry.js";
|
|
5
5
|
import _Jwt from "./Jwt.js";
|
|
6
|
+
import _JwtError from "./JwtError.js";
|
|
6
7
|
export { KeyGenerator } from "./KeyGenerator.js";
|
|
7
8
|
export { Algorithm } from "./algorithm/Algorithm.js";
|
|
8
9
|
export { JwtUtils } from "./JwtUtils.js";
|
|
9
10
|
export { KeyEntry as KIDEntry } from "./KeyEntry.js";
|
|
10
11
|
export { Jwt } from "./Jwt.js";
|
|
12
|
+
export { JwtError } from "./JwtError.js";
|
|
11
13
|
export declare class JwtManager {
|
|
12
14
|
protected KIDMap: JwtManager.KIDMap;
|
|
13
15
|
protected defaultEntry: JwtManager.KeyEntry;
|
|
@@ -48,6 +50,7 @@ export declare namespace JwtManager {
|
|
|
48
50
|
export import JwtUtils = _JwtUtils;
|
|
49
51
|
export import KeyEntry = _KeyEntry;
|
|
50
52
|
export import Jwt = _Jwt;
|
|
53
|
+
export import JwtError = _JwtError;
|
|
51
54
|
type KeyOption = KeyEntry | KeyEntry.KeyEntryOptions;
|
|
52
55
|
interface KIDMap {
|
|
53
56
|
[kid: string]: KeyEntry;
|