@macroforge/mcp-server 0.1.36 → 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 @@ independent copies of values.
8
8
 
9
9
  | Type | Generated Code | Description |
10
10
  |------|----------------|-------------|
11
- | Class | `clone(): ClassName` | Instance method creating a new instance with copied fields |
12
- | Enum | `cloneEnumName(value: EnumName): EnumName` | Standalone function (enums are primitives, returns value as-is) |
13
- | Interface | `cloneInterfaceName(value: InterfaceName): InterfaceName` | Standalone function creating a new object literal |
14
- | Type Alias | `cloneTypeName(value: TypeName): TypeName` | Standalone function with spread copy for objects |
11
+ | Class | `classNameClone(value)` + `static clone(value)` | Standalone function + static wrapper method |
12
+ | Enum | `enumNameClone(value: EnumName): EnumName` | Standalone function (enums are primitives, returns value as-is) |
13
+ | Interface | `interfaceNameClone(value: InterfaceName): InterfaceName` | Standalone function creating a new object literal |
14
+ | Type Alias | `typeNameClone(value: TypeName): TypeName` | Standalone function with spread copy for objects |
15
15
 
16
- ## Configuration
17
-
18
- The `functionNamingStyle` option in `macroforge.json` controls naming:
19
- - `"suffix"` (default): Suffixes with type name (e.g., `cloneMyType`)
20
- - `"prefix"`: Prefixes with type name (e.g., `myTypeClone`)
21
- - `"generic"`: Uses TypeScript generics (e.g., `clone<T extends MyType>`)
22
- - `"namespace"`: Legacy namespace wrapping
23
16
 
24
17
  ## Cloning Strategy
25
18
 
@@ -34,28 +27,55 @@ and the caller should clone them explicitly.
34
27
 
35
28
  ## Example
36
29
 
37
- ```typescript
38
- @derive(Clone)
30
+ ```typescript before
31
+ /** @derive(Clone) */
32
+ class Point {
33
+ x: number;
34
+ y: number;
35
+ }
36
+ ```
37
+
38
+ ```typescript after
39
39
  class Point {
40
40
  x: number;
41
41
  y: number;
42
+
43
+ static clone(value: Point): Point {
44
+ return pointClone(value);
45
+ }
46
+ }
47
+
48
+ export function pointClone(value: Point): Point {
49
+ const cloned = Object.create(Object.getPrototypeOf(value));
50
+ cloned.x = value.x;
51
+ cloned.y = value.y;
52
+ return cloned;
42
53
  }
54
+ ```
55
+
56
+ Generated output:
57
+
58
+ ```typescript
59
+ class Point {
60
+ x: number;
61
+ y: number;
43
62
 
44
- // Generated:
45
- // clone(): Point {
46
- // const cloned = Object.create(Object.getPrototypeOf(this));
47
- // cloned.x = this.x;
48
- // cloned.y = this.y;
49
- // return cloned;
50
- // }
63
+ static clone(value: Point): Point {
64
+ return pointClone(value);
65
+ }
66
+ }
51
67
 
52
- const p1 = new Point();
53
- const p2 = p1.clone(); // Creates a new Point with same values
68
+ export function pointClone(value: Point): Point {
69
+ const cloned = Object.create(Object.getPrototypeOf(value));
70
+ cloned.x = value.x;
71
+ cloned.y = value.y;
72
+ return cloned;
73
+ }
54
74
  ```
55
75
 
56
76
  ## Implementation Notes
57
77
 
58
- - **Classes**: Uses `Object.create(Object.getPrototypeOf(this))` to preserve
78
+ - **Classes**: Uses `Object.create(Object.getPrototypeOf(value))` to preserve
59
79
  the prototype chain, ensuring `instanceof` checks work correctly
60
80
  - **Enums**: Simply returns the value (enums are primitives in TypeScript)
61
81
  - **Interfaces/Type Aliases**: Creates new object literals with spread operator
@@ -5,24 +5,17 @@ TypeScript classes, interfaces, enums, and type aliases.
5
5
 
6
6
  ## Generated Output
7
7
 
8
- **Classes**: Generates an instance method returning a string
9
- like `"ClassName { field1: value1, field2: value2 }"`.
8
+ **Classes**: Generates a standalone function `classNameToString(value)` and a static wrapper
9
+ method `static toString(value)` returning a string like `"ClassName { field1: value1, field2: value2 }"`.
10
10
 
11
- **Enums**: Generates a standalone function `toStringEnumName(value)` that performs
11
+ **Enums**: Generates a standalone function `enumNameToString(value)` that performs
12
12
  reverse lookup on numeric enums.
13
13
 
14
- **Interfaces**: Generates a standalone function `toStringInterfaceName(value)`.
14
+ **Interfaces**: Generates a standalone function `interfaceNameToString(value)`.
15
15
 
16
16
  **Type Aliases**: Generates a standalone function using JSON.stringify for
17
17
  complex types, or field enumeration for object types.
18
18
 
19
- ## Configuration
20
-
21
- The `functionNamingStyle` option in `macroforge.json` controls naming:
22
- - `"suffix"` (default): Suffixes with type name (e.g., `toStringMyType`)
23
- - `"prefix"`: Prefixes with type name (e.g., `myTypeToString`)
24
- - `"generic"`: Uses TypeScript generics (e.g., `toString<T extends MyType>`)
25
- - `"namespace"`: Legacy namespace wrapping
26
19
 
27
20
  ## Field-Level Options
28
21
 
@@ -33,20 +26,59 @@ The `@debug` decorator supports:
33
26
 
34
27
  ## Example
35
28
 
29
+ ```typescript before
30
+ /** @derive(Debug) */
31
+ class User {
32
+ /** @debug({ rename: "id" }) */
33
+ userId: number;
34
+
35
+ /** @debug({ skip: true }) */
36
+ password: string;
37
+
38
+ email: string;
39
+ }
40
+ ```
41
+
42
+ ```typescript after
43
+ class User {
44
+ userId: number;
45
+
46
+ password: string;
47
+
48
+ email: string;
49
+
50
+ static toString(value: User): string {
51
+ return userToString(value);
52
+ }
53
+ }
54
+
55
+ export function userToString(value: User): string {
56
+ const parts: string[] = [];
57
+ parts.push('id: ' + value.userId);
58
+ parts.push('email: ' + value.email);
59
+ return 'User { ' + parts.join(', ') + ' }';
60
+ }
61
+ ```
62
+
63
+ Generated output:
64
+
36
65
  ```typescript
37
- @derive(Debug)
38
66
  class User {
39
- @debug(rename = "id")
40
67
  userId: number;
41
68
 
42
- @debug(skip)
43
69
  password: string;
44
70
 
45
71
  email: string;
72
+
73
+ static toString(value: User): string {
74
+ return userToString(value);
75
+ }
46
76
  }
47
77
 
48
- // Generated:
49
- // toString(): string {
50
- // return "User { id: " + this.userId + ", email: " + this.email + " }";
51
- // }
78
+ export function userToString(value: User): string {
79
+ const parts: string[] = [];
80
+ parts.push('id: ' + value.userId);
81
+ parts.push('email: ' + value.email);
82
+ return 'User { ' + parts.join(', ') + ' }';
83
+ }
52
84
  ```
@@ -13,13 +13,6 @@ a standard way to create "zero" or "empty" instances of types.
13
13
  | Interface | `defaultValueInterfaceName(): InterfaceName` | Standalone function returning object literal |
14
14
  | Type Alias | `defaultValueTypeName(): TypeName` | Standalone function with type-appropriate default |
15
15
 
16
- ## Configuration
17
-
18
- The `functionNamingStyle` option in `macroforge.json` controls naming:
19
- - `"suffix"` (default): Suffixes with type name (e.g., `defaultValueMyType`)
20
- - `"prefix"`: Prefixes with type name (e.g., `myTypeDefaultValue`)
21
- - `"generic"`: Uses TypeScript generics (e.g., `defaultValue<T extends MyType>`)
22
- - `"namespace"`: Legacy namespace wrapping
23
16
 
24
17
  ## Default Values by Type
25
18
 
@@ -50,47 +43,105 @@ The `@default` decorator allows specifying explicit default values:
50
43
 
51
44
  ## Example
52
45
 
53
- ```typescript
54
- @derive(Default)
46
+ ```typescript before
47
+ /** @derive(Default) */
55
48
  class UserSettings {
56
- @default("light")
49
+ /** @default("light") */
57
50
  theme: string;
58
51
 
59
- @default(10)
52
+ /** @default(10) */
60
53
  pageSize: number;
61
54
 
62
- notifications: boolean; // Uses type default: false
55
+ notifications: boolean; // Uses type default: false
63
56
  }
57
+ ```
58
+
59
+ ```typescript after
60
+ class UserSettings {
61
+ theme: string;
64
62
 
65
- // Generated:
66
- // static defaultValue(): UserSettings {
67
- // const instance = new UserSettings();
68
- // instance.theme = "light";
69
- // instance.pageSize = 10;
70
- // instance.notifications = false;
71
- // return instance;
72
- // }
63
+ pageSize: number;
64
+
65
+ notifications: boolean; // Uses type default: false
66
+
67
+ static defaultValue(): UserSettings {
68
+ const instance = new UserSettings();
69
+ instance.theme = 'light';
70
+ instance.pageSize = 10;
71
+ instance.notifications = false;
72
+ return instance;
73
+ }
74
+ }
75
+ ```
76
+
77
+ Generated output:
78
+
79
+ ```typescript
80
+ class UserSettings {
81
+ theme: string;
82
+
83
+ pageSize: number;
84
+
85
+ notifications: boolean; // Uses type default: false
86
+
87
+ static defaultValue(): UserSettings {
88
+ const instance = new UserSettings();
89
+ instance.theme = 'light';
90
+ instance.pageSize = 10;
91
+ instance.notifications = false;
92
+ return instance;
93
+ }
94
+ }
73
95
  ```
74
96
 
75
97
  ## Enum Defaults
76
98
 
77
99
  For enums, mark one variant with `@default`:
78
100
 
101
+ ```typescript before
102
+ /** @derive(Default) */
103
+ enum Status {
104
+ /** @default */
105
+ Pending,
106
+ Active,
107
+ Completed
108
+ }
109
+ ```
110
+
111
+ ```typescript after
112
+ enum Status {
113
+ /** @default */
114
+ Pending,
115
+ Active,
116
+ Completed
117
+ }
118
+
119
+ export function statusDefaultValue(): Status {
120
+ return Status.Pending;
121
+ }
122
+
123
+ export const Status = {
124
+ defaultValue: statusDefaultValue
125
+ } as const;
126
+ ```
127
+
128
+ Generated output:
129
+
79
130
  ```typescript
80
- @derive(Default)
81
131
  enum Status {
82
- @default
132
+ /** @default */
83
133
  Pending,
84
134
  Active,
85
135
  Completed
86
136
  }
87
137
 
88
- // Generated:
89
- // export namespace Status {
90
- // export function defaultValue(): Status {
91
- // return Status.Pending;
92
- // }
93
- // }
138
+ export function statusDefaultValue(): Status {
139
+ return Status.Pending;
140
+ }
141
+
142
+ export const Status = {
143
+ defaultValue: statusDefaultValue
144
+ } as const;
94
145
  ```
95
146
 
96
147
  ## Error Handling
@@ -0,0 +1,11 @@
1
+ ## Cycle/Forward-Reference Support
2
+
3
+ Uses deferred patching to handle references:
4
+
5
+ 1. When encountering `{ "__ref": id }`, returns a `PendingRef` marker
6
+ 2. Continues deserializing other fields
7
+ 3. After all objects are created, `ctx.applyPatches()` resolves all pending references
8
+
9
+ References only apply to object-shaped, serializable values. The generator avoids probing for
10
+ `__ref` on primitive-like fields (including literal unions and `T | null` where `T` is primitive-like),
11
+ and it parses `Date` / `Date | null` from ISO strings without treating them as references.