@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.0] - 2026-03-13
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Added `ai/` documentation for agent-oriented project materials.
|
|
7
|
+
- Added a non-resettable request-context attribute.
|
|
8
|
+
- Added component type conventions to the cognitive context.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Updated `README.md` with package and agent-interface documentation refinements.
|
|
12
|
+
- Migrated dependency injection to `@teqfw/di` v2 and updated package metadata accordingly.
|
|
13
|
+
- Refined architecture and terminology around the dispatcher, request context, and transport boundary.
|
|
14
|
+
- Reworked source files to codex-generated module layout and aligned exported namespace style with the `$` convention.
|
|
15
|
+
- Verified modules in `src/` against updated TeqFW ES module conventions and aligned DTO component types with those rules.
|
|
16
|
+
- Restructured and cleaned up `ctx/docs`, including TeqFW convention documents and removal of the obsolete composition level.
|
|
17
|
+
- Moved the accept test into the integration test suite.
|
|
18
|
+
- Refreshed runtime and development dependencies.
|
|
19
|
+
|
|
20
|
+
### Removed
|
|
21
|
+
- Removed legacy code, tests, and the shared `common.mjs` unit-test helper.
|
|
22
|
+
|
|
3
23
|
## [0.4.0] - 2025-12-20
|
|
4
24
|
|
|
5
25
|
### Added
|
package/README.md
CHANGED
|
@@ -1,152 +1,240 @@
|
|
|
1
1
|
# @flancer32/teq-web
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
It follows the principles of the [TeqFW](https://github.com/flancer32/teqfw) architecture but works independently and
|
|
5
|
-
can be integrated into any Node.js project.
|
|
6
|
-
The plugin offers a flexible, pluggable HTTP/2-capable server with three-stage handler processing and dependency-driven
|
|
7
|
-
execution order.
|
|
3
|
+
Infrastructure web server and deterministic request pipeline for TeqFW packages.
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
`@flancer32/teq-web` is an infrastructural component of the **Tequila Framework (TeqFW)** platform.
|
|
6
|
+
|
|
7
|
+
The package provides a deterministic **request lifecycle pipeline** and a built-in **Node.js web server** that other TeqFW packages can use as the runtime environment for processing HTTP requests.
|
|
8
|
+
|
|
9
|
+
Within the TeqFW ecosystem, this package plays a role similar to how **Express** or **Fastify** are used in typical Node.js applications: it acts as the **web runtime layer** used by higher-level packages.
|
|
10
|
+
|
|
11
|
+
Unlike general-purpose web frameworks, this package focuses only on coordinating **request lifecycle execution through a deterministic handler pipeline**.
|
|
12
|
+
|
|
13
|
+
The package requires the dependency container **@teqfw/di**.
|
|
14
|
+
|
|
15
|
+
Platform website: <https://teqfw.com/>
|
|
10
16
|
|
|
11
17
|
## Overview
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
The package provides infrastructure for processing web requests inside a TeqFW application.
|
|
20
|
+
|
|
21
|
+
Core responsibilities:
|
|
22
|
+
|
|
23
|
+
- deterministic **request lifecycle coordination**
|
|
24
|
+
- ordered **handler execution pipeline**
|
|
25
|
+
- **Node.js server integration** (`http`, `http2`, `https`)
|
|
26
|
+
- **handler registration metadata**
|
|
27
|
+
- **static file handler**
|
|
28
|
+
- DTO factories and enums used by handler implementations
|
|
29
|
+
|
|
30
|
+
The package does **not** provide:
|
|
31
|
+
|
|
32
|
+
- routing frameworks
|
|
33
|
+
- controllers
|
|
34
|
+
- application architecture
|
|
35
|
+
- persistence
|
|
36
|
+
- session management
|
|
37
|
+
- business logic abstractions
|
|
38
|
+
|
|
39
|
+
Its sole responsibility is coordinating the **lifecycle of a web request**.
|
|
40
|
+
|
|
41
|
+
## Role in the TeqFW Ecosystem
|
|
42
|
+
|
|
43
|
+
| Layer | Responsibility |
|
|
44
|
+
| -------------------- | ----------------------------------------- |
|
|
45
|
+
| Application packages | business logic, handlers |
|
|
46
|
+
| `@flancer32/teq-web` | web server and request lifecycle pipeline |
|
|
47
|
+
| `@teqfw/di` | runtime dependency linking |
|
|
48
|
+
|
|
49
|
+
TeqFW applications are composed of multiple packages that declare dependencies through the DI container.
|
|
50
|
+
|
|
51
|
+
`@flancer32/teq-web` provides the **web runtime layer** in which those packages handle incoming requests.
|
|
52
|
+
|
|
53
|
+
## Request Lifecycle
|
|
54
|
+
|
|
55
|
+
Each request is processed through a fixed three-stage pipeline:
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
INIT → PROCESS → FINALIZE
|
|
59
|
+
```
|
|
14
60
|
|
|
15
|
-
|
|
16
|
-
- A **handler interface** for modular request handling across plugins or components.
|
|
17
|
-
- A **built-in server** based on Node.js libraries (`http`, `http2`), supporting TLS via `http2.createSecureServer()`.
|
|
18
|
-
- Support for **relative handler ordering** using `before` / `after` declarations and topological sorting.
|
|
19
|
-
- Compatibility with **external servers** like Express/Fastify by using the dispatcher as middleware.
|
|
20
|
-
- Minimal dependencies and full support for dependency injection via `@teqfw/di`.
|
|
61
|
+
Stage semantics:
|
|
21
62
|
|
|
22
|
-
|
|
63
|
+
| Stage | Purpose |
|
|
64
|
+
| -------- | ------------------------------------------------- |
|
|
65
|
+
| INIT | request preparation (logging, enrichment, guards) |
|
|
66
|
+
| PROCESS | request handling |
|
|
67
|
+
| FINALIZE | cleanup and post-processing |
|
|
23
68
|
|
|
24
|
-
|
|
69
|
+
Processing stops when a `PROCESS` handler marks the request as completed.
|
|
25
70
|
|
|
26
|
-
|
|
71
|
+
If no handler handles the request, the system produces **404 Not Found**.
|
|
27
72
|
|
|
28
|
-
|
|
29
|
-
2. **Processing (`process`)** — Handlers are checked sequentially until one returns `true` (request handled).
|
|
30
|
-
3. **Post-processing (`post`)** — All handlers are executed unconditionally, even after errors.
|
|
73
|
+
## Core Components
|
|
31
74
|
|
|
32
|
-
|
|
33
|
-
a built-in implementation of Kahn's algorithm.
|
|
75
|
+
### Pipeline Engine
|
|
34
76
|
|
|
35
|
-
|
|
77
|
+
The **Pipeline Engine** is the single lifecycle coordination authority.
|
|
36
78
|
|
|
37
|
-
|
|
38
|
-
const My_Handler = {
|
|
39
|
-
getRegistrationInfo: () => Object.freeze({
|
|
40
|
-
name: 'My_Handler',
|
|
41
|
-
stage: 'process', // can be 'pre', 'process', or 'post'
|
|
42
|
-
before: [],
|
|
43
|
-
after: [],
|
|
44
|
-
}),
|
|
79
|
+
Responsibilities:
|
|
45
80
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
81
|
+
- handler registration
|
|
82
|
+
- deterministic handler ordering
|
|
83
|
+
- request lifecycle execution
|
|
84
|
+
- request completion control
|
|
85
|
+
- runtime error handling
|
|
86
|
+
|
|
87
|
+
Handlers are ordered based on declarative metadata (`before` / `after` constraints).
|
|
88
|
+
|
|
89
|
+
### Server
|
|
90
|
+
|
|
91
|
+
The built-in server connects the Node.js transport layer to the request pipeline.
|
|
92
|
+
|
|
93
|
+
Supported server types:
|
|
94
|
+
|
|
95
|
+
- `http`
|
|
96
|
+
- `http2`
|
|
97
|
+
- `https`
|
|
98
|
+
|
|
99
|
+
The server locks the handler pipeline before entering the execution phase.
|
|
100
|
+
|
|
101
|
+
### Handlers
|
|
102
|
+
|
|
103
|
+
Handlers are independent modules participating in request processing.
|
|
104
|
+
|
|
105
|
+
Each handler provides registration metadata:
|
|
106
|
+
|
|
107
|
+
- unique handler name
|
|
108
|
+
- execution stage
|
|
109
|
+
- relative ordering constraints
|
|
110
|
+
|
|
111
|
+
Handlers do not coordinate with each other directly. Execution order is derived from metadata and is deterministic.
|
|
112
|
+
|
|
113
|
+
## Example (TeqFW Style)
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
// App/Web/Handler/Hello.mjs
|
|
117
|
+
|
|
118
|
+
export const __deps__ = {
|
|
119
|
+
dtoInfoFactory: "Fl32_Web_Back_Dto_Info__Factory$",
|
|
120
|
+
STAGE: "Fl32_Web_Back_Enum_Stage$",
|
|
51
121
|
};
|
|
52
122
|
|
|
53
|
-
export default
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
await
|
|
101
|
-
|
|
102
|
-
// Register handlers
|
|
103
|
-
const dispatcher = await container.get('Fl32_Web_Back_Dispatcher$');
|
|
104
|
-
dispatcher.addHandler(logHandler);
|
|
105
|
-
dispatcher.addHandler(staticHandler);
|
|
106
|
-
|
|
107
|
-
// Create and start the server
|
|
108
|
-
const server = await container.get('Fl32_Web_Back_Server$');
|
|
109
|
-
await server.start({
|
|
110
|
-
port: 3443,
|
|
111
|
-
type: 'https',
|
|
112
|
-
tls: {
|
|
113
|
-
key: readFileSync(join(certs, 'key.pem'), 'utf8'),
|
|
114
|
-
cert: readFileSync(join(certs, 'cert.pem'), 'utf8'),
|
|
115
|
-
ca: readFileSync(join(certs, 'ca.pem'), 'utf8'),
|
|
116
|
-
}
|
|
117
|
-
});
|
|
123
|
+
export default class App_Web_Handler_Hello {
|
|
124
|
+
constructor({ dtoInfoFactory, STAGE }) {
|
|
125
|
+
const info = dtoInfoFactory.create({
|
|
126
|
+
name: "App_Web_Handler_Hello",
|
|
127
|
+
stage: STAGE.PROCESS,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
this.getRegistrationInfo = () => info;
|
|
131
|
+
|
|
132
|
+
this.handle = async function (context) {
|
|
133
|
+
const { response } = context;
|
|
134
|
+
|
|
135
|
+
response.writeHead(200, { "Content-Type": "text/plain" });
|
|
136
|
+
response.end("ok");
|
|
137
|
+
|
|
138
|
+
context.complete();
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
// App/Web/Server/Start.mjs
|
|
146
|
+
|
|
147
|
+
export const __deps__ = {
|
|
148
|
+
pipeline: "Fl32_Web_Back_PipelineEngine$",
|
|
149
|
+
server: "Fl32_Web_Back_Server$",
|
|
150
|
+
helloHandler: "App_Web_Handler_Hello$",
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export default class App_Web_Server_Start {
|
|
154
|
+
constructor({ pipeline, server, helloHandler }) {
|
|
155
|
+
this.execute = async function () {
|
|
156
|
+
pipeline.addHandler(helloHandler);
|
|
157
|
+
|
|
158
|
+
await server.start({
|
|
159
|
+
port: 3000,
|
|
160
|
+
type: "http",
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Application entry point:
|
|
168
|
+
|
|
169
|
+
```javascript
|
|
170
|
+
const app = await container.get("App_Web_Server_Start$");
|
|
171
|
+
await app.execute();
|
|
118
172
|
```
|
|
119
173
|
|
|
120
|
-
|
|
174
|
+
## Designed for Development with LLM Agents
|
|
175
|
+
|
|
176
|
+
TeqFW is an architectural approach designed for software development in which **LLM agents participate directly in the development process**.
|
|
177
|
+
|
|
178
|
+
Traditional software architectures assume that all code is written and maintained by humans.
|
|
179
|
+
|
|
180
|
+
TeqFW assumes a different workflow:
|
|
181
|
+
|
|
182
|
+
- humans design the **architecture and specifications**
|
|
183
|
+
- LLM agents generate and maintain the **implementation**
|
|
184
|
+
|
|
185
|
+
To support this workflow, TeqFW structures applications so they are easier for automated agents to analyze and modify.
|
|
186
|
+
|
|
187
|
+
Key design principles include:
|
|
188
|
+
|
|
189
|
+
- explicit dependency contracts
|
|
190
|
+
- deterministic runtime linking
|
|
191
|
+
- predictable module structure
|
|
192
|
+
- namespace-based component addressing
|
|
193
|
+
- minimal hidden coupling between modules
|
|
194
|
+
|
|
195
|
+
This allows systems to be more reliably:
|
|
121
196
|
|
|
122
|
-
|
|
123
|
-
|
|
197
|
+
- analyzed
|
|
198
|
+
- generated
|
|
199
|
+
- refactored
|
|
200
|
+
- extended
|
|
124
201
|
|
|
125
|
-
|
|
202
|
+
by both **human developers and AI agents**.
|
|
126
203
|
|
|
127
|
-
|
|
204
|
+
## Agent-Driven Implementation
|
|
128
205
|
|
|
129
|
-
|
|
206
|
+
TeqFW libraries are developed using **Agent-Driven Software Management (ADSM)**, a methodology created by **Alex Gusev**.
|
|
130
207
|
|
|
131
|
-
|
|
132
|
-
// Express
|
|
133
|
-
const app = Express();
|
|
134
|
-
app.use(async (req, res) => {
|
|
135
|
-
await dispatcher.onEventRequest(req, res);
|
|
136
|
-
});
|
|
137
|
-
app.listen(3000);
|
|
208
|
+
The workflow is:
|
|
138
209
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
210
|
+
1. A human architect defines the **product model and specifications**
|
|
211
|
+
2. **LLM agents (Codex)** generate the implementation
|
|
212
|
+
3. The human architect reviews and integrates the generated code
|
|
213
|
+
|
|
214
|
+
This package is part of that experiment and demonstrates how **human-designed architecture can be implemented by AI agents**.
|
|
215
|
+
|
|
216
|
+
## Agent Interface
|
|
217
|
+
|
|
218
|
+
This package includes **agent interface documentation** intended for LLM agents that use the library as a dependency.
|
|
219
|
+
|
|
220
|
+
These documents are distributed inside the package in:
|
|
221
|
+
|
|
222
|
+
```text
|
|
223
|
+
./ai/
|
|
147
224
|
```
|
|
148
225
|
|
|
149
|
-
|
|
226
|
+
For a quick integration reference, see:
|
|
227
|
+
|
|
228
|
+
- `ai/examples/minimal-server.md`
|
|
229
|
+
|
|
230
|
+
They describe:
|
|
231
|
+
|
|
232
|
+
- runtime abstractions
|
|
233
|
+
- request lifecycle semantics
|
|
234
|
+
- handler contracts
|
|
235
|
+
- integration rules for TeqFW applications
|
|
236
|
+
|
|
237
|
+
Human developers typically read the README and source code, while **LLM agents can rely on the documentation in `./ai/`.**
|
|
150
238
|
|
|
151
239
|
## Installation
|
|
152
240
|
|
|
@@ -154,11 +242,32 @@ await fastify.listen({port: 3000});
|
|
|
154
242
|
npm install @flancer32/teq-web
|
|
155
243
|
```
|
|
156
244
|
|
|
157
|
-
|
|
245
|
+
The package requires a configured `@teqfw/di` container.
|
|
246
|
+
|
|
247
|
+
## Tequila Framework
|
|
248
|
+
|
|
249
|
+
`@flancer32/teq-web` is part of the **Tequila Framework (TeqFW)** ecosystem.
|
|
250
|
+
|
|
251
|
+
More information about the platform:
|
|
252
|
+
[https://teqfw.com/](https://teqfw.com/)
|
|
253
|
+
|
|
254
|
+
TeqFW is an experimental platform exploring how software architecture changes when **AI agents become active participants in the development process**.
|
|
255
|
+
|
|
256
|
+
Key architectural ideas include:
|
|
257
|
+
|
|
258
|
+
- modular monolith architecture
|
|
259
|
+
- runtime dependency linking
|
|
260
|
+
- namespace-based component addressing
|
|
261
|
+
- pure JavaScript without compilation
|
|
262
|
+
- system structures optimized for collaboration with LLM agents
|
|
263
|
+
|
|
264
|
+
## Author
|
|
265
|
+
|
|
266
|
+
**Alex Gusev**
|
|
158
267
|
|
|
159
|
-
|
|
268
|
+
Creator of:
|
|
160
269
|
|
|
161
|
-
|
|
270
|
+
- **Tequila Framework (TeqFW)**
|
|
271
|
+
- **ADSM (Agent-Driven Software Management)**
|
|
162
272
|
|
|
163
|
-
This
|
|
164
|
-
**3DP** method (Dialog-Driven Development Process) and evolves alongside actual use cases.
|
|
273
|
+
This project explores how software architecture evolves when **LLM agents become active participants in the development process**.
|
package/ai/AGENTS.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
Version: 20260311
|
|
4
|
+
|
|
5
|
+
## Package Purpose
|
|
6
|
+
|
|
7
|
+
This directory provides the Agent Interface of `@flancer32/teq-web`. It contains a compact usage-oriented projection of the package intended for LLM agents that consume the package as a dependency inside TeqFW applications.
|
|
8
|
+
|
|
9
|
+
The interface describes how external code should use the package and excludes repository organization, development workflow, testing strategy, and other internal project concerns.
|
|
10
|
+
|
|
11
|
+
## TeqFW Usage Model
|
|
12
|
+
|
|
13
|
+
`@flancer32/teq-web` is designed for TeqFW-style runtime composition with `@teqfw/di`.
|
|
14
|
+
|
|
15
|
+
Dependencies should be linked through Canonical Dependency Codes and constructor injection rather than through direct static imports between application modules. External code should treat the package as infrastructure resolved by the container:
|
|
16
|
+
|
|
17
|
+
- application modules declare dependencies through `__deps__`;
|
|
18
|
+
- the container resolves `Fl32_Web_*` identifiers at runtime;
|
|
19
|
+
- orchestration is performed inside DI-managed application services;
|
|
20
|
+
- handlers and server components are configured before the server enters execution phase.
|
|
21
|
+
|
|
22
|
+
## Reading Order
|
|
23
|
+
|
|
24
|
+
Agents should read the documents in this directory in the following order:
|
|
25
|
+
|
|
26
|
+
1. `AGENTS.md` — overview of the agent interface and navigation.
|
|
27
|
+
2. `overview.md` — package role, intended usage boundary, and main entry points.
|
|
28
|
+
3. `abstractions.md` — core runtime concepts and consumer-facing abstractions.
|
|
29
|
+
4. `rules.md` — mandatory usage constraints and invariants.
|
|
30
|
+
5. `examples/minimal-server.md` — minimal TeqFW-style orchestration example.
|
|
31
|
+
|
|
32
|
+
## Interface Scope
|
|
33
|
+
|
|
34
|
+
The documents in this directory define only the supported usage semantics relevant to package consumers. Behaviors not described here should be treated as undefined and should not be inferred from internal implementation details.
|
|
35
|
+
|
|
36
|
+
Internal helper modules and deep implementation paths are outside the preferred consumer interface unless a task explicitly requires them.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Core Abstractions
|
|
2
|
+
|
|
3
|
+
## Pipeline Engine
|
|
4
|
+
|
|
5
|
+
`Fl32_Web_Back_PipelineEngine$` is the single lifecycle coordinator. It owns handler registration, derives deterministic order from handler metadata, creates one request context per request, and executes handlers in this fixed order:
|
|
6
|
+
|
|
7
|
+
`INIT -> PROCESS -> FINALIZE`
|
|
8
|
+
|
|
9
|
+
Main methods:
|
|
10
|
+
|
|
11
|
+
- `addHandler(handler)` or `registerHandler(handler)` registers a handler before the pipeline is locked;
|
|
12
|
+
- `lockHandlers()` freezes handler order explicitly;
|
|
13
|
+
- `onEventRequest(req, res)` or `handleRequest(req, res)` executes one request lifecycle.
|
|
14
|
+
|
|
15
|
+
## Server
|
|
16
|
+
|
|
17
|
+
`Fl32_Web_Back_Server$` is the built-in transport adapter around Node.js `http` and `http2`. On `start(cfg)` it locks the pipeline, creates the server instance, binds request events to the Pipeline Engine, and starts listening.
|
|
18
|
+
|
|
19
|
+
Config is created with `Fl32_Web_Back_Server_Config$`. Supported transport modes come from `Fl32_Web_Back_Enum_Server_Type$`:
|
|
20
|
+
|
|
21
|
+
- `http`
|
|
22
|
+
- `http2`
|
|
23
|
+
- `https`
|
|
24
|
+
|
|
25
|
+
`https` requires TLS config.
|
|
26
|
+
|
|
27
|
+
## Handler Contract
|
|
28
|
+
|
|
29
|
+
Custom handlers implement `Fl32_Web_Back_Api_Handler`:
|
|
30
|
+
|
|
31
|
+
- `getRegistrationInfo()` returns handler metadata;
|
|
32
|
+
- `handle(context)` performs work for one request.
|
|
33
|
+
|
|
34
|
+
Handler metadata is created with `Fl32_Web_Back_Dto_Info__Factory$` and contains:
|
|
35
|
+
|
|
36
|
+
- `name`: unique handler name;
|
|
37
|
+
- `stage`: `INIT`, `PROCESS`, or `FINALIZE`;
|
|
38
|
+
- `before`: handler names that must run after this handler;
|
|
39
|
+
- `after`: handler names that must run before this handler.
|
|
40
|
+
|
|
41
|
+
Ordering is resolved once from this metadata and is deterministic within each stage.
|
|
42
|
+
|
|
43
|
+
## Request Context
|
|
44
|
+
|
|
45
|
+
The Pipeline Engine passes one request-scoped context to every handler. Its stable fields are:
|
|
46
|
+
|
|
47
|
+
- `request`: Node.js request object;
|
|
48
|
+
- `response`: Node.js response object;
|
|
49
|
+
- `data`: mutable per-request shared storage for handlers;
|
|
50
|
+
- `completed`: completion flag;
|
|
51
|
+
- `complete()`: marks request processing as completed;
|
|
52
|
+
- `isCompleted()`: reads the completion state.
|
|
53
|
+
|
|
54
|
+
Handlers may mutate `data` and may read the rest of the context. They must not replace the context object.
|
|
55
|
+
|
|
56
|
+
## Stage Semantics
|
|
57
|
+
|
|
58
|
+
- `INIT`: always runs first; use for setup, logging, request enrichment, or guard preparation.
|
|
59
|
+
- `PROCESS`: runs until completion is marked; use for actual request handling.
|
|
60
|
+
- `FINALIZE`: always runs last; use for cleanup and post-processing.
|
|
61
|
+
|
|
62
|
+
Only `PROCESS` handlers may mark the request as completed.
|
|
63
|
+
|
|
64
|
+
## Built-in Static Handler
|
|
65
|
+
|
|
66
|
+
`Fl32_Web_Back_Handler_Static$` is a PROCESS-stage handler for static file delivery. Before use, call `init({sources})` with source DTOs created by `Fl32_Web_Back_Dto_Source$Factory`.
|
|
67
|
+
|
|
68
|
+
Each source describes:
|
|
69
|
+
|
|
70
|
+
- `root`: filesystem root;
|
|
71
|
+
- `prefix`: URL prefix matched by the handler;
|
|
72
|
+
- `allow`: optional allowlist map for paths under the source;
|
|
73
|
+
- `defaults`: optional fallback filenames for directory requests.
|
|
74
|
+
|
|
75
|
+
If the static handler serves a file successfully, it marks the request as completed.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Minimal Server Example
|
|
2
|
+
|
|
3
|
+
This example shows the preferred TeqFW-style usage path: external code resolves one application service from the container, and that service receives web infrastructure through constructor injection.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
// App/Web/Handler/Hello.mjs
|
|
7
|
+
// @ts-check
|
|
8
|
+
|
|
9
|
+
export const __deps__ = {
|
|
10
|
+
dtoInfoFactory: 'Fl32_Web_Back_Dto_Info__Factory$',
|
|
11
|
+
STAGE: 'Fl32_Web_Back_Enum_Stage$',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default class App_Web_Handler_Hello {
|
|
15
|
+
/**
|
|
16
|
+
* @param {{
|
|
17
|
+
* dtoInfoFactory: Fl32_Web_Back_Dto_Info$Factory,
|
|
18
|
+
* STAGE: Fl32_Web_Back_Enum_Stage,
|
|
19
|
+
* }} deps
|
|
20
|
+
*/
|
|
21
|
+
constructor({dtoInfoFactory, STAGE}) {
|
|
22
|
+
const info = dtoInfoFactory.create({
|
|
23
|
+
name: 'App_Web_Handler_Hello',
|
|
24
|
+
stage: STAGE.PROCESS,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
this.getRegistrationInfo = () => info;
|
|
28
|
+
|
|
29
|
+
this.handle = async function (context) {
|
|
30
|
+
const {response} = context;
|
|
31
|
+
response.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8'});
|
|
32
|
+
response.end('ok');
|
|
33
|
+
context.complete();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// App/Web/Server/Start.mjs
|
|
41
|
+
// @ts-check
|
|
42
|
+
|
|
43
|
+
export const __deps__ = {
|
|
44
|
+
pipeline: 'Fl32_Web_Back_PipelineEngine$',
|
|
45
|
+
server: 'Fl32_Web_Back_Server$',
|
|
46
|
+
helloHandler: 'App_Web_Handler_Hello$',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default class App_Web_Server_Start {
|
|
50
|
+
/**
|
|
51
|
+
* @param {{
|
|
52
|
+
* pipeline: Fl32_Web_Back_PipelineEngine,
|
|
53
|
+
* server: Fl32_Web_Back_Server,
|
|
54
|
+
* helloHandler: App_Web_Handler_Hello,
|
|
55
|
+
* }} deps
|
|
56
|
+
*/
|
|
57
|
+
constructor({pipeline, server, helloHandler}) {
|
|
58
|
+
this.execute = async function () {
|
|
59
|
+
pipeline.addHandler(helloHandler);
|
|
60
|
+
await server.start({port: 3000, type: 'http'});
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
// composition root
|
|
68
|
+
const app = await container.get('App_Web_Server_Start$');
|
|
69
|
+
await app.execute();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Consumer notes:
|
|
73
|
+
|
|
74
|
+
- The composition root configures namespace roots once and resolves one application entry service.
|
|
75
|
+
- Application modules do not construct collaborators directly and do not call `new` for DI-managed handlers or infrastructure services.
|
|
76
|
+
- `server.start()` locks handler registration for the runtime lifetime of that server instance.
|
|
77
|
+
- If your application already has its own transport layer, inject `Fl32_Web_Back_PipelineEngine$` and call `pipeline.onEventRequest(req, res)` from that adapter instead of using `Fl32_Web_Back_Server$`.
|
|
78
|
+
- A correct PROCESS handler ends the response and then marks the context completed.
|
package/ai/overview.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Package Overview
|
|
2
|
+
|
|
3
|
+
`@flancer32/teq-web` is server-side request coordination infrastructure for TeqFW applications. It provides a deterministic handler pipeline for web requests and a built-in Node.js server that feeds requests into that pipeline.
|
|
4
|
+
|
|
5
|
+
This package is not a general-purpose web framework. It does not define routing, controllers, domain models, persistence, session handling, or application structure. Its role is limited to coordinating one request lifecycle inside a TeqFW modular monolith.
|
|
6
|
+
|
|
7
|
+
The package assumes `@teqfw/di` and exposes its runtime surface through DI-managed modules under the `Fl32_Web_` namespace rooted at the published `src/` tree. In normal usage, application modules receive these dependencies through constructor injection and orchestrate them from DI-managed services rather than creating containers or wiring collaborators manually inside feature code.
|
|
8
|
+
|
|
9
|
+
Use this package when external code needs one of these roles:
|
|
10
|
+
|
|
11
|
+
- accept HTTP, HTTPS, or HTTP/2 requests with the built-in server;
|
|
12
|
+
- run request handlers through a fixed three-stage lifecycle;
|
|
13
|
+
- register multiple independent handlers with deterministic ordering;
|
|
14
|
+
- serve static files through the built-in PROCESS-stage handler.
|
|
15
|
+
|
|
16
|
+
Do not use this package as:
|
|
17
|
+
|
|
18
|
+
- a manually wired standalone web platform outside TeqFW DI;
|
|
19
|
+
- a replacement for an application router or MVC framework;
|
|
20
|
+
- a browser, CLI, or serverless runtime component.
|
|
21
|
+
|
|
22
|
+
The main consumer entry points are:
|
|
23
|
+
|
|
24
|
+
- `Fl32_Web_Back_PipelineEngine$` for request lifecycle coordination;
|
|
25
|
+
- `Fl32_Web_Back_Server$` for the built-in Node.js server;
|
|
26
|
+
- `Fl32_Web_Back_Api_Handler` plus `Fl32_Web_Back_Dto_Info__Factory$` and `Fl32_Web_Back_Dto_Info` for custom handlers;
|
|
27
|
+
- `Fl32_Web_Back_Handler_Static$` plus `Fl32_Web_Back_Dto_Source` values for static file serving.
|