Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Sources/StructuredQueriesCore/PrimaryKeyed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,31 @@ extension Delete where From: TableDraft {
self.where { $0.primaryKey.in(primaryKeys) }
}
}

import Foundation

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import Foundation statement is placed mid-file, immediately before the types that use UUID. While this works, it's more conventional in Swift to place all imports at the top of the file for better readability and consistency with the rest of the codebase. Consider moving this import to the top of the file.

Copilot uses AI. Check for mistakes.
public struct _DraftIdentifier: Hashable, CustomReflectable, Sendable {
public let rawValue: UUID
public init() {
rawValue = UUID()
}
public static func == (lhs: Self, rhs: Self) -> Bool {
true
}
public func hash(into hasher: inout Hasher) {
}
public var customMirror: Mirror {
Mirror(self, children: [])
}
}
public struct DraftIdentifier: Hashable, Sendable {
private let rawValue: _DraftIdentifier
public init(_ draftIdentifier: _DraftIdentifier) {
rawValue = draftIdentifier
}
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.rawValue.rawValue == rhs.rawValue.rawValue
}
public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue.rawValue)
}
}
Comment on lines +304 to +329

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _DraftIdentifier and DraftIdentifier types lack documentation comments. Since these are public types that users will interact with (via the generated draftIdentifier property), they should have documentation explaining their purpose and usage. Consider adding doc comments that explain:

  • _DraftIdentifier: An internal identifier type used to track draft instances, intentionally designed to not participate in equality comparisons
  • DraftIdentifier: A public wrapper that provides proper identity semantics for use with SwiftUI's ForEach and other identity-based APIs

Copilot uses AI. Check for mistakes.
8 changes: 8 additions & 0 deletions Sources/StructuredQueriesMacros/TableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ extension TableMacro: ExtensionMacro {
\(draftProperties, separator: "\n")
\(memberBlocks, separator: "\n")
\(memberwiseInit)
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body of the draftIdentifier computed property is not indented. The line DraftIdentifier(_draftIdentifier) should be indented to match the formatting of other generated code. This should be DraftIdentifier(_draftIdentifier) (with 2 spaces of indentation) to match the expected code style shown in the test snapshots.

Suggested change
DraftIdentifier(_draftIdentifier)
DraftIdentifier(_draftIdentifier)

Copilot uses AI. Check for mistakes.
}
Comment on lines +813 to +816

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated code references _DraftIdentifier and DraftIdentifier without module qualification. These types are defined in StructuredQueriesCore, so they should be qualified as \(moduleName)._DraftIdentifier() and \(moduleName).DraftIdentifier(_draftIdentifier) to be consistent with how other types from the core module are referenced (e.g., \(moduleName).TableDraft on line 808).

Copilot uses AI. Check for mistakes.
}
"""
// NB: End of workaround
Expand Down Expand Up @@ -1400,6 +1404,10 @@ extension TableMacro: MemberMacro {
\(draftProperties, separator: "\n")
\(memberBlocks, separator: "\n")
\(memberwiseInit)
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
Comment on lines +1407 to +1409

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated code references _DraftIdentifier and DraftIdentifier without module qualification. These types are defined in StructuredQueriesCore, so they should be qualified as \(moduleName)._DraftIdentifier() and \(moduleName).DraftIdentifier(_draftIdentifier) to be consistent with how other types from the core module are referenced (e.g., \(moduleName).TableDraft on line 1402).

Suggested change
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
private let _draftIdentifier = \(moduleName)._DraftIdentifier()
public var draftIdentifier: some Hashable {
\(moduleName).DraftIdentifier(_draftIdentifier)

Copilot uses AI. Check for mistakes.

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body of the draftIdentifier computed property is not indented. The line DraftIdentifier(_draftIdentifier) should be indented to match the formatting of other generated code. This should be DraftIdentifier(_draftIdentifier) (with 2 spaces of indentation) to match the expected code style shown in the test snapshots.

Suggested change
DraftIdentifier(_draftIdentifier)
DraftIdentifier(_draftIdentifier)

Copilot uses AI. Check for mistakes.
}
}
"""
// NB: End of workaround
Expand Down
60 changes: 60 additions & 0 deletions Tests/StructuredQueriesMacrosTests/TableMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ extension SnapshotTests {
self.email = email
self.age = age
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -1189,6 +1193,10 @@ extension SnapshotTests {
self.id = id
self.name = name
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -1706,6 +1714,10 @@ extension SnapshotTests {
self.id = id
self.referrerID = referrerID
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -1939,6 +1951,10 @@ extension SnapshotTests {
self.id = id
self.name = name
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -2114,6 +2130,10 @@ extension SnapshotTests {
self.id = id
self.seconds = seconds
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -2288,6 +2308,10 @@ extension SnapshotTests {
self.color = color
self.name = name
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -3149,6 +3173,10 @@ extension SnapshotTests {
) {
self.id = id
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -3423,6 +3451,10 @@ extension SnapshotTests {
self.id = id
self.name = name
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -3619,6 +3651,10 @@ extension SnapshotTests {
self.date = date
self.priority = priority
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -3761,6 +3797,10 @@ extension SnapshotTests {
) {
self.id = id
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -3985,6 +4025,10 @@ extension SnapshotTests {
self.id = id
self.title = title
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -4141,6 +4185,10 @@ extension SnapshotTests {
self.id = id
self.timestamps = timestamps
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -4283,6 +4331,10 @@ extension SnapshotTests {
) {
self.id = id
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -4463,6 +4515,10 @@ extension SnapshotTests {
self.reminderTitle = reminderTitle
self.remindersListTitle = remindersListTitle
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down Expand Up @@ -4632,6 +4688,10 @@ extension SnapshotTests {
self.id = id
self.userModificationDate = userModificationDate
}
private let _draftIdentifier = _DraftIdentifier()
public var draftIdentifier: some Hashable {
DraftIdentifier(_draftIdentifier)
}
}
}

Expand Down
26 changes: 14 additions & 12 deletions Tests/StructuredQueriesTests/TableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ extension SnapshotTests {
"""
} results: {
"""
┌───────────────────────────────────────────────────┐
│ SnapshotTests.TableTests.DefaultSelect.Row.Draft( │
│ id: 1, │
│ isDeleted: false │
│ ) │
└───────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────┐
│ SnapshotTests.TableTests.DefaultSelect.Row.Draft( │
│ id: 1, │
│ isDeleted: false, │
│ _draftIdentifier: StructuredQueriesCore._DraftIdentifier │
│ ) │
└────────────────────────────────────────────────────────────┘
"""
}
assertQuery(Row.select(\.id)) {
Expand Down Expand Up @@ -386,12 +387,13 @@ extension SnapshotTests {
"""
} results: {
"""
┌──────────────────────────────────────────────────┐
│ SnapshotTests.TableTests.DefaultWhere.Row.Draft( │
│ id: 1, │
│ isDeleted: false │
│ ) │
└──────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────┐
│ SnapshotTests.TableTests.DefaultWhere.Row.Draft( │
│ id: 1, │
│ isDeleted: false, │
│ _draftIdentifier: StructuredQueriesCore._DraftIdentifier │
│ ) │
└────────────────────────────────────────────────────────────┘
"""
}
assertQuery(Row.unscoped) {
Expand Down