@rexeus/typeweaver 0.0.1
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 +145 -0
- package/dist/acorn-rXlN7gk4.js +2953 -0
- package/dist/angular-D_XFD5k4.js +2531 -0
- package/dist/babel-DZgCLJ3w.js +6956 -0
- package/dist/cli-Ci6HB8FI.js +23830 -0
- package/dist/estree-B92etQ3n.js +4318 -0
- package/dist/flow--vV0j3Y-.js +26826 -0
- package/dist/glimmer-B-ODUU1A.js +2661 -0
- package/dist/graphql-Cl6ZUrDI.js +1226 -0
- package/dist/html-D3ugDhTt.js +2637 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -0
- package/dist/markdown-BsYj_q7V.js +3322 -0
- package/dist/meriyah-DkEqawD_.js +2456 -0
- package/dist/postcss-DdgOJBTx.js +4922 -0
- package/dist/run-cli-with-tsx.js +18 -0
- package/dist/templates/Index.ejs +3 -0
- package/dist/typescript-C4gnKzhB.js +12888 -0
- package/dist/yaml-B0tq6Ttj.js +4156 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# @rexeus/typeweaver
|
|
2
|
+
|
|
3
|
+
CLI tool for generating type-safe API code from TypeWeaver definitions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @rexeus/typeweaver
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Generate TypeScript code from your API definitions:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx typeweaver generate --input ./api/definitions --output ./api/generated --plugins clients,aws-cdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Options
|
|
20
|
+
|
|
21
|
+
- `--input, -i <path>`: Input directory containing API definitions (required)
|
|
22
|
+
- `--output, -o <path>`: Output directory for generated code (required)
|
|
23
|
+
- `--config, -c <path>`: Configuration file path (optional)
|
|
24
|
+
- `--plugins, -p <plugins>`: Comma-separated list of plugins to use (e.g., "clients,aws-cdk")
|
|
25
|
+
- `--prettier / --no-prettier`: Enable/disable code formatting with Prettier (default: true)
|
|
26
|
+
- `--clean / --no-clean`: Enable/disable output directory cleaning (default: true)
|
|
27
|
+
|
|
28
|
+
### What Gets Generated
|
|
29
|
+
|
|
30
|
+
From your API definitions, TypeWeaver generates:
|
|
31
|
+
|
|
32
|
+
1. **Request Types & Commands** - Type-safe request interfaces and command classes
|
|
33
|
+
2. **Response Types** - Typed response interfaces for all status codes
|
|
34
|
+
3. **Validators** - Runtime validators for requests and responses using Zod
|
|
35
|
+
4. **API Clients** - Typed HTTP clients with automatic response validation
|
|
36
|
+
5. **Router Implementations** - HTTP API Gateway routers (with aws-cdk plugin)
|
|
37
|
+
6. **Shared Error Types** - Reusable error response types
|
|
38
|
+
|
|
39
|
+
### Project Structure
|
|
40
|
+
|
|
41
|
+
Your API definitions should follow this structure:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
api/definitions/
|
|
45
|
+
├── users/ # Entity directory
|
|
46
|
+
│ ├── GetUserDefinition.ts # Operation definition
|
|
47
|
+
│ ├── CreateUserDefinition.ts
|
|
48
|
+
│ └── userSchema.ts # Schemas for the entity
|
|
49
|
+
├── posts/
|
|
50
|
+
│ ├── GetPostDefinition.ts
|
|
51
|
+
│ └── CreatePostDefinition.ts
|
|
52
|
+
└── shared/ # Shared responses
|
|
53
|
+
├── NotFoundErrorDefinition.ts
|
|
54
|
+
├── ValidationErrorDefinition.ts
|
|
55
|
+
└── sharedResponses.ts
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Example Definition
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// api/definitions/users/GetUserDefinition.ts
|
|
62
|
+
import { HttpOperationDefinition, HttpMethod, HttpStatusCode } from "@rexeus/typeweaver-core";
|
|
63
|
+
import { z } from "zod/v4";
|
|
64
|
+
|
|
65
|
+
export default new HttpOperationDefinition({
|
|
66
|
+
operationId: "GetUser",
|
|
67
|
+
method: HttpMethod.GET,
|
|
68
|
+
path: "/users/:userId",
|
|
69
|
+
request: {
|
|
70
|
+
param: z.object({
|
|
71
|
+
userId: z.uuid(),
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
74
|
+
responses: [
|
|
75
|
+
{
|
|
76
|
+
statusCode: HttpStatusCode.OK,
|
|
77
|
+
body: z.object({
|
|
78
|
+
id: z.uuid(),
|
|
79
|
+
name: z.string(),
|
|
80
|
+
email: z.email(),
|
|
81
|
+
}),
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Plugin System
|
|
88
|
+
|
|
89
|
+
TypeWeaver supports a plugin-based architecture for extensible code generation. Available plugins:
|
|
90
|
+
|
|
91
|
+
- **types** (default): TypeScript types and Zod validators
|
|
92
|
+
- **clients**: HTTP API client generation
|
|
93
|
+
- **aws-cdk**: AWS CDK constructs and HTTP API Gateway routers
|
|
94
|
+
|
|
95
|
+
### Using Plugins
|
|
96
|
+
|
|
97
|
+
Via command line:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npx typeweaver generate --input ./api/definitions --output ./api/generated --plugins clients,aws-cdk
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Configuration File
|
|
104
|
+
|
|
105
|
+
Create a `typeweaver.config.js` file for more complex configurations:
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
export default {
|
|
109
|
+
input: "./api/definitions",
|
|
110
|
+
output: "./api/generated",
|
|
111
|
+
plugins: ["clients", "aws-cdk"],
|
|
112
|
+
prettier: true,
|
|
113
|
+
clean: true,
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Then run:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npx typeweaver generate --config ./typeweaver.config.js
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Generated Output
|
|
124
|
+
|
|
125
|
+
With the **clients** plugin, you'll get type-safe API clients:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { UsersClient } from "./api/generated";
|
|
129
|
+
|
|
130
|
+
const client = new UsersClient({ baseURL: "https://api.example.com" });
|
|
131
|
+
const result = await client.send(new GetUserRequestCommand({ param: { userId: "123" } }));
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
With the **aws-cdk** plugin, you'll get HTTP API Gateway routers:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { UsersHttpApiRouter } from "./api/generated";
|
|
138
|
+
|
|
139
|
+
const router = new UsersHttpApiRouter();
|
|
140
|
+
// Use in your AWS CDK stack
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
ISC © Dennis Wentzien 2025
|