@tsonic/express 10.0.22 → 10.0.24
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/README.md +12 -2
- package/docs/advanced.md +109 -0
- package/docs/deviations.md +20 -0
- package/docs/generation.md +47 -0
- package/docs/release.md +37 -0
- package/docs/snippets/10/body-parsing.ts +5 -0
- package/docs/snippets/10/create-app-router.ts +3 -0
- package/docs/snippets/10/error-middleware.ts +3 -0
- package/docs/snippets/10/hello-world-app.ts +12 -0
- package/docs/snippets/10/listen-close.ts +3 -0
- package/docs/snippets/10/middleware.ts +5 -0
- package/docs/snippets/10/quick-start-app.ts +12 -0
- package/docs/snippets/10/routing.ts +7 -0
- package/docs/snippets/10/static-files.ts +2 -0
- package/index/bindings.json +322 -502
- package/index/internal/index.d.ts +5 -14
- package/package.json +1 -1
- package/tsonic.bindings.json +1 -1
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ export function main(): void {
|
|
|
33
33
|
|
|
34
34
|
app.listen(3000);
|
|
35
35
|
}
|
|
36
|
+
|
|
36
37
|
EOF
|
|
37
38
|
|
|
38
39
|
npm run dev
|
|
@@ -55,6 +56,7 @@ export function main(): void {
|
|
|
55
56
|
|
|
56
57
|
app.listen(3000);
|
|
57
58
|
}
|
|
59
|
+
|
|
58
60
|
```
|
|
59
61
|
|
|
60
62
|
## Basic API Surface
|
|
@@ -66,6 +68,7 @@ import { express } from "@tsonic/express/index.js";
|
|
|
66
68
|
|
|
67
69
|
const app = express.create();
|
|
68
70
|
const router = express.Router();
|
|
71
|
+
|
|
69
72
|
```
|
|
70
73
|
|
|
71
74
|
### Routing
|
|
@@ -75,10 +78,11 @@ Common verbs:
|
|
|
75
78
|
```ts
|
|
76
79
|
app.get("/health", (_req, res) => res.send("ok"));
|
|
77
80
|
app.post("/items", (req, res) => res.json(req.body));
|
|
78
|
-
app.put("/items/:id", (req, res) => res.send(req.
|
|
81
|
+
app.put("/items/:id", (req, res) => res.send(req.param("id")));
|
|
79
82
|
app.delete("/items/:id", (_req, res) => res.sendStatus(204));
|
|
80
83
|
app.patch("/items/:id", (_req, res) => res.sendStatus(204));
|
|
81
84
|
app.all("/anything", (_req, res) => res.send("matched"));
|
|
85
|
+
|
|
82
86
|
```
|
|
83
87
|
|
|
84
88
|
### Middleware
|
|
@@ -88,12 +92,13 @@ app.use((req, _res, next) => {
|
|
|
88
92
|
// Do something with req
|
|
89
93
|
next();
|
|
90
94
|
});
|
|
95
|
+
|
|
91
96
|
```
|
|
92
97
|
|
|
93
98
|
Error middleware:
|
|
94
99
|
|
|
95
100
|
```ts
|
|
96
|
-
app.
|
|
101
|
+
app.useError((err, _req, res, _next) => {
|
|
97
102
|
res.status(500).json({ error: `${err}` });
|
|
98
103
|
});
|
|
99
104
|
```
|
|
@@ -122,12 +127,14 @@ app.use(express.json());
|
|
|
122
127
|
app.use(express.urlencoded());
|
|
123
128
|
app.use(express.text());
|
|
124
129
|
app.use(express.raw());
|
|
130
|
+
|
|
125
131
|
```
|
|
126
132
|
|
|
127
133
|
### Static files
|
|
128
134
|
|
|
129
135
|
```ts
|
|
130
136
|
app.use(express.static("./public"));
|
|
137
|
+
|
|
131
138
|
```
|
|
132
139
|
|
|
133
140
|
### Listen / close
|
|
@@ -135,6 +142,7 @@ app.use(express.static("./public"));
|
|
|
135
142
|
```ts
|
|
136
143
|
const server = app.listen(3000);
|
|
137
144
|
server.close();
|
|
145
|
+
|
|
138
146
|
```
|
|
139
147
|
|
|
140
148
|
## Advanced docs
|
|
@@ -152,3 +160,5 @@ This repo is versioned by runtime major:
|
|
|
152
160
|
## License
|
|
153
161
|
|
|
154
162
|
MIT
|
|
163
|
+
|
|
164
|
+
|
package/docs/advanced.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Advanced usage (`@tsonic/express`)
|
|
2
|
+
|
|
3
|
+
This doc covers patterns that go beyond “hello world”.
|
|
4
|
+
|
|
5
|
+
For known compatibility gaps vs Express/Node, see `docs/deviations.md`.
|
|
6
|
+
|
|
7
|
+
## Routers
|
|
8
|
+
|
|
9
|
+
Use routers to structure your app:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { express } from "@tsonic/express/index.js";
|
|
13
|
+
|
|
14
|
+
export function main(): void {
|
|
15
|
+
const app = express.create();
|
|
16
|
+
|
|
17
|
+
const api = express.Router();
|
|
18
|
+
api.get("/health", (_req, res) => res.send("ok"));
|
|
19
|
+
|
|
20
|
+
app.use("/api", api);
|
|
21
|
+
app.listen(3000);
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Middleware ordering
|
|
26
|
+
|
|
27
|
+
Middlewares run in the order you register them:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
app.use((req, _res, next) => {
|
|
31
|
+
// pre
|
|
32
|
+
next();
|
|
33
|
+
// post
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Error middleware
|
|
38
|
+
|
|
39
|
+
Error handlers have `(err, req, res, next)` shape:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
app.useError((err, _req, res, _next) => {
|
|
43
|
+
res.status(500).json({ error: `${err}` });
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Handler return types (sync vs async)
|
|
48
|
+
|
|
49
|
+
Handlers can be synchronous:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
app.get("/", (_req, res) => {
|
|
53
|
+
res.send("ok");
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Or `async`:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
app.get("/slow", async (_req, res) => {
|
|
61
|
+
// await something
|
|
62
|
+
res.send("done");
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Body parsing options
|
|
67
|
+
|
|
68
|
+
The built-in body parsers return request handlers:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
app.use(express.json());
|
|
72
|
+
app.use(express.urlencoded());
|
|
73
|
+
app.use(express.text());
|
|
74
|
+
app.use(express.raw());
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Most options types are exported from `@tsonic/express/index.js`:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { express, JsonOptions } from "@tsonic/express/index.js";
|
|
81
|
+
|
|
82
|
+
const json = new JsonOptions();
|
|
83
|
+
// set options here
|
|
84
|
+
app.use(express.json(json));
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Static files
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
app.use(express.static("./public"));
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Response helpers
|
|
94
|
+
|
|
95
|
+
Common response patterns:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
res.status(200).json({ ok: true });
|
|
99
|
+
res.sendStatus(204);
|
|
100
|
+
res.redirect("/login");
|
|
101
|
+
res.set("x-powered-by", "tsonic");
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Cookies
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
res.cookie("sid", "abc123");
|
|
108
|
+
res.clearCookie("sid");
|
|
109
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Express Compatibility Deviations
|
|
2
|
+
|
|
3
|
+
This package reflects the `express-clr` runtime behavior.
|
|
4
|
+
|
|
5
|
+
Authoritative deviations live in:
|
|
6
|
+
|
|
7
|
+
- `../express-clr/docs/deviations.md`
|
|
8
|
+
|
|
9
|
+
Key current items:
|
|
10
|
+
|
|
11
|
+
1. `express()` callable form is represented as `express.create()` / `express.app()`.
|
|
12
|
+
2. C#-safe method names are used for some verbs (`lock_`, `m_search`), with `method("...")` for exact-verb routing.
|
|
13
|
+
3. `next('router')` remains best-effort under flattened mount behavior.
|
|
14
|
+
4. Advanced path-pattern behavior is best-effort; common string and `:param` patterns are covered.
|
|
15
|
+
5. Built-in parser/static middleware behavior is close, not byte-for-byte identical to upstream Node middleware internals.
|
|
16
|
+
6. Cookie signing/signed-cookie behavior is best-effort, not a full `cookie-parser` edge-case clone.
|
|
17
|
+
7. Handler dispatch in runtime is reflection-free; unsupported delegate signatures are ignored instead of reflection invocation.
|
|
18
|
+
8. Runtime JSON support is reflection-free and guarantees primitives, dictionaries, arrays/lists, and `JsonElement`/`JsonDocument` shapes. Arbitrary CLR object/anonymous-object reflection serialization is intentionally not provided.
|
|
19
|
+
|
|
20
|
+
Deviations should shrink over time and are validated through the runtime test matrix in `express-clr`.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Generation Workflow
|
|
2
|
+
|
|
3
|
+
This repository publishes generated TypeScript bindings for `express-clr`.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- `../express-clr` exists and is built in `Release`.
|
|
8
|
+
- `../tsbindgen` exists and builds.
|
|
9
|
+
- `../dotnet/versions/<major>` exists.
|
|
10
|
+
- `../aspnetcore` exists.
|
|
11
|
+
- Local .NET runtime and ASP.NET runtime are installed under `$DOTNET_HOME` (default `$HOME/.dotnet`).
|
|
12
|
+
|
|
13
|
+
## Generate for .NET 10
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm run generate:10
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Equivalent script:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
./__build/scripts/generate.sh 10
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## What the Script Does
|
|
26
|
+
|
|
27
|
+
1. Validates dependencies and runtime paths.
|
|
28
|
+
2. Cleans `versions/<major>/` generated output.
|
|
29
|
+
3. Builds `tsbindgen` in `Release`.
|
|
30
|
+
4. Generates bindings from `express-clr` assembly.
|
|
31
|
+
5. Copies `README.md` and `LICENSE`.
|
|
32
|
+
6. Prunes output to package-focused files:
|
|
33
|
+
- `index.d.ts`
|
|
34
|
+
- `index.js`
|
|
35
|
+
- `index/bindings.json`
|
|
36
|
+
- `index/internal/index.d.ts`
|
|
37
|
+
- `families.json`
|
|
38
|
+
- `package.json`
|
|
39
|
+
- `README.md`
|
|
40
|
+
- `LICENSE`
|
|
41
|
+
|
|
42
|
+
## Environment Overrides
|
|
43
|
+
|
|
44
|
+
- `DOTNET_HOME`
|
|
45
|
+
- `DOTNET_VERSION`
|
|
46
|
+
|
|
47
|
+
Use these when runtime paths are non-default.
|
package/docs/release.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Release Workflow
|
|
2
|
+
|
|
3
|
+
This repo publishes one package per .NET major under `versions/<major>/`.
|
|
4
|
+
|
|
5
|
+
## .NET 10 Release Steps
|
|
6
|
+
|
|
7
|
+
1. Ensure `express-clr` changes are merged and pulled to `main`.
|
|
8
|
+
2. Regenerate bindings:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm run generate:10
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
3. Review generated diffs in `versions/10/`.
|
|
15
|
+
4. Update `versions/10/package.json` version if needed.
|
|
16
|
+
5. Validate package metadata and README.
|
|
17
|
+
6. Publish:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm run publish:10
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Post-Publish Checks
|
|
24
|
+
|
|
25
|
+
- Confirm npm package page for `@tsonic/express`.
|
|
26
|
+
- Verify install from a clean sample:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm i @tsonic/express@10
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- Smoke-check import and basic usage.
|
|
33
|
+
|
|
34
|
+
## Notes
|
|
35
|
+
|
|
36
|
+
- Runtime behavior changes belong to `express-clr`.
|
|
37
|
+
- This repo should only contain generated API/package-facing artifacts and docs.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
app.get("/health", (_req, res) => res.send("ok"));
|
|
2
|
+
app.post("/items", (req, res) => res.json(req.body));
|
|
3
|
+
app.put("/items/:id", (req, res) => res.send(req.param("id")));
|
|
4
|
+
app.delete("/items/:id", (_req, res) => res.sendStatus(204));
|
|
5
|
+
app.patch("/items/:id", (_req, res) => res.sendStatus(204));
|
|
6
|
+
app.all("/anything", (_req, res) => res.send("matched"));
|
|
7
|
+
|