@macroforge/mcp-server 0.1.32 → 0.1.34
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 +68 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -1
- package/dist/index.js.map +1 -1
- package/dist/tools/docs-loader.d.ts +133 -5
- package/dist/tools/docs-loader.d.ts.map +1 -1
- package/dist/tools/docs-loader.js +131 -15
- package/dist/tools/docs-loader.js.map +1 -1
- package/dist/tools/index.d.ts +48 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +163 -14
- package/dist/tools/index.js.map +1 -1
- package/docs/api/api-overview.md +24 -46
- package/docs/api/expand-sync.md +24 -51
- package/docs/api/native-plugin.md +24 -56
- package/docs/api/position-mapper.md +34 -76
- package/docs/api/transform-sync.md +27 -59
- package/docs/builtin-macros/clone.md +150 -68
- package/docs/builtin-macros/debug.md +216 -81
- package/docs/builtin-macros/default.md +234 -91
- package/docs/builtin-macros/deserialize.md +891 -166
- package/docs/builtin-macros/hash.md +238 -82
- package/docs/builtin-macros/macros-overview.md +42 -103
- package/docs/builtin-macros/ord.md +205 -92
- package/docs/builtin-macros/partial-eq.md +178 -97
- package/docs/builtin-macros/partial-ord.md +209 -98
- package/docs/builtin-macros/serialize.md +326 -137
- package/docs/concepts/architecture.md +40 -99
- package/docs/concepts/derive-system.md +132 -125
- package/docs/concepts/how-macros-work.md +52 -84
- package/docs/custom-macros/custom-overview.md +17 -39
- package/docs/custom-macros/rust-setup.md +22 -55
- package/docs/custom-macros/ts-macro-derive.md +43 -107
- package/docs/custom-macros/ts-quote.md +177 -507
- package/docs/getting-started/first-macro.md +108 -33
- package/docs/getting-started/installation.md +32 -73
- package/docs/integration/cli.md +70 -156
- package/docs/integration/configuration.md +32 -75
- package/docs/integration/integration-overview.md +16 -55
- package/docs/integration/mcp-server.md +30 -69
- package/docs/integration/svelte-preprocessor.md +60 -83
- package/docs/integration/typescript-plugin.md +32 -74
- package/docs/integration/vite-plugin.md +30 -79
- package/docs/language-servers/ls-overview.md +22 -46
- package/docs/language-servers/svelte.md +30 -69
- package/docs/language-servers/zed.md +34 -72
- package/docs/roadmap/roadmap.md +54 -130
- package/docs/sections.json +3 -262
- package/package.json +2 -2
|
@@ -1,121 +1,265 @@
|
|
|
1
1
|
# Default
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
*The `Default` macro generates a static `defaultValue()` factory method that creates instances with default values. This is analogous to Rust's `Default` trait, providing a standard way to create "zero" or "empty" instances of types.*
|
|
3
|
+
## Basic Usage
|
|
4
|
+
**Before:**
|
|
5
|
+
```
|
|
6
|
+
/** @derive(Default) */
|
|
7
|
+
class Config {
|
|
8
|
+
host: string;
|
|
9
|
+
port: number;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
|
|
12
|
+
constructor(host: string, port: number, enabled: boolean) {
|
|
13
|
+
this.host = host;
|
|
14
|
+
this.port = port;
|
|
15
|
+
this.enabled = enabled;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
**After:**
|
|
20
|
+
```
|
|
21
|
+
class Config {
|
|
22
|
+
host: string;
|
|
23
|
+
port: number;
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
|
|
26
|
+
constructor(host: string, port: number, enabled: boolean) {
|
|
27
|
+
this.host = host;
|
|
28
|
+
this.port = port;
|
|
29
|
+
this.enabled = enabled;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static defaultValue(): Config {
|
|
33
|
+
const instance = new Config();
|
|
34
|
+
instance.host = '';
|
|
35
|
+
instance.port = 0;
|
|
36
|
+
instance.enabled = false;
|
|
37
|
+
return instance;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
``` ```
|
|
10
41
|
const config = Config.defaultValue();
|
|
11
42
|
console.log(config.host); // ""
|
|
12
43
|
console.log(config.port); // 0
|
|
13
44
|
console.log(config.enabled); // false
|
|
45
|
+
``` ## Automatic Default Values
|
|
46
|
+
Like Rust's `Default` trait, the macro automatically determines default values for primitive types and common collections:
|
|
47
|
+
| TypeScript Type | Default Value | Rust Equivalent |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| `string` | `""` | `String::default()` |
|
|
50
|
+
| `number` | `0` | `i32::default()` |
|
|
51
|
+
| `boolean` | `false` | `bool::default()` |
|
|
52
|
+
| `bigint` | `0n` | `i64::default()` |
|
|
53
|
+
| `T[]` / `Array<T>` | `[]` | `Vec::default()` |
|
|
54
|
+
| `Map<K, V>` | `new Map()` | `HashMap::default()` |
|
|
55
|
+
| `Set<T>` | `new Set()` | `HashSet::default()` |
|
|
56
|
+
| `Date` | `new Date()` | — |
|
|
57
|
+
| `T | null` / `T | undefined` | `null` | `Option::default()` |
|
|
58
|
+
| Custom types | **Error** | **Error** (needs `impl Default`) |
|
|
59
|
+
## Nullable Types (like Rust's Option)
|
|
60
|
+
Just like Rust's `Option<T>` defaults to `None`, nullable TypeScript types automatically default to `null`:
|
|
61
|
+
**Before:**
|
|
14
62
|
```
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
| Custom types | **Error** | **Error** (needs `impl Default`)
|
|
39
|
-
|
|
40
|
-
## Nullable Types (like Rust's Option)
|
|
41
|
-
|
|
42
|
-
Just like Rust's `Option<T>` defaults to `None`, nullable TypeScript types automatically default to `null`:
|
|
43
|
-
|
|
44
|
-
<MacroExample before={data.examples.nullable.before} after={data.examples.nullable.after} />
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
63
|
+
/** @derive(Default) */
|
|
64
|
+
interface User {
|
|
65
|
+
name: string;
|
|
66
|
+
email: string | null;
|
|
67
|
+
age: number;
|
|
68
|
+
metadata: Record<string, unknown> | null;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
**After:**
|
|
72
|
+
```
|
|
73
|
+
interface User {
|
|
74
|
+
name: string;
|
|
75
|
+
email: string | null;
|
|
76
|
+
age: number;
|
|
77
|
+
metadata: Record<string, unknown> | null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export namespace User {
|
|
81
|
+
export function defaultValue(): User {
|
|
82
|
+
return { name: '', email: null, age: 0, metadata: null } as User;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
``` ```
|
|
47
86
|
const user = User.defaultValue();
|
|
48
87
|
console.log(user.name); // ""
|
|
49
88
|
console.log(user.email); // null (nullable type)
|
|
50
89
|
console.log(user.age); // 0
|
|
51
90
|
console.log(user.metadata); // null (nullable type)
|
|
91
|
+
``` ## Custom Types Require @default
|
|
92
|
+
Just like Rust requires `impl Default` for custom types, Macroforge requires the `@default()` decorator on fields with non-primitive types:
|
|
93
|
+
**Before:**
|
|
52
94
|
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```
|
|
95
|
+
/** @derive(Default) */
|
|
96
|
+
interface AppConfig {
|
|
97
|
+
name: string;
|
|
98
|
+
port: number;
|
|
99
|
+
/** @default(Settings.defaultValue()) */
|
|
100
|
+
settings: Settings;
|
|
101
|
+
/** @default(Permissions.defaultValue()) */
|
|
102
|
+
permissions: Permissions;
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
**After:**
|
|
106
|
+
```
|
|
107
|
+
interface AppConfig {
|
|
108
|
+
name: string;
|
|
109
|
+
port: number;
|
|
110
|
+
|
|
111
|
+
settings: Settings;
|
|
112
|
+
|
|
113
|
+
permissions: Permissions;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export namespace AppConfig {
|
|
117
|
+
export function defaultValue(): AppConfig {
|
|
118
|
+
return {
|
|
119
|
+
name: '',
|
|
120
|
+
port: 0,
|
|
121
|
+
settings: Settings.defaultValue(),
|
|
122
|
+
permissions: Permissions.defaultValue()
|
|
123
|
+
} as AppConfig;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
``` <p class="text-red-500 text-sm mt-2">Without `@default` on custom type fields, the macro will emit an error: ```
|
|
65
127
|
// Error: @derive(Default) cannot determine default for non-primitive fields.
|
|
66
128
|
// Add @default(value) to: settings, permissions
|
|
129
|
+
``` ## Custom Default Values
|
|
130
|
+
Use the `@default()` decorator to specify custom default values for any field:
|
|
131
|
+
**Before:**
|
|
67
132
|
```
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
133
|
+
/** @derive(Default) */
|
|
134
|
+
class ServerConfig {
|
|
135
|
+
/** @default("localhost") */
|
|
136
|
+
host: string;
|
|
137
|
+
|
|
138
|
+
/** @default(8080) */
|
|
139
|
+
port: number;
|
|
140
|
+
|
|
141
|
+
/** @default(true) */
|
|
142
|
+
enabled: boolean;
|
|
143
|
+
|
|
144
|
+
/** @default(["info", "error"]) */
|
|
145
|
+
logLevels: string[];
|
|
146
|
+
|
|
147
|
+
constructor(host: string, port: number, enabled: boolean, logLevels: string[]) {
|
|
148
|
+
this.host = host;
|
|
149
|
+
this.port = port;
|
|
150
|
+
this.enabled = enabled;
|
|
151
|
+
this.logLevels = logLevels;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
**After:**
|
|
156
|
+
```
|
|
157
|
+
class ServerConfig {
|
|
158
|
+
host: string;
|
|
159
|
+
|
|
160
|
+
port: number;
|
|
161
|
+
|
|
162
|
+
enabled: boolean;
|
|
163
|
+
|
|
164
|
+
logLevels: string[];
|
|
165
|
+
|
|
166
|
+
constructor(host: string, port: number, enabled: boolean, logLevels: string[]) {
|
|
167
|
+
this.host = host;
|
|
168
|
+
this.port = port;
|
|
169
|
+
this.enabled = enabled;
|
|
170
|
+
this.logLevels = logLevels;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static defaultValue(): ServerConfig {
|
|
174
|
+
const instance = new ServerConfig();
|
|
175
|
+
instance.host = 'localhost';
|
|
176
|
+
instance.port = 8080;
|
|
177
|
+
instance.enabled = true;
|
|
178
|
+
instance.logLevels = ['info', 'error'];
|
|
179
|
+
return instance;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
``` ```
|
|
76
183
|
const config = ServerConfig.defaultValue();
|
|
77
184
|
console.log(config.host); // "localhost"
|
|
78
185
|
console.log(config.port); // 8080
|
|
79
186
|
console.log(config.enabled); // true
|
|
80
187
|
console.log(config.logLevels); // ["info", "error"]
|
|
188
|
+
``` ## Interface Support
|
|
189
|
+
Default also works with interfaces. For interfaces, a namespace is generated with a `defaultValue()` function:
|
|
190
|
+
**Before:**
|
|
81
191
|
```
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
```
|
|
192
|
+
/** @derive(Default) */
|
|
193
|
+
interface Point {
|
|
194
|
+
x: number;
|
|
195
|
+
y: number;
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
**After:**
|
|
199
|
+
```
|
|
200
|
+
interface Point {
|
|
201
|
+
x: number;
|
|
202
|
+
y: number;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export namespace Point {
|
|
206
|
+
export function defaultValue(): Point {
|
|
207
|
+
return { x: 0, y: 0 } as Point;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
``` ```
|
|
90
211
|
const origin = Point.defaultValue();
|
|
91
212
|
console.log(origin); // { x: 0, y: 0 }
|
|
213
|
+
``` ## Enum Support
|
|
214
|
+
Default works with enums. For enums, it returns the first variant as the default value:
|
|
215
|
+
**Before:**
|
|
92
216
|
```
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
217
|
+
/** @derive(Default) */
|
|
218
|
+
enum Status {
|
|
219
|
+
Pending = 'pending',
|
|
220
|
+
Active = 'active',
|
|
221
|
+
Completed = 'completed'
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
**After:**
|
|
225
|
+
```
|
|
226
|
+
enum Status {
|
|
227
|
+
Pending = 'pending',
|
|
228
|
+
Active = 'active',
|
|
229
|
+
Completed = 'completed'
|
|
230
|
+
}
|
|
231
|
+
``` ```
|
|
101
232
|
const defaultStatus = Status.defaultValue();
|
|
102
233
|
console.log(defaultStatus); // "pending"
|
|
234
|
+
``` ## Type Alias Support
|
|
235
|
+
Default works with type aliases. For object types, it creates an object with default field values:
|
|
236
|
+
**Before:**
|
|
103
237
|
```
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
```
|
|
238
|
+
/** @derive(Default) */
|
|
239
|
+
type Dimensions = {
|
|
240
|
+
width: number;
|
|
241
|
+
height: number;
|
|
242
|
+
};
|
|
243
|
+
```
|
|
244
|
+
**After:**
|
|
245
|
+
```
|
|
246
|
+
type Dimensions = {
|
|
247
|
+
width: number;
|
|
248
|
+
height: number;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export namespace Dimensions {
|
|
252
|
+
export function defaultValue(): Dimensions {
|
|
253
|
+
return { width: 0, height: 0 } as Dimensions;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
``` ```
|
|
112
257
|
const dims = Dimensions.defaultValue();
|
|
113
258
|
console.log(dims); // { width: 0, height: 0 }
|
|
259
|
+
``` ## Combining with Other Macros
|
|
260
|
+
**Source:**
|
|
114
261
|
```
|
|
115
|
-
|
|
116
|
-
## Combining with Other Macros
|
|
117
|
-
|
|
118
|
-
<InteractiveMacro code={`/** @derive(Default, Debug, Clone, PartialEq) */
|
|
262
|
+
/** @derive(Default, Debug, Clone, PartialEq) */
|
|
119
263
|
class User {
|
|
120
264
|
/** @default("Anonymous") */
|
|
121
265
|
name: string;
|
|
@@ -127,9 +271,8 @@ class User {
|
|
|
127
271
|
this.name = name;
|
|
128
272
|
this.age = age;
|
|
129
273
|
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
274
|
+
}
|
|
275
|
+
``` ```
|
|
133
276
|
const user1 = User.defaultValue();
|
|
134
277
|
const user2 = user1.clone();
|
|
135
278
|
|