Skip to content

Generate Entity Codable bridge from @Entity macro - #19

Merged
colemancda merged 6 commits into
masterfrom
feature/macro
Jul 14, 2026
Merged

colemancda merged 6 commits into
masterfrom
feature/macro

Conversation

@colemancda

Copy link
Copy Markdown
Member

Summary

  • Extends the @Entity macro to generate concrete init(from: ModelData) throws and encode() -> ModelData implementations for each @Attribute/@Relationship property, calling ModelData.decode/encode(forKey:) and decodeRelationship/encodeRelationship(forKey:) directly — no Swift.Codable involved.
  • Removes the hand-written Person init/encode in TestModel.swift, now generated by the macro (it would otherwise conflict with the generated members).
  • Moves the old generic Codable-based bridge (Encoder.swift, Decoder.swift, and their CodingKey/CodingUserInfoKey support files) out of Sources/CoreModel and into Tests/CoreModelTests/LegacyCodable/. It's no longer part of the library's public surface, but stays exercised — CoreDataTests still calls its .encode(log:)/.init(from:userInfo:log:) overloads directly, while everything else now goes through the macro-generated zero-arg encode()/init(from:).

Test plan

  • swift test — 17/17 tests pass (both the macro-generated path and the relocated legacy bridge are exercised)
  • swift build -c release — passes
  • swift build --swift-sdk swift-6.3.2-RELEASE_wasm-embedded (macros disabled) — unaffected, still passes

Extends the macro to emit concrete init(from: ModelData) throws and
encode() -> ModelData implementations for each @Attribute/@relationship
property, using ModelData.decode/encode(forKey:) and
decodeRelationship/encodeRelationship(forKey:) directly. This removes
the need for the generic Codable-derived default implementation for
any type using the macro.
Now generated by the @entity macro; the hand-written version duplicated
the same behavior and would conflict with the macro-generated members.
Support code for the old Codable-based Entity bridge, which now lives
in Tests/CoreModelTests/LegacyCodable.
Support code for the old Codable-based Entity bridge, which now lives
in Tests/CoreModelTests/LegacyCodable.
No longer needed by the library now that the @entity macro generates
encode() directly; kept in Tests/CoreModelTests/LegacyCodable and still
exercised by CoreDataTests. Adds the CoreModel import the file now
needs as a separate module.
No longer needed by the library now that the @entity macro generates
init(from:) directly; kept in Tests/CoreModelTests/LegacyCodable and
still exercised by CoreDataTests. Adds the CoreModel import the file
now needs as a separate module.
@colemancda
colemancda merged commit d961a8b into master Jul 14, 2026
28 checks passed
@colemancda
colemancda deleted the feature/macro branch July 14, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant