@flancer32/teq-web 0.4.0 → 0.5.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 +20 -0
- package/README.md +236 -127
- package/ai/AGENTS.md +36 -0
- package/ai/abstractions.md +75 -0
- package/ai/examples/minimal-server.md +78 -0
- package/ai/overview.md +27 -0
- package/ai/rules.md +41 -0
- package/package.json +43 -37
- package/src/Back/Api/Handler.mjs +26 -0
- package/src/Back/{Defaults.js → Defaults.mjs} +6 -1
- package/src/Back/Dto/Info.mjs +66 -0
- package/src/Back/Dto/{Handler/Source.js → Source.mjs} +26 -23
- package/src/Back/Enum/Server/Type.mjs +13 -0
- package/src/Back/Enum/Stage.mjs +13 -0
- package/src/Back/Handler/Pre/Log.mjs +59 -0
- package/src/Back/Handler/Static/A/{Config.js → Config.mjs} +14 -3
- package/src/Back/Handler/Static/A/{Fallback.js → Fallback.mjs} +16 -4
- package/src/Back/Handler/Static/A/{FileService.js → FileService.mjs} +31 -14
- package/src/Back/Handler/Static/A/{Registry.js → Registry.mjs} +18 -6
- package/src/Back/Handler/Static/A/{Resolver.js → Resolver.mjs} +13 -2
- package/src/Back/Handler/Static.mjs +83 -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 -3
- package/src/Back/Logger.mjs +57 -0
- package/src/Back/PipelineEngine.mjs +228 -0
- package/src/Back/Server/Config/{Tls.js → Tls.mjs} +35 -33
- package/src/Back/Server/Config.mjs +69 -0
- package/src/Back/{Server.js → Server.mjs} +35 -24
- package/types.d.ts +27 -22
- package/src/AGENTS.md +0 -108
- package/src/Back/Api/Handler.js +0 -26
- 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.js +0 -69
- package/teqfw.json +0 -8
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,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
|
-
}
|