typespec-fastify 0.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/README.md +105 -0
- package/index.js +1 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# TypeSpec Fastify Emitter
|
|
2
|
+
|
|
3
|
+
Generates Fastify server code from TypeSpec HTTP service definitions using the Alloy Framework.
|
|
4
|
+
|
|
5
|
+
> [!IMPORTANT]
|
|
6
|
+
> This project is in early development and not production-ready. Expect breaking changes and missing features.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install --save-dev typespec-fastify
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- Route handlers generated from TypeSpec operations
|
|
17
|
+
- TypeScript operation interfaces for business logic
|
|
18
|
+
- Automatic parameter extraction (path, query, headers, body)
|
|
19
|
+
- Type-safe code generation
|
|
20
|
+
- User-controlled server lifecycle
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### 1. Configure TypeSpec
|
|
25
|
+
|
|
26
|
+
Create `tspconfig.yaml`:
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
emit:
|
|
30
|
+
- "typespec-fastify"
|
|
31
|
+
options:
|
|
32
|
+
"typespec-fastify":
|
|
33
|
+
"output-dir": "{project-root}/src/generated"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Define Service
|
|
37
|
+
|
|
38
|
+
Create `main.tsp`:
|
|
39
|
+
|
|
40
|
+
```typespec
|
|
41
|
+
import "@typespec/http";
|
|
42
|
+
using TypeSpec.Http;
|
|
43
|
+
|
|
44
|
+
@service
|
|
45
|
+
namespace PetStore;
|
|
46
|
+
|
|
47
|
+
model Pet {
|
|
48
|
+
id: int32;
|
|
49
|
+
name: string;
|
|
50
|
+
age: int32;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@route("/pets")
|
|
54
|
+
interface Pets {
|
|
55
|
+
@get list(@query limit?: int32): Pet[];
|
|
56
|
+
@get get(@path petId: int32): Pet;
|
|
57
|
+
@post create(@body pet: Pet): Pet;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. Compile
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npx tsp compile .
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 4. Implement
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import fastify from "fastify";
|
|
71
|
+
import { registerRoutes } from "./generated/router.js";
|
|
72
|
+
import type { Pets } from "./generated/operations/pets.js";
|
|
73
|
+
|
|
74
|
+
const petsOperations: Pets = {
|
|
75
|
+
async list(options) {
|
|
76
|
+
return [{ id: 1, name: "Fluffy", age: 3 }];
|
|
77
|
+
},
|
|
78
|
+
async get(petId) {
|
|
79
|
+
return { id: petId, name: "Fluffy", age: 3 };
|
|
80
|
+
},
|
|
81
|
+
async create(body) {
|
|
82
|
+
return { ...body, id: 123 };
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const server = fastify({ logger: true });
|
|
87
|
+
await registerRoutes(server, { pets: petsOperations });
|
|
88
|
+
await server.listen({ port: 3000 });
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Architecture
|
|
92
|
+
|
|
93
|
+
**Built with:**
|
|
94
|
+
|
|
95
|
+
- Alloy Framework (JSX-based code generation)
|
|
96
|
+
- TypeSpec HTTP (service definitions)
|
|
97
|
+
- TypeSpec Emitter Framework (compiler integration)
|
|
98
|
+
|
|
99
|
+
## Contributing
|
|
100
|
+
|
|
101
|
+
Contributions welcome.
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const placeholder = true;
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "typespec-fastify",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "TypeSpec emitter for Fastify server code generation",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+ssh://git@github.com/JordanHood/typespec-fastify.git"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"README.md",
|
|
13
|
+
"index.js"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"typespec",
|
|
17
|
+
"fastify",
|
|
18
|
+
"emitter",
|
|
19
|
+
"codegen"
|
|
20
|
+
],
|
|
21
|
+
"author": "Jordan Hood",
|
|
22
|
+
"license": "MIT"
|
|
23
|
+
}
|