@flancer32/teq-web 0.4.0 → 0.6.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/CHANGELOG.md +30 -0
- package/README.md +236 -127
- package/ai/AGENTS.md +36 -0
- package/ai/abstractions.md +75 -0
- package/ai/examples/minimal-server.md +79 -0
- package/ai/overview.md +29 -0
- package/ai/rules.md +44 -0
- package/package.json +43 -37
- package/src/Back/Api/Handler.mjs +26 -0
- package/src/Back/Config/Runtime/Tls.mjs +89 -0
- package/src/Back/Config/Runtime.mjs +114 -0
- package/src/Back/Dto/Info.mjs +62 -0
- package/src/Back/Dto/RequestContext.mjs +33 -0
- package/src/Back/Dto/{Handler/Source.js → Source.mjs} +24 -25
- package/src/Back/Enum/Server/Type.mjs +13 -0
- package/src/Back/Enum/Stage.mjs +13 -0
- package/src/Back/Handler/Pre/Log.mjs +55 -0
- package/src/Back/Handler/Static/A/{Config.js → Config.mjs} +11 -4
- package/src/Back/Handler/Static/A/{Fallback.js → Fallback.mjs} +12 -4
- package/src/Back/Handler/Static/A/{FileService.js → FileService.mjs} +30 -17
- package/src/Back/Handler/Static/A/{Registry.js → Registry.mjs} +15 -7
- package/src/Back/Handler/Static/A/{Resolver.js → Resolver.mjs} +10 -3
- package/src/Back/Handler/Static.mjs +79 -0
- package/src/Back/Helper/Cast.mjs +116 -0
- package/src/Back/Helper/{Mime.js → Mime.mjs} +2 -0
- package/src/Back/Helper/Order/Kahn.mjs +69 -0
- package/src/Back/Helper/{Respond.js → Respond.mjs} +14 -7
- package/src/Back/Logger.mjs +57 -0
- package/src/Back/PipelineEngine.mjs +216 -0
- package/src/Back/{Server.js → Server.mjs} +38 -30
- package/types.d.ts +45 -22
- package/src/AGENTS.md +0 -108
- package/src/Back/Api/Handler.js +0 -26
- package/src/Back/Defaults.js +0 -6
- package/src/Back/Dispatcher.js +0 -115
- package/src/Back/Dto/Handler/Info.js +0 -68
- package/src/Back/Enum/Server/Type.js +0 -12
- package/src/Back/Enum/Stage.js +0 -10
- package/src/Back/Handler/Pre/Log.js +0 -45
- package/src/Back/Handler/Static.js +0 -63
- package/src/Back/Helper/Cast.js +0 -114
- package/src/Back/Helper/Order/Kahn.js +0 -66
- package/src/Back/Logger.js +0 -53
- package/src/Back/Server/Config/Tls.js +0 -55
- package/src/Back/Server/Config.js +0 -69
- package/teqfw.json +0 -8
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Factory for dispatcher handler registration metadata.
|
|
3
|
-
*
|
|
4
|
-
* Produces validated DTOs for registering web request handlers.
|
|
5
|
-
*
|
|
6
|
-
* @see TeqFw_Core_Shared_Api_Factory
|
|
7
|
-
*/
|
|
8
|
-
export default class Fl32_Web_Back_Dto_Handler_Info {
|
|
9
|
-
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
10
|
-
/**
|
|
11
|
-
* @param {Fl32_Web_Back_Helper_Cast} cast
|
|
12
|
-
* @param {typeof Fl32_Web_Back_Enum_Stage} STAGE
|
|
13
|
-
*/
|
|
14
|
-
constructor(
|
|
15
|
-
{
|
|
16
|
-
Fl32_Web_Back_Helper_Cast$: cast,
|
|
17
|
-
Fl32_Web_Back_Enum_Stage$: STAGE,
|
|
18
|
-
}
|
|
19
|
-
) {
|
|
20
|
-
/* eslint-enable jsdoc/check-param-names */
|
|
21
|
-
/**
|
|
22
|
-
* Create a validated DTO for handler registration.
|
|
23
|
-
*
|
|
24
|
-
* @param {*} [data] - Optional raw object.
|
|
25
|
-
* @returns {Dto}
|
|
26
|
-
*/
|
|
27
|
-
this.create = function (data) {
|
|
28
|
-
const res = (data && typeof data === 'object' && !Array.isArray(data))
|
|
29
|
-
? Object.assign(new Dto(), data)
|
|
30
|
-
: new Dto();
|
|
31
|
-
res.after = cast.array(data?.after, cast.string);
|
|
32
|
-
res.before = cast.array(data?.before, cast.string);
|
|
33
|
-
res.name = cast.string(data?.name);
|
|
34
|
-
res.stage = cast.enum(data?.stage, STAGE, {lower: true});
|
|
35
|
-
return res;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @memberOf Fl32_Web_Back_Dto_Handler_Info
|
|
42
|
-
*/
|
|
43
|
-
class Dto {
|
|
44
|
-
/**
|
|
45
|
-
* Handlers to run before this one.
|
|
46
|
-
* @type {string[]}
|
|
47
|
-
*/
|
|
48
|
-
after;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Handlers to run after this one.
|
|
52
|
-
* @type {string[]}
|
|
53
|
-
*/
|
|
54
|
-
before;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Unique handler name for ordering.
|
|
58
|
-
* @type {string}
|
|
59
|
-
*/
|
|
60
|
-
name;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Execution stage: 'pre', 'process', or 'post'.
|
|
64
|
-
* @type {string}
|
|
65
|
-
* @see Fl32_Web_Back_Enum_Stage
|
|
66
|
-
*/
|
|
67
|
-
stage;
|
|
68
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enum for server types used to configure built-in web server.
|
|
3
|
-
* - 'http': HTTP/1.1
|
|
4
|
-
* - 'http2': HTTP/2 without TLS (cleartext)
|
|
5
|
-
* - 'https': HTTP/2 over TLS (via http2.createSecureServer)
|
|
6
|
-
*/
|
|
7
|
-
const Fl32_Web_Back_Enum_Server_Type = {
|
|
8
|
-
HTTP2: 'http2',
|
|
9
|
-
HTTP: 'http',
|
|
10
|
-
HTTPS: 'https'
|
|
11
|
-
};
|
|
12
|
-
export default Fl32_Web_Back_Enum_Server_Type;
|
package/src/Back/Enum/Stage.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enum for web request processing stages in this plugin.
|
|
3
|
-
* Used to define processing phases in the web dispatcher specific to this plugin.
|
|
4
|
-
*/
|
|
5
|
-
const Fl32_Web_Back_Enum_Stage = {
|
|
6
|
-
PRE: 'pre', // Pre-processing stage: initial request handling (e.g., logging, authentication)
|
|
7
|
-
PROCESS: 'process', // Main processing stage: routing and core logic
|
|
8
|
-
POST: 'post' // Post-processing stage: final actions (e.g., logging response, cleanup)
|
|
9
|
-
};
|
|
10
|
-
export default Fl32_Web_Back_Enum_Stage;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logs basic request information at the beginning of the request lifecycle.
|
|
3
|
-
* @implements Fl32_Web_Back_Api_Handler
|
|
4
|
-
*/
|
|
5
|
-
export default class Fl32_Web_Back_Handler_Pre_Log {
|
|
6
|
-
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
7
|
-
/**
|
|
8
|
-
* @param {Fl32_Web_Back_Logger} logger
|
|
9
|
-
* @param {Fl32_Web_Back_Dto_Handler_Info} dtoInfo
|
|
10
|
-
* @param {typeof Fl32_Web_Back_Enum_Stage} STAGE
|
|
11
|
-
*/
|
|
12
|
-
constructor(
|
|
13
|
-
{
|
|
14
|
-
Fl32_Web_Back_Logger$: logger,
|
|
15
|
-
Fl32_Web_Back_Dto_Handler_Info$: dtoInfo,
|
|
16
|
-
Fl32_Web_Back_Enum_Stage$: STAGE,
|
|
17
|
-
}
|
|
18
|
-
) {
|
|
19
|
-
/* eslint-enable jsdoc/check-param-names */
|
|
20
|
-
// VARS
|
|
21
|
-
const _info = dtoInfo.create();
|
|
22
|
-
_info.name = this.constructor.name;
|
|
23
|
-
_info.stage = STAGE.PRE;
|
|
24
|
-
Object.freeze(_info);
|
|
25
|
-
|
|
26
|
-
// MAIN
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Log request method and URL.
|
|
30
|
-
*
|
|
31
|
-
* @param {module:http.IncomingMessage|module:http2.Http2ServerRequest} req
|
|
32
|
-
* @returns {Promise<void>}
|
|
33
|
-
*/
|
|
34
|
-
this.handle = async function (req) {
|
|
35
|
-
logger.debug(`${req.method} ${req.url}`);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Return handler registration info.
|
|
40
|
-
*
|
|
41
|
-
* @returns {Fl32_Web_Back_Dto_Handler_Info.Dto}
|
|
42
|
-
*/
|
|
43
|
-
this.getRegistrationInfo = () => _info;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Universal file handler serving files from multiple sources using helper modules.
|
|
3
|
-
*
|
|
4
|
-
* @implements Fl32_Web_Back_Api_Handler
|
|
5
|
-
*/
|
|
6
|
-
export default class Fl32_Web_Back_Handler_Static {
|
|
7
|
-
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
8
|
-
/**
|
|
9
|
-
* @param {Fl32_Web_Back_Handler_Static_A_Registry} registry
|
|
10
|
-
* @param {Fl32_Web_Back_Handler_Static_A_FileService} fileService
|
|
11
|
-
* @param {Fl32_Web_Back_Helper_Respond} respond
|
|
12
|
-
* @param {Fl32_Web_Back_Logger} logger
|
|
13
|
-
* @param {Fl32_Web_Back_Dto_Handler_Info} dtoInfo
|
|
14
|
-
* @param {typeof Fl32_Web_Back_Enum_Stage} STAGE
|
|
15
|
-
*/
|
|
16
|
-
constructor(
|
|
17
|
-
{
|
|
18
|
-
Fl32_Web_Back_Handler_Static_A_Registry$: registry,
|
|
19
|
-
Fl32_Web_Back_Handler_Static_A_FileService$: fileService,
|
|
20
|
-
Fl32_Web_Back_Helper_Respond$: respond,
|
|
21
|
-
Fl32_Web_Back_Logger$: logger,
|
|
22
|
-
Fl32_Web_Back_Dto_Handler_Info$: dtoInfo,
|
|
23
|
-
Fl32_Web_Back_Enum_Stage$: STAGE,
|
|
24
|
-
}
|
|
25
|
-
) {
|
|
26
|
-
/* eslint-enable jsdoc/check-param-names */
|
|
27
|
-
|
|
28
|
-
const _info = dtoInfo.create();
|
|
29
|
-
_info.name = this.constructor.name;
|
|
30
|
-
_info.stage = STAGE.PROCESS;
|
|
31
|
-
Object.freeze(_info);
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Initialize registry with provided sources.
|
|
35
|
-
*
|
|
36
|
-
* @param {{sources: Fl32_Web_Back_Dto_Handler_Source.Dto[]}} params
|
|
37
|
-
* @returns {Promise<void>}
|
|
38
|
-
*/
|
|
39
|
-
this.init = async ({sources = []} = {}) => {
|
|
40
|
-
registry.addConfigs(sources);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Attempt to handle incoming request.
|
|
45
|
-
*
|
|
46
|
-
* @param {module:http.IncomingMessage|module:http2.Http2ServerRequest} req
|
|
47
|
-
* @param {module:http.ServerResponse|module:http2.Http2ServerResponse} res
|
|
48
|
-
* @returns {Promise<boolean>} True if file served
|
|
49
|
-
*/
|
|
50
|
-
this.handle = async (req, res) => {
|
|
51
|
-
if (!respond.isWritable(res)) return false;
|
|
52
|
-
const urlPath = decodeURIComponent(req.url.split('?')[0]);
|
|
53
|
-
const match = registry.find(urlPath);
|
|
54
|
-
if (!match) return false;
|
|
55
|
-
return fileService.serve(match.config, match.rel, req, res);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @returns {Fl32_Web_Back_Dto_Handler_Info.Dto}
|
|
60
|
-
*/
|
|
61
|
-
this.getRegistrationInfo = () => _info;
|
|
62
|
-
}
|
|
63
|
-
}
|
package/src/Back/Helper/Cast.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
export default class Fl32_Web_Back_Helper_Cast {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Cast input data into an array. Ensures the result is always an array.
|
|
5
|
-
* Optionally casts each item using the provided itemCast function.
|
|
6
|
-
*
|
|
7
|
-
* @param {*} data - Input data to be cast to array.
|
|
8
|
-
* @param {function(*): *} [itemCast] - Optional function to cast each item.
|
|
9
|
-
* @returns {Array}
|
|
10
|
-
*/
|
|
11
|
-
array(data, itemCast) {
|
|
12
|
-
let arr = [];
|
|
13
|
-
|
|
14
|
-
if (Array.isArray(data)) {
|
|
15
|
-
arr = data;
|
|
16
|
-
} else if (data !== null) {
|
|
17
|
-
arr = [data];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return (typeof itemCast === 'function')
|
|
21
|
-
? arr.map(itemCast).filter(v => v !== undefined)
|
|
22
|
-
: arr;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Cast input data into decimal 'number' data type.
|
|
28
|
-
* @param {*} data
|
|
29
|
-
* @returns {number|undefined}
|
|
30
|
-
*/
|
|
31
|
-
decimal(data) {
|
|
32
|
-
const res = Number.parseFloat(data);
|
|
33
|
-
return ((typeof res === 'number') && (!isNaN(res))) ? res : undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Cast input data into a valid enumeration value.
|
|
38
|
-
* Supports case normalization (upper/lower).
|
|
39
|
-
* If both `upper` and `lower` are true, `upper` takes precedence.
|
|
40
|
-
*
|
|
41
|
-
* @param {*} data - The input to cast.
|
|
42
|
-
* @param {object} enu - Object whose values represent valid enum values.
|
|
43
|
-
* @param {object} [params] - Parameters object.
|
|
44
|
-
* @param {boolean} [params.lower] - Normalize input to lower case before comparison.
|
|
45
|
-
* @param {boolean} [params.upper] - Normalize input to upper case before comparison.
|
|
46
|
-
* @returns {string|undefined}
|
|
47
|
-
*/
|
|
48
|
-
enum(data, enu, {lower, upper} = {}) {
|
|
49
|
-
let norm = data;
|
|
50
|
-
|
|
51
|
-
if (typeof data === 'string') {
|
|
52
|
-
if (upper) norm = data.toUpperCase();
|
|
53
|
-
else if (lower) norm = data.toLowerCase();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const values = Object.values(enu);
|
|
57
|
-
return values.includes(norm) ? norm : undefined;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Cast input data into integer 'number' data type.
|
|
62
|
-
* @param {*} data - Input data to be cast to integer.
|
|
63
|
-
* @returns {number|undefined}
|
|
64
|
-
*/
|
|
65
|
-
int(data) {
|
|
66
|
-
const norm = (typeof data === 'string') ? data.trim() : data;
|
|
67
|
-
const res = Number.parseInt(norm);
|
|
68
|
-
return ((typeof res === 'number') && (!isNaN(res))) ? res : undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Cast input data into 'string' data type.
|
|
73
|
-
* @param {*} data - Input data to be cast to string.
|
|
74
|
-
* @returns {string|undefined}
|
|
75
|
-
*/
|
|
76
|
-
string(data) {
|
|
77
|
-
if (typeof data === 'string') {
|
|
78
|
-
return data;
|
|
79
|
-
} else if (typeof data === 'number') {
|
|
80
|
-
return String(data);
|
|
81
|
-
} else if (typeof data === 'boolean') {
|
|
82
|
-
return (data) ? 'true' : 'false';
|
|
83
|
-
}
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Cast an object to a map with string keys and array-of-string values.
|
|
89
|
-
* Throws error on invalid structure or values.
|
|
90
|
-
*
|
|
91
|
-
* @param {*} data - Raw input to cast.
|
|
92
|
-
* @returns {Record<string, string[]>}
|
|
93
|
-
*/
|
|
94
|
-
stringArrayMap(data) {
|
|
95
|
-
if (data === undefined) return {};
|
|
96
|
-
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
|
|
97
|
-
throw new Error('Invalid value for allow');
|
|
98
|
-
}
|
|
99
|
-
const res = {};
|
|
100
|
-
for (const [key, arr] of Object.entries(data)) {
|
|
101
|
-
if (!Array.isArray(arr)) throw new Error(`Invalid allow list for ${key}`);
|
|
102
|
-
const k = this.string(key);
|
|
103
|
-
if (!k) throw new Error('Invalid allow key');
|
|
104
|
-
const items = [];
|
|
105
|
-
for (const item of arr) {
|
|
106
|
-
const val = this.string(item);
|
|
107
|
-
if (!val) throw new Error(`Invalid allow list for ${k}`);
|
|
108
|
-
items.push(val);
|
|
109
|
-
}
|
|
110
|
-
res[k] = items;
|
|
111
|
-
}
|
|
112
|
-
return res;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sorts named handlers by relative `before` / `after` constraints using Kahn's algorithm.
|
|
3
|
-
*/
|
|
4
|
-
export default class Fl32_Web_Back_Helper_Order_Kahn {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Topologically sorts handlers with `name`, `before`, `after` fields.
|
|
8
|
-
*
|
|
9
|
-
* @param {Fl32_Web_Back_Api_Handler[]} handlers - Handlers to sort.
|
|
10
|
-
* @returns {Fl32_Web_Back_Api_Handler[]} - Sorted list.
|
|
11
|
-
* @throws {Error} - If circular dependency is detected.
|
|
12
|
-
*/
|
|
13
|
-
sort(handlers) {
|
|
14
|
-
const nameToHandler = new Map();
|
|
15
|
-
const graph = new Map(); // name => Set of downstream nodes
|
|
16
|
-
const inDegree = new Map(); // name => number of incoming edges
|
|
17
|
-
|
|
18
|
-
// Initialize maps
|
|
19
|
-
for (const h of handlers) {
|
|
20
|
-
const info = h.getRegistrationInfo();
|
|
21
|
-
const name = info.name;
|
|
22
|
-
nameToHandler.set(name, h);
|
|
23
|
-
graph.set(name, new Set());
|
|
24
|
-
inDegree.set(name, 0);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Build graph
|
|
28
|
-
for (const h of handlers) {
|
|
29
|
-
const {name, after = [], before = []} = h.getRegistrationInfo();
|
|
30
|
-
|
|
31
|
-
for (const dep of after) {
|
|
32
|
-
if (!graph.has(dep)) continue;
|
|
33
|
-
graph.get(dep).add(name);
|
|
34
|
-
inDegree.set(name, inDegree.get(name) + 1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
for (const dep of before) {
|
|
38
|
-
if (!graph.has(dep)) continue;
|
|
39
|
-
graph.get(name).add(dep);
|
|
40
|
-
inDegree.set(dep, inDegree.get(dep) + 1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Kahn's algorithm
|
|
45
|
-
const queue = [];
|
|
46
|
-
for (const [name, count] of inDegree.entries()) {
|
|
47
|
-
if (count === 0) queue.push(name);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const sorted = [];
|
|
51
|
-
while (queue.length > 0) {
|
|
52
|
-
const name = queue.shift();
|
|
53
|
-
sorted.push(nameToHandler.get(name));
|
|
54
|
-
for (const neighbor of graph.get(name)) {
|
|
55
|
-
inDegree.set(neighbor, inDegree.get(neighbor) - 1);
|
|
56
|
-
if (inDegree.get(neighbor) === 0) queue.push(neighbor);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (sorted.length !== handlers.length) {
|
|
61
|
-
throw new Error('Circular dependency detected among handlers');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return sorted;
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/Back/Logger.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple logger implementation that delegates to the native console.
|
|
3
|
-
*/
|
|
4
|
-
export default class Fl32_Web_Back_Logger {
|
|
5
|
-
/**
|
|
6
|
-
* Logs an error message.
|
|
7
|
-
* @param {...any} args - The error message or data.
|
|
8
|
-
*/
|
|
9
|
-
error(...args) {
|
|
10
|
-
console.error('[ERROR]', ...args);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Logs a warning message.
|
|
15
|
-
* @param {...any} args - The warning message or data.
|
|
16
|
-
*/
|
|
17
|
-
warn(...args) {
|
|
18
|
-
console.warn('[WARN]', ...args);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Logs an informational message.
|
|
23
|
-
* @param {...any} args - The informational message or data.
|
|
24
|
-
*/
|
|
25
|
-
info(...args) {
|
|
26
|
-
console.info('[INFO]', ...args);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Logs a debug message.
|
|
31
|
-
* @param {...any} args - The debug message or data.
|
|
32
|
-
*/
|
|
33
|
-
debug(...args) {
|
|
34
|
-
console.debug('[DEBUG]', ...args);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Logs a trace message.
|
|
39
|
-
* @param {...any} args - The trace message or data.
|
|
40
|
-
*/
|
|
41
|
-
trace(...args) {
|
|
42
|
-
console.trace('[TRACE]', ...args);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Logs an exception with optional additional context.
|
|
47
|
-
* @param {Error} exception - The exception to log.
|
|
48
|
-
* @param {...any} context - Additional context or metadata.
|
|
49
|
-
*/
|
|
50
|
-
exception(exception, ...context) {
|
|
51
|
-
console.error('[EXCEPTION]', exception.stack || exception.toString(), ...context);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Factory for TLS configuration DTO.
|
|
3
|
-
* Produces validated DTOs for HTTPS server configuration.
|
|
4
|
-
*/
|
|
5
|
-
export default class Fl32_Web_Back_Server_Config_Tls {
|
|
6
|
-
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
7
|
-
/**
|
|
8
|
-
* @param {Fl32_Web_Back_Helper_Cast} cast
|
|
9
|
-
*/
|
|
10
|
-
constructor(
|
|
11
|
-
{
|
|
12
|
-
Fl32_Web_Back_Helper_Cast$: cast,
|
|
13
|
-
}
|
|
14
|
-
) {
|
|
15
|
-
/* eslint-enable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
16
|
-
/**
|
|
17
|
-
* Create a validated DTO for TLS configuration.
|
|
18
|
-
*
|
|
19
|
-
* @param {*} [data] - Optional raw object.
|
|
20
|
-
* @returns {Dto}
|
|
21
|
-
*/
|
|
22
|
-
this.create = function (data) {
|
|
23
|
-
const res = Object.assign(new Dto(), data);
|
|
24
|
-
if (data) {
|
|
25
|
-
res.ca = cast.string(data?.ca);
|
|
26
|
-
res.cert = cast.string(data.cert);
|
|
27
|
-
res.key = cast.string(data.key);
|
|
28
|
-
}
|
|
29
|
-
return res;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @memberOf Fl32_Web_Back_Server_Config_Tls
|
|
36
|
-
*/
|
|
37
|
-
class Dto {
|
|
38
|
-
/**
|
|
39
|
-
* Trusted CA certificates in PEM format.
|
|
40
|
-
* @type {string|undefined}
|
|
41
|
-
*/
|
|
42
|
-
ca;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Certificate in PEM format.
|
|
46
|
-
* @type {string}
|
|
47
|
-
*/
|
|
48
|
-
cert;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Private key in PEM format.
|
|
52
|
-
* @type {string}
|
|
53
|
-
*/
|
|
54
|
-
key;
|
|
55
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Factory for server configuration DTO.
|
|
3
|
-
* Supports HTTP, HTTPS and HTTP2 server types with TLS configuration.
|
|
4
|
-
*/
|
|
5
|
-
export default class Fl32_Web_Back_Server_Config {
|
|
6
|
-
/* eslint-disable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
7
|
-
/**
|
|
8
|
-
* @param {Fl32_Web_Back_Helper_Cast} cast
|
|
9
|
-
* @param {typeof Fl32_Web_Back_Enum_Server_Type} SERVER_TYPE
|
|
10
|
-
* @param {Fl32_Web_Back_Server_Config_Tls} tlsFactory
|
|
11
|
-
*/
|
|
12
|
-
constructor(
|
|
13
|
-
{
|
|
14
|
-
Fl32_Web_Back_Helper_Cast$: cast,
|
|
15
|
-
Fl32_Web_Back_Enum_Server_Type$: SERVER_TYPE,
|
|
16
|
-
Fl32_Web_Back_Server_Config_Tls$: tlsFactory,
|
|
17
|
-
}
|
|
18
|
-
) {
|
|
19
|
-
/* eslint-enable jsdoc/require-param-description,jsdoc/check-param-names */
|
|
20
|
-
// INSTANCE METHODS
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new DTO instance with properly casted attributes.
|
|
23
|
-
* Ensures valid values for enums and numerical fields.
|
|
24
|
-
* Validates TLS configuration when type is HTTPS.
|
|
25
|
-
*
|
|
26
|
-
* @param {Fl32_Web_Back_Server_Config.Dto|object} [data] - Raw input data for the DTO.
|
|
27
|
-
* @returns {Dto} - A properly structured DTO instance.
|
|
28
|
-
* @throws {Error} When HTTPS type is specified without TLS configuration.
|
|
29
|
-
*/
|
|
30
|
-
this.create = function (data) {
|
|
31
|
-
const res = Object.assign(new Dto(), data);
|
|
32
|
-
if (data) {
|
|
33
|
-
res.port = cast.int(data.port);
|
|
34
|
-
res.type = cast.enum(data.type, SERVER_TYPE, {lower: true});
|
|
35
|
-
|
|
36
|
-
if (data.tls) {
|
|
37
|
-
res.tls = tlsFactory.create(data.tls);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (res.type === SERVER_TYPE.HTTPS && !res.tls) {
|
|
41
|
-
throw new Error('TLS configuration is required for HTTPS server type');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return res;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @memberOf Fl32_Web_Back_Server_Config
|
|
51
|
-
*/
|
|
52
|
-
class Dto {
|
|
53
|
-
/**
|
|
54
|
-
* Port to listening (3000).
|
|
55
|
-
*
|
|
56
|
-
* @type {number}
|
|
57
|
-
*/
|
|
58
|
-
port;
|
|
59
|
-
/**
|
|
60
|
-
* @type {string}
|
|
61
|
-
* @see Fl32_Web_Back_Enum_Server_Type
|
|
62
|
-
*/
|
|
63
|
-
type;
|
|
64
|
-
/**
|
|
65
|
-
* TLS configuration for HTTPS server.
|
|
66
|
-
* @type {Fl32_Web_Back_Server_Config_Tls.Dto|undefined}
|
|
67
|
-
*/
|
|
68
|
-
tls;
|
|
69
|
-
}
|