@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,12 +1,38 @@
|
|
|
1
1
|
# PartialEq
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
*The `PartialEq` macro generates an `equals()` method for field-by-field structural equality comparison. This is analogous to Rust's `PartialEq` trait, enabling value-based equality semantics instead of reference equality.*
|
|
3
|
+
## Basic Usage
|
|
4
|
+
**Before:**
|
|
5
|
+
```
|
|
6
|
+
/** @derive(PartialEq) */
|
|
7
|
+
class Point {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
|
|
11
|
+
constructor(x: number, y: number) {
|
|
12
|
+
this.x = x;
|
|
13
|
+
this.y = y;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
**After:**
|
|
18
|
+
```
|
|
19
|
+
class Point {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
|
|
23
|
+
constructor(x: number, y: number) {
|
|
24
|
+
this.x = x;
|
|
25
|
+
this.y = y;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
equals(other: unknown): boolean {
|
|
29
|
+
if (this === other) return true;
|
|
30
|
+
if (!(other instanceof Point)) return false;
|
|
31
|
+
const typedOther = other as Point;
|
|
32
|
+
return this.x === typedOther.x && this.y === typedOther.y;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
``` ```
|
|
10
36
|
const p1 = new Point(10, 20);
|
|
11
37
|
const p2 = new Point(10, 20);
|
|
12
38
|
const p3 = new Point(5, 5);
|
|
@@ -14,63 +40,81 @@ const p3 = new Point(5, 5);
|
|
|
14
40
|
console.log(p1.equals(p2)); // true (same values)
|
|
15
41
|
console.log(p1.equals(p3)); // false (different values)
|
|
16
42
|
console.log(p1 === p2); // false (different references)
|
|
43
|
+
``` ## How It Works
|
|
44
|
+
The PartialEq macro performs field-by-field comparison using these strategies:
|
|
45
|
+
- **Primitives** (string, number, boolean, null, undefined) → Strict equality (`===`)
|
|
46
|
+
- **Date** → Compares timestamps via `getTime()`
|
|
47
|
+
- **Array** → Length check + element-by-element comparison
|
|
48
|
+
- **Map** → Size check + entry comparison
|
|
49
|
+
- **Set** → Size check + membership verification
|
|
50
|
+
- **Objects** → Calls `equals()` if available, otherwise `===`
|
|
51
|
+
## Field Options
|
|
52
|
+
### @partialEq(skip)
|
|
53
|
+
Use `@partialEq(skip)` to exclude a field from equality comparison:
|
|
54
|
+
**Before:**
|
|
17
55
|
```
|
|
56
|
+
/** @derive(PartialEq) */
|
|
57
|
+
class User {
|
|
58
|
+
id: number;
|
|
59
|
+
name: string;
|
|
18
60
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
The PartialEq macro performs field-by-field comparison using these strategies:
|
|
22
|
-
|
|
23
|
-
- **Primitives** (string, number, boolean, null, undefined) → Strict equality (`===`)
|
|
24
|
-
|
|
25
|
-
- **Date** → Compares timestamps via `getTime()`
|
|
26
|
-
|
|
27
|
-
- **Array** → Length check + element-by-element comparison
|
|
28
|
-
|
|
29
|
-
- **Map** → Size check + entry comparison
|
|
30
|
-
|
|
31
|
-
- **Set** → Size check + membership verification
|
|
32
|
-
|
|
33
|
-
- **Objects** → Calls `equals()` if available, otherwise `===`
|
|
34
|
-
|
|
35
|
-
## Field Options
|
|
36
|
-
|
|
37
|
-
### @partialEq(skip)
|
|
38
|
-
|
|
39
|
-
Use `@partialEq(skip)` to exclude a field from equality comparison:
|
|
40
|
-
|
|
41
|
-
<MacroExample before={data.examples.skip.before} after={data.examples.skip.after} />
|
|
61
|
+
/** @partialEq(skip) */
|
|
62
|
+
createdAt: Date;
|
|
42
63
|
|
|
43
|
-
|
|
64
|
+
constructor(id: number, name: string, createdAt: Date) {
|
|
65
|
+
this.id = id;
|
|
66
|
+
this.name = name;
|
|
67
|
+
this.createdAt = createdAt;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
**After:**
|
|
72
|
+
```
|
|
73
|
+
class User {
|
|
74
|
+
id: number;
|
|
75
|
+
name: string;
|
|
76
|
+
|
|
77
|
+
createdAt: Date;
|
|
78
|
+
|
|
79
|
+
constructor(id: number, name: string, createdAt: Date) {
|
|
80
|
+
this.id = id;
|
|
81
|
+
this.name = name;
|
|
82
|
+
this.createdAt = createdAt;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
equals(other: unknown): boolean {
|
|
86
|
+
if (this === other) return true;
|
|
87
|
+
if (!(other instanceof User)) return false;
|
|
88
|
+
const typedOther = other as User;
|
|
89
|
+
return this.id === typedOther.id && this.name === typedOther.name;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
``` ```
|
|
44
93
|
const user1 = new User(1, "Alice", new Date("2024-01-01"));
|
|
45
94
|
const user2 = new User(1, "Alice", new Date("2024-12-01"));
|
|
46
95
|
|
|
47
96
|
console.log(user1.equals(user2)); // true (createdAt is skipped)
|
|
97
|
+
``` ## Type Safety
|
|
98
|
+
The generated `equals()` method accepts `unknown` and performs runtime type checking:
|
|
99
|
+
**Source:**
|
|
48
100
|
```
|
|
49
|
-
|
|
50
|
-
## Type Safety
|
|
51
|
-
|
|
52
|
-
The generated `equals()` method accepts `unknown` and performs runtime type checking:
|
|
53
|
-
|
|
54
|
-
<InteractiveMacro code={`/** @derive(PartialEq) */
|
|
101
|
+
/** @derive(PartialEq) */
|
|
55
102
|
class User {
|
|
56
103
|
name: string;
|
|
57
104
|
constructor(name: string) {
|
|
58
105
|
this.name = name;
|
|
59
106
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
107
|
+
}
|
|
108
|
+
``` ```
|
|
63
109
|
const user = new User("Alice");
|
|
64
110
|
|
|
65
111
|
console.log(user.equals(new User("Alice"))); // true
|
|
66
112
|
console.log(user.equals("Alice")); // false (not a User instance)
|
|
113
|
+
``` ## With Nested Objects
|
|
114
|
+
For objects with nested fields, PartialEq recursively calls `equals()` if available:
|
|
115
|
+
**Source:**
|
|
67
116
|
```
|
|
68
|
-
|
|
69
|
-
## With Nested Objects
|
|
70
|
-
|
|
71
|
-
For objects with nested fields, PartialEq recursively calls `equals()` if available:
|
|
72
|
-
|
|
73
|
-
<InteractiveMacro code={`/** @derive(PartialEq) */
|
|
117
|
+
/** @derive(PartialEq) */
|
|
74
118
|
class Address {
|
|
75
119
|
city: string;
|
|
76
120
|
zip: string;
|
|
@@ -90,9 +134,8 @@ class Person {
|
|
|
90
134
|
this.name = name;
|
|
91
135
|
this.address = address;
|
|
92
136
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
137
|
+
}
|
|
138
|
+
``` ```
|
|
96
139
|
const addr1 = new Address("NYC", "10001");
|
|
97
140
|
const addr2 = new Address("NYC", "10001");
|
|
98
141
|
|
|
@@ -100,62 +143,104 @@ const p1 = new Person("Alice", addr1);
|
|
|
100
143
|
const p2 = new Person("Alice", addr2);
|
|
101
144
|
|
|
102
145
|
console.log(p1.equals(p2)); // true (deep equality via Address.equals)
|
|
146
|
+
``` ## Interface Support
|
|
147
|
+
PartialEq works with interfaces. For interfaces, a namespace is generated with an `equals` function:
|
|
148
|
+
**Before:**
|
|
103
149
|
```
|
|
150
|
+
/** @derive(PartialEq) */
|
|
151
|
+
interface Point {
|
|
152
|
+
x: number;
|
|
153
|
+
y: number;
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
**After:**
|
|
157
|
+
```
|
|
158
|
+
interface Point {
|
|
159
|
+
x: number;
|
|
160
|
+
y: number;
|
|
161
|
+
}
|
|
104
162
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
```
|
|
163
|
+
export namespace Point {
|
|
164
|
+
export function equals(self: Point, other: Point): boolean {
|
|
165
|
+
if (self === other) return true;
|
|
166
|
+
return self.x === other.x && self.y === other.y;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
``` ```
|
|
112
170
|
const p1: Point = { x: 10, y: 20 };
|
|
113
171
|
const p2: Point = { x: 10, y: 20 };
|
|
114
172
|
const p3: Point = { x: 5, y: 5 };
|
|
115
173
|
|
|
116
174
|
console.log(Point.equals(p1, p2)); // true
|
|
117
175
|
console.log(Point.equals(p1, p3)); // false
|
|
176
|
+
``` ## Enum Support
|
|
177
|
+
PartialEq works with enums. For enums, strict equality comparison is used:
|
|
178
|
+
**Before:**
|
|
118
179
|
```
|
|
180
|
+
/** @derive(PartialEq) */
|
|
181
|
+
enum Status {
|
|
182
|
+
Active = 'active',
|
|
183
|
+
Inactive = 'inactive',
|
|
184
|
+
Pending = 'pending'
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
**After:**
|
|
188
|
+
```
|
|
189
|
+
enum Status {
|
|
190
|
+
Active = 'active',
|
|
191
|
+
Inactive = 'inactive',
|
|
192
|
+
Pending = 'pending'
|
|
193
|
+
}
|
|
119
194
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
195
|
+
export namespace Status {
|
|
196
|
+
export function equals(a: Status, b: Status): boolean {
|
|
197
|
+
return a === b;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
``` ```
|
|
127
201
|
console.log(Status.equals(Status.Active, Status.Active)); // true
|
|
128
202
|
console.log(Status.equals(Status.Active, Status.Inactive)); // false
|
|
203
|
+
``` ## Type Alias Support
|
|
204
|
+
PartialEq works with type aliases. For object types, field-by-field comparison is used:
|
|
205
|
+
**Before:**
|
|
129
206
|
```
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
```
|
|
207
|
+
/** @derive(PartialEq) */
|
|
208
|
+
type Point = {
|
|
209
|
+
x: number;
|
|
210
|
+
y: number;
|
|
211
|
+
};
|
|
212
|
+
```
|
|
213
|
+
**After:**
|
|
214
|
+
```
|
|
215
|
+
type Point = {
|
|
216
|
+
x: number;
|
|
217
|
+
y: number;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export namespace Point {
|
|
221
|
+
export function equals(a: Point, b: Point): boolean {
|
|
222
|
+
if (a === b) return true;
|
|
223
|
+
return a.x === b.x && a.y === b.y;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
``` ```
|
|
138
227
|
const p1: Point = { x: 10, y: 20 };
|
|
139
228
|
const p2: Point = { x: 10, y: 20 };
|
|
140
229
|
|
|
141
230
|
console.log(Point.equals(p1, p2)); // true
|
|
231
|
+
``` For union types, strict equality is used:
|
|
232
|
+
**Source:**
|
|
142
233
|
```
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
<InteractiveMacro code={`/** @derive(PartialEq) */
|
|
147
|
-
type ApiStatus = "loading" | "success" | "error";`} />
|
|
148
|
-
|
|
149
|
-
```typescript
|
|
234
|
+
/** @derive(PartialEq) */
|
|
235
|
+
type ApiStatus = "loading" | "success" | "error";
|
|
236
|
+
``` ```
|
|
150
237
|
console.log(ApiStatus.equals("success", "success")); // true
|
|
151
238
|
console.log(ApiStatus.equals("success", "error")); // false
|
|
239
|
+
``` ## Common Patterns
|
|
240
|
+
### Finding Items in Arrays
|
|
241
|
+
**Source:**
|
|
152
242
|
```
|
|
153
|
-
|
|
154
|
-
## Common Patterns
|
|
155
|
-
|
|
156
|
-
### Finding Items in Arrays
|
|
157
|
-
|
|
158
|
-
<InteractiveMacro code={`/** @derive(PartialEq) */
|
|
243
|
+
/** @derive(PartialEq) */
|
|
159
244
|
class Product {
|
|
160
245
|
sku: string;
|
|
161
246
|
name: string;
|
|
@@ -164,9 +249,8 @@ class Product {
|
|
|
164
249
|
this.sku = sku;
|
|
165
250
|
this.name = name;
|
|
166
251
|
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
```typescript
|
|
252
|
+
}
|
|
253
|
+
``` ```
|
|
170
254
|
const products = [
|
|
171
255
|
new Product("A1", "Widget"),
|
|
172
256
|
new Product("B2", "Gadget"),
|
|
@@ -177,13 +261,11 @@ const target = new Product("B2", "Gadget");
|
|
|
177
261
|
const found = products.find(p => p.equals(target));
|
|
178
262
|
|
|
179
263
|
console.log(found); // Product { sku: "B2", name: "Gadget" }
|
|
264
|
+
``` ### Use with Hash
|
|
265
|
+
When using objects as keys in Map-like structures, combine PartialEq with Hash:
|
|
266
|
+
**Source:**
|
|
180
267
|
```
|
|
181
|
-
|
|
182
|
-
### Use with Hash
|
|
183
|
-
|
|
184
|
-
When using objects as keys in Map-like structures, combine PartialEq with Hash:
|
|
185
|
-
|
|
186
|
-
<InteractiveMacro code={`/** @derive(PartialEq, Hash) */
|
|
268
|
+
/** @derive(PartialEq, Hash) */
|
|
187
269
|
class Key {
|
|
188
270
|
id: number;
|
|
189
271
|
type: string;
|
|
@@ -192,9 +274,8 @@ class Key {
|
|
|
192
274
|
this.id = id;
|
|
193
275
|
this.type = type;
|
|
194
276
|
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
277
|
+
}
|
|
278
|
+
``` ```
|
|
198
279
|
const k1 = new Key(1, "user");
|
|
199
280
|
const k2 = new Key(1, "user");
|
|
200
281
|
|