@macroforge/mcp-server 0.1.37 → 0.1.39
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/docs/api/api-overview.md +13 -13
- package/docs/api/expand-sync.md +8 -8
- package/docs/api/native-plugin.md +15 -15
- package/docs/api/position-mapper.md +6 -6
- package/docs/api/transform-sync.md +11 -11
- package/docs/builtin-macros/clone.md +43 -23
- package/docs/builtin-macros/debug.md +50 -18
- package/docs/builtin-macros/default.md +79 -28
- package/docs/builtin-macros/deserialize/cycleforward-reference-support.md +11 -0
- package/docs/builtin-macros/deserialize/example.md +1625 -0
- package/docs/builtin-macros/deserialize/overview.md +15 -10
- package/docs/builtin-macros/deserialize/union-type-deserialization.md +27 -0
- package/docs/builtin-macros/deserialize/validation.md +34 -0
- package/docs/builtin-macros/deserialize.md +1608 -23
- package/docs/builtin-macros/hash.md +87 -20
- package/docs/builtin-macros/macros-overview.md +40 -40
- package/docs/builtin-macros/ord.md +56 -31
- package/docs/builtin-macros/partial-eq/example.md +526 -0
- package/docs/builtin-macros/partial-eq/overview.md +39 -0
- package/docs/builtin-macros/partial-eq.md +184 -26
- package/docs/builtin-macros/partial-ord.md +68 -30
- package/docs/builtin-macros/serialize/example.md +139 -0
- package/docs/builtin-macros/serialize/overview.md +32 -0
- package/docs/builtin-macros/serialize/type-specific-serialization.md +22 -0
- package/docs/builtin-macros/serialize.md +130 -28
- package/docs/concepts/architecture.md +2 -2
- package/docs/concepts/derive-system.md +25 -39
- package/docs/concepts/how-macros-work.md +8 -4
- package/docs/custom-macros/custom-overview.md +23 -23
- package/docs/custom-macros/rust-setup.md +31 -31
- package/docs/custom-macros/ts-macro-derive.md +107 -107
- package/docs/custom-macros/ts-quote.md +226 -226
- package/docs/getting-started/first-macro.md +38 -28
- package/docs/getting-started/installation.md +15 -15
- package/docs/integration/cli.md +9 -9
- package/docs/integration/configuration.md +16 -16
- package/docs/integration/mcp-server.md +6 -6
- package/docs/integration/svelte-preprocessor.md +40 -41
- package/docs/integration/typescript-plugin.md +13 -12
- package/docs/integration/vite-plugin.md +12 -12
- package/docs/language-servers/zed.md +1 -1
- package/docs/sections.json +88 -2
- package/package.json +2 -2
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
# Deserialize
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `Deserialize` macro generates JSON deserialization methods with **cycle and
|
|
4
|
+
forward-reference support**, plus comprehensive runtime validation. This enables
|
|
5
|
+
safe parsing of complex JSON structures including circular references.
|
|
4
6
|
|
|
5
|
-
##
|
|
7
|
+
## Generated Output
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
| Type | Generated Code | Description |
|
|
10
|
+
|------|----------------|-------------|
|
|
11
|
+
| Class | `classNameDeserialize(input)` + `static deserialize(input)` | Standalone function + static factory method |
|
|
12
|
+
| Enum | `enumNameDeserialize(input)`, `enumNameDeserializeWithContext(data)`, `enumNameIs(value)` | Standalone functions |
|
|
13
|
+
| Interface | `interfaceNameDeserialize(input)`, etc. | Standalone functions |
|
|
14
|
+
| Type Alias | `typeNameDeserialize(input)`, etc. | Standalone functions |
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
const json = '{"name":"Alice","age":30,"createdAt":"2024-01-15T10:30:00.000Z"}';
|
|
11
|
-
const user = User.fromJSON(JSON.parse(json));
|
|
16
|
+
## Return Type
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
All public deserialization methods return `Result<T, Array<{ field: string; message: string }>>`:
|
|
19
|
+
|
|
20
|
+
- `Result.ok(value)` - Successfully deserialized value
|
|
21
|
+
- `Result.err(errors)` - Array of validation errors with field names and messages
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
## Union Type Deserialization
|
|
2
|
+
|
|
3
|
+
Union types are deserialized based on their member types:
|
|
4
|
+
|
|
5
|
+
### Literal Unions
|
|
6
|
+
For unions of literal values (`"A" | "B" | 123`), the value is validated against
|
|
7
|
+
the allowed literals directly.
|
|
8
|
+
|
|
9
|
+
### Primitive Unions
|
|
10
|
+
For unions containing primitive types (`string | number`), the deserializer uses
|
|
11
|
+
`typeof` checks to validate the value type. No `__type` discriminator is needed.
|
|
12
|
+
|
|
13
|
+
### Class/Interface Unions
|
|
14
|
+
For unions of serializable types (`User | Admin`), the deserializer requires a
|
|
15
|
+
`__type` field in the JSON to dispatch to the correct type's `deserializeWithContext` method.
|
|
16
|
+
|
|
17
|
+
### Generic Type Parameters
|
|
18
|
+
For generic unions like `type Result<T> = T | Error`, the generic type parameter `T`
|
|
19
|
+
is passed through as-is since its concrete type is only known at the call site.
|
|
20
|
+
|
|
21
|
+
### Mixed Unions
|
|
22
|
+
Mixed unions (e.g., `string | Date | User`) check in order:
|
|
23
|
+
1. Literal values
|
|
24
|
+
2. Primitives (via `typeof`)
|
|
25
|
+
3. Date (via `instanceof` or ISO string parsing)
|
|
26
|
+
4. Serializable types (via `__type` dispatch)
|
|
27
|
+
5. Generic type parameters (pass-through)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
## Validation
|
|
2
|
+
|
|
3
|
+
The macro supports 30+ validators via `@serde(validate(...))`:
|
|
4
|
+
|
|
5
|
+
### String Validators
|
|
6
|
+
- `email`, `url`, `uuid` - Format validation
|
|
7
|
+
- `minLength(n)`, `maxLength(n)`, `length(n)` - Length constraints
|
|
8
|
+
- `pattern("regex")` - Regular expression matching
|
|
9
|
+
- `nonEmpty`, `trimmed`, `lowercase`, `uppercase` - String properties
|
|
10
|
+
|
|
11
|
+
### Number Validators
|
|
12
|
+
- `gt(n)`, `gte(n)`, `lt(n)`, `lte(n)`, `between(min, max)` - Range checks
|
|
13
|
+
- `int`, `positive`, `nonNegative`, `finite` - Number properties
|
|
14
|
+
|
|
15
|
+
### Array Validators
|
|
16
|
+
- `minItems(n)`, `maxItems(n)`, `itemsCount(n)` - Collection size
|
|
17
|
+
|
|
18
|
+
### Date Validators
|
|
19
|
+
- `validDate`, `afterDate("ISO")`, `beforeDate("ISO")` - Date validation
|
|
20
|
+
|
|
21
|
+
## Field-Level Options
|
|
22
|
+
|
|
23
|
+
The `@serde` decorator supports:
|
|
24
|
+
|
|
25
|
+
- `skip` / `skipDeserializing` - Exclude field from deserialization
|
|
26
|
+
- `rename = "jsonKey"` - Read from different JSON property
|
|
27
|
+
- `default` / `default = expr` - Use default value if missing
|
|
28
|
+
- `flatten` - Read fields from parent object level
|
|
29
|
+
- `validate(...)` - Apply validators
|
|
30
|
+
|
|
31
|
+
## Container-Level Options
|
|
32
|
+
|
|
33
|
+
- `denyUnknownFields` - Error on unrecognized JSON properties
|
|
34
|
+
- `renameAll = "camelCase"` - Apply naming convention to all fields
|