@macroforge/mcp-server 0.1.37 → 0.1.38

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.
@@ -8,18 +8,11 @@ objects to be used as keys in hash-based collections.
8
8
 
9
9
  | Type | Generated Code | Description |
10
10
  |------|----------------|-------------|
11
- | Class | `hashCode(): number` | Instance method computing hash from all fields |
12
- | Enum | `hashCodeEnumName(value: EnumName): number` | Standalone function hashing by enum value |
13
- | Interface | `hashCodeInterfaceName(value: InterfaceName): number` | Standalone function computing hash |
14
- | Type Alias | `hashCodeTypeName(value: TypeName): number` | Standalone function computing hash |
11
+ | Class | `classNameHashCode(value)` + `static hashCode(value)` | Standalone function + static wrapper method |
12
+ | Enum | `enumNameHashCode(value: EnumName): number` | Standalone function hashing by enum value |
13
+ | Interface | `interfaceNameHashCode(value: InterfaceName): number` | Standalone function computing hash |
14
+ | Type Alias | `typeNameHashCode(value: TypeName): number` | Standalone function computing hash |
15
15
 
16
- ## Configuration
17
-
18
- The `functionNamingStyle` option in `macroforge.json` controls naming:
19
- - `"prefix"` (default): Prefixes with type name (e.g., `myTypeHashCode`)
20
- - `"suffix"`: Suffixes with type name (e.g., `hashCodeMyType`)
21
- - `"generic"`: Uses TypeScript generics (e.g., `hashCode<T extends MyType>`)
22
- - `"namespace"`: Legacy namespace wrapping
23
16
 
24
17
  ## Hash Algorithm
25
18
 
@@ -55,23 +48,97 @@ The `@hash` decorator supports:
55
48
 
56
49
  ## Example
57
50
 
51
+ ```typescript before
52
+ /** @derive(Hash, PartialEq) */
53
+ class User {
54
+ id: number;
55
+ name: string;
56
+
57
+ /** @hash({ skip: true }) */
58
+ cachedScore: number;
59
+ }
60
+ ```
61
+
62
+ ```typescript after
63
+ class User {
64
+ id: number;
65
+ name: string;
66
+
67
+ cachedScore: number;
68
+
69
+ static hashCode(value: User): number {
70
+ return userHashCode(value);
71
+ }
72
+
73
+ static equals(a: User, b: User): boolean {
74
+ return userEquals(a, b);
75
+ }
76
+ }
77
+
78
+ export function userHashCode(value: User): number {
79
+ let hash = 17;
80
+ hash =
81
+ (hash * 31 +
82
+ (Number.isInteger(value.id)
83
+ ? value.id | 0
84
+ : value.id
85
+ .toString()
86
+ .split('')
87
+ .reduce((h, c) => (h * 31 + c.charCodeAt(0)) | 0, 0))) |
88
+ 0;
89
+ hash =
90
+ (hash * 31 +
91
+ (value.name ?? '').split('').reduce((h, c) => (h * 31 + c.charCodeAt(0)) | 0, 0)) |
92
+ 0;
93
+ return hash;
94
+ }
95
+
96
+ export function userEquals(a: User, b: User): boolean {
97
+ if (a === b) return true;
98
+ return a.id === b.id && a.name === b.name && a.cachedScore === b.cachedScore;
99
+ }
100
+ ```
101
+
102
+ Generated output:
103
+
58
104
  ```typescript
59
- @derive(Hash, PartialEq)
60
105
  class User {
61
106
  id: number;
62
107
  name: string;
63
108
 
64
- @hash(skip) // Cached value shouldn't affect hash
65
109
  cachedScore: number;
110
+
111
+ static hashCode(value: User): number {
112
+ return userHashCode(value);
113
+ }
114
+
115
+ static equals(a: User, b: User): boolean {
116
+ return userEquals(a, b);
117
+ }
66
118
  }
67
119
 
68
- // Generated:
69
- // hashCode(): number {
70
- // let hash = 17;
71
- // hash = (hash * 31 + (Number.isInteger(this.id) ? this.id | 0 : ...)) | 0;
72
- // hash = (hash * 31 + (this.name ?? '').split('').reduce(...)) | 0;
73
- // return hash;
74
- // }
120
+ export function userHashCode(value: User): number {
121
+ let hash = 17;
122
+ hash =
123
+ (hash * 31 +
124
+ (Number.isInteger(value.id)
125
+ ? value.id | 0
126
+ : value.id
127
+ .toString()
128
+ .split('')
129
+ .reduce((h, c) => (h * 31 + c.charCodeAt(0)) | 0, 0))) |
130
+ 0;
131
+ hash =
132
+ (hash * 31 +
133
+ (value.name ?? '').split('').reduce((h, c) => (h * 31 + c.charCodeAt(0)) | 0, 0)) |
134
+ 0;
135
+ return hash;
136
+ }
137
+
138
+ export function userEquals(a: User, b: User): boolean {
139
+ if (a === b) return true;
140
+ return a.id === b.id && a.name === b.name && a.cachedScore === b.cachedScore;
141
+ }
75
142
  ```
76
143
 
77
144
  ## Hash Contract
@@ -8,29 +8,22 @@ compared with a guaranteed ordering relationship.
8
8
 
9
9
  | Type | Generated Code | Description |
10
10
  |------|----------------|-------------|
11
- | Class | `compareTo(other): number` | Instance method returning -1, 0, or 1 |
12
- | Enum | `compareEnumName(a: EnumName, b: EnumName): number` | Standalone function comparing enum values |
13
- | Interface | `compareInterfaceName(a: InterfaceName, b: InterfaceName): number` | Standalone function comparing fields |
14
- | Type Alias | `compareTypeName(a: TypeName, b: TypeName): number` | Standalone function with type-appropriate comparison |
11
+ | Class | `classNameCompare(a, b)` + `static compareTo(a, b)` | Standalone function + static wrapper method |
12
+ | Enum | `enumNameCompare(a: EnumName, b: EnumName): number` | Standalone function comparing enum values |
13
+ | Interface | `interfaceNameCompare(a: InterfaceName, b: InterfaceName): number` | Standalone function comparing fields |
14
+ | Type Alias | `typeNameCompare(a: TypeName, b: TypeName): number` | Standalone function with type-appropriate comparison |
15
15
 
16
- ## Configuration
17
-
18
- The `functionNamingStyle` option in `macroforge.json` controls naming:
19
- - `"prefix"` (default): Prefixes with type name (e.g., `myTypeCompare`)
20
- - `"suffix"`: Suffixes with type name (e.g., `compareMyType`)
21
- - `"generic"`: Uses TypeScript generics (e.g., `compare<T extends MyType>`)
22
- - `"namespace"`: Legacy namespace wrapping
23
16
 
24
17
  ## Return Values
25
18
 
26
19
  Unlike `PartialOrd`, `Ord` provides **total ordering** - every pair of values
27
20
  can be compared:
28
21
 
29
- - **-1**: `this` is less than `other`
30
- - **0**: `this` is equal to `other`
31
- - **1**: `this` is greater than `other`
22
+ - **-1**: `a` is less than `b`
23
+ - **0**: `a` is equal to `b`
24
+ - **1**: `a` is greater than `b`
32
25
 
33
- The method **never returns null** - all values must be comparable.
26
+ The function **never returns null** - all values must be comparable.
34
27
 
35
28
  ## Comparison Strategy
36
29
 
@@ -60,29 +53,61 @@ The `@ord` decorator supports:
60
53
 
61
54
  ## Example
62
55
 
56
+ ```typescript before
57
+ /** @derive(Ord) */
58
+ class Version {
59
+ major: number;
60
+ minor: number;
61
+ patch: number;
62
+ }
63
+ ```
64
+
65
+ ```typescript after
66
+ class Version {
67
+ major: number;
68
+ minor: number;
69
+ patch: number;
70
+
71
+ static compareTo(a: Version, b: Version): number {
72
+ return versionCompare(a, b);
73
+ }
74
+ }
75
+
76
+ export function versionCompare(a: Version, b: Version): number {
77
+ if (a === b) return 0;
78
+ const cmp0 = a.major < b.major ? -1 : a.major > b.major ? 1 : 0;
79
+ if (cmp0 !== 0) return cmp0;
80
+ const cmp1 = a.minor < b.minor ? -1 : a.minor > b.minor ? 1 : 0;
81
+ if (cmp1 !== 0) return cmp1;
82
+ const cmp2 = a.patch < b.patch ? -1 : a.patch > b.patch ? 1 : 0;
83
+ if (cmp2 !== 0) return cmp2;
84
+ return 0;
85
+ }
86
+ ```
87
+
88
+ Generated output:
89
+
63
90
  ```typescript
64
- @derive(Ord)
65
91
  class Version {
66
92
  major: number;
67
93
  minor: number;
68
94
  patch: number;
95
+
96
+ static compareTo(a: Version, b: Version): number {
97
+ return versionCompare(a, b);
98
+ }
69
99
  }
70
100
 
71
- // Generated:
72
- // compareTo(other: Version): number {
73
- // if (this === other) return 0;
74
- // const typedOther = other;
75
- // const cmp0 = this.major < typedOther.major ? -1 : this.major > typedOther.major ? 1 : 0;
76
- // if (cmp0 !== 0) return cmp0;
77
- // const cmp1 = this.minor < typedOther.minor ? -1 : ...;
78
- // if (cmp1 !== 0) return cmp1;
79
- // const cmp2 = this.patch < typedOther.patch ? -1 : ...;
80
- // if (cmp2 !== 0) return cmp2;
81
- // return 0;
82
- // }
83
-
84
- // Usage:
85
- versions.sort((a, b) => a.compareTo(b));
101
+ export function versionCompare(a: Version, b: Version): number {
102
+ if (a === b) return 0;
103
+ const cmp0 = a.major < b.major ? -1 : a.major > b.major ? 1 : 0;
104
+ if (cmp0 !== 0) return cmp0;
105
+ const cmp1 = a.minor < b.minor ? -1 : a.minor > b.minor ? 1 : 0;
106
+ if (cmp1 !== 0) return cmp1;
107
+ const cmp2 = a.patch < b.patch ? -1 : a.patch > b.patch ? 1 : 0;
108
+ if (cmp2 !== 0) return cmp2;
109
+ return 0;
110
+ }
86
111
  ```
87
112
 
88
113
  ## Ord vs PartialOrd