@reactive-contracts/compiler 0.1.0-beta → 0.1.1-beta
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 +185 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# @reactive-contracts/compiler
|
|
2
|
+
|
|
3
|
+
Build-time compiler and CLI for Reactive Contracts - generates type-safe code from your contract definitions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @reactive-contracts/compiler
|
|
9
|
+
# or
|
|
10
|
+
yarn add @reactive-contracts/compiler
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @reactive-contracts/compiler
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## CLI Usage
|
|
16
|
+
|
|
17
|
+
The compiler provides a CLI tool called `rcontracts`:
|
|
18
|
+
|
|
19
|
+
### Initialize a Project
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx rcontracts init
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This creates:
|
|
26
|
+
- `rcontracts.config.ts` - Configuration file
|
|
27
|
+
- `contracts/` - Directory for your contract definitions
|
|
28
|
+
- `contracts/sample.contract.ts` - Example contract
|
|
29
|
+
|
|
30
|
+
### Compile Contracts
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx rcontracts compile
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Compiles all contracts and generates:
|
|
37
|
+
- **Frontend code** - Type-safe hooks and client utilities
|
|
38
|
+
- **Backend code** - Resolver stubs and type definitions
|
|
39
|
+
- **Runtime utilities** - Shared validation and types
|
|
40
|
+
|
|
41
|
+
### Validate Contracts
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx rcontracts validate
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Validates all contracts without generating code. Useful for CI pipelines.
|
|
48
|
+
|
|
49
|
+
### Diagnose a Contract
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx rcontracts diagnose UserProfile
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Shows detailed analysis for a specific contract including:
|
|
56
|
+
- Shape analysis
|
|
57
|
+
- Constraint validation
|
|
58
|
+
- Reactivity configuration
|
|
59
|
+
- Potential issues
|
|
60
|
+
|
|
61
|
+
### Show Changes
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npx rcontracts diff
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Shows changes since last compile.
|
|
68
|
+
|
|
69
|
+
### Run Migrations
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx rcontracts migrate
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Runs contract migrations for version updates.
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
Create a `rcontracts.config.ts` in your project root:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { defineConfig } from '@reactive-contracts/compiler';
|
|
83
|
+
|
|
84
|
+
export default defineConfig({
|
|
85
|
+
// Directory containing your .contract.ts files
|
|
86
|
+
contractsDir: './contracts',
|
|
87
|
+
|
|
88
|
+
// Output directory for generated code
|
|
89
|
+
outputDir: './generated',
|
|
90
|
+
|
|
91
|
+
// Generate frontend code (React hooks, etc.)
|
|
92
|
+
generateFrontend: true,
|
|
93
|
+
|
|
94
|
+
// Generate backend code (resolvers, etc.)
|
|
95
|
+
generateBackend: true,
|
|
96
|
+
|
|
97
|
+
// Enable strict validation
|
|
98
|
+
strict: true,
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Programmatic API
|
|
103
|
+
|
|
104
|
+
You can also use the compiler programmatically:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { compile, validate } from '@reactive-contracts/compiler';
|
|
108
|
+
|
|
109
|
+
// Compile contracts
|
|
110
|
+
await compile({
|
|
111
|
+
contractsDir: './contracts',
|
|
112
|
+
outputDir: './generated',
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Validate only
|
|
116
|
+
const result = await validate({
|
|
117
|
+
contractsDir: './contracts',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (!result.valid) {
|
|
121
|
+
console.error('Validation errors:', result.errors);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Generated Code Structure
|
|
126
|
+
|
|
127
|
+
After running `rcontracts compile`, the output directory will contain:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
generated/
|
|
131
|
+
├── frontend/
|
|
132
|
+
│ ├── UserProfile.ts # React hooks and client code
|
|
133
|
+
│ └── ...
|
|
134
|
+
├── backend/
|
|
135
|
+
│ ├── UserProfile.resolver.ts # Resolver stubs
|
|
136
|
+
│ └── ...
|
|
137
|
+
└── runtime/
|
|
138
|
+
├── types.ts # Shared types
|
|
139
|
+
└── validation.ts # Runtime validation
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Integration with Build Tools
|
|
143
|
+
|
|
144
|
+
### Vite
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
// vite.config.ts
|
|
148
|
+
import { defineConfig } from 'vite';
|
|
149
|
+
|
|
150
|
+
export default defineConfig({
|
|
151
|
+
plugins: [
|
|
152
|
+
// Run rcontracts compile before build
|
|
153
|
+
{
|
|
154
|
+
name: 'reactive-contracts',
|
|
155
|
+
buildStart: async () => {
|
|
156
|
+
const { compile } = await import('@reactive-contracts/compiler');
|
|
157
|
+
await compile();
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### package.json scripts
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"scripts": {
|
|
169
|
+
"contracts:compile": "rcontracts compile",
|
|
170
|
+
"contracts:validate": "rcontracts validate",
|
|
171
|
+
"contracts:watch": "rcontracts compile --watch",
|
|
172
|
+
"prebuild": "pnpm contracts:compile"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Related Packages
|
|
178
|
+
|
|
179
|
+
- [`@reactive-contracts/core`](https://www.npmjs.com/package/@reactive-contracts/core) - Core types and contract definitions
|
|
180
|
+
- [`@reactive-contracts/react`](https://www.npmjs.com/package/@reactive-contracts/react) - React hooks and client utilities
|
|
181
|
+
- [`@reactive-contracts/server`](https://www.npmjs.com/package/@reactive-contracts/server) - Server-side implementation utilities
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactive-contracts/compiler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-beta",
|
|
4
4
|
"description": "Build-time compiler and validator for Reactive Contracts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"picocolors": "^1.1.1",
|
|
27
27
|
"tsx": "^4.21.0",
|
|
28
28
|
"zod": "^4.3.5",
|
|
29
|
-
"@reactive-contracts/core": "0.1.
|
|
29
|
+
"@reactive-contracts/core": "0.1.1-beta"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/fs-extra": "^11.0.4",
|