From de54e81c77e6ec0276b55a8ef6289f4fb21e1a0f Mon Sep 17 00:00:00 2001 From: Mark Xue Date: Tue, 27 Oct 2026 14:32:32 -0700 Subject: [PATCH 1/2] Decode PDS no-op bodies on putRecord and deleteRecord outputs The lexicons require only uri and cid on putRecord/createRecord output and nothing on deleteRecord output. A PDS omits commit when the write is a no-op (identical record, or deleting a missing record), so commit is now optional. validationStatus is optional and an open knownValues string. Co-Authored-By: Claude Sonnet 5.5 (cherry picked from commit 8d809ff90804ac1de8f1338fb807759e3acc13d8) --- .changeset/optional-write-commit.md | 5 + .../Com/Atproto/Repo/DeleteRecord.swift | 5 +- .../Lexicon/Com/Atproto/Repo/PutRecord.swift | 22 +++-- .../RepoWriteOutputDecodingTests.swift | 99 +++++++++++++++++++ 4 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 .changeset/optional-write-commit.md create mode 100644 Tests/AtprotoTypesTests/RepoWriteOutputDecodingTests.swift diff --git a/.changeset/optional-write-commit.md b/.changeset/optional-write-commit.md new file mode 100644 index 0000000..4a3c325 --- /dev/null +++ b/.changeset/optional-write-commit.md @@ -0,0 +1,5 @@ +--- +"@germ-network/atprototypes": minor +--- + +`PutRecordOutput.commit`, `PutRecordOutput.validationStatus` and `DeleteRecordOutput.commit` are now optional, so a PDS no-op (identical record, or deleting a missing record) decodes. `PutRecordOutput.ValidationStatus` is now an open `RawRepresentable` struct with `.valid` and `.unknown`, so unrecognized values decode instead of throwing. diff --git a/Sources/AtprotoTypes/Lexicon/Com/Atproto/Repo/DeleteRecord.swift b/Sources/AtprotoTypes/Lexicon/Com/Atproto/Repo/DeleteRecord.swift index 027d66a..c4b0494 100644 --- a/Sources/AtprotoTypes/Lexicon/Com/Atproto/Repo/DeleteRecord.swift +++ b/Sources/AtprotoTypes/Lexicon/Com/Atproto/Repo/DeleteRecord.swift @@ -61,9 +61,10 @@ extension Lexicon.Com.Atproto.Repo { } public struct DeleteRecordOutput: Codable, Sendable { - public let commit: Defs.CommitMeta + ///Absent when the record did not exist. + public let commit: Defs.CommitMeta? - public init(commit: Defs.CommitMeta) { + public init(commit: Defs.CommitMeta?) { self.commit = commit } } diff --git a/Sources/AtprotoTypes/Lexicon/Com/Atproto/Repo/PutRecord.swift b/Sources/AtprotoTypes/Lexicon/Com/Atproto/Repo/PutRecord.swift index ca1857f..00b2624 100644 --- a/Sources/AtprotoTypes/Lexicon/Com/Atproto/Repo/PutRecord.swift +++ b/Sources/AtprotoTypes/Lexicon/Com/Atproto/Repo/PutRecord.swift @@ -70,19 +70,27 @@ extension Lexicon.Com.Atproto.Repo { public struct PutRecordOutput: Codable, Sendable { public let uri: String public let cid: String - public let commit: Defs.CommitMeta - public let validationStatus: ValidationStatus + ///Absent when the write was a no-op: the record was identical to the live one. + public let commit: Defs.CommitMeta? + public let validationStatus: ValidationStatus? - public enum ValidationStatus: String, Sendable, Codable { - case valid - case unknown + ///Lexicon knownValues: an open set, so an unrecognized value still decodes. + public struct ValidationStatus: RawRepresentable, Codable, Hashable, Sendable { + public let rawValue: String + + public init(rawValue: String) { + self.rawValue = rawValue + } + + public static let valid = Self(rawValue: "valid") + public static let unknown = Self(rawValue: "unknown") } public init( uri: String, cid: String, - commit: Defs.CommitMeta, - validationStatus: ValidationStatus + commit: Defs.CommitMeta?, + validationStatus: ValidationStatus? ) { self.uri = uri self.cid = cid diff --git a/Tests/AtprotoTypesTests/RepoWriteOutputDecodingTests.swift b/Tests/AtprotoTypesTests/RepoWriteOutputDecodingTests.swift new file mode 100644 index 0000000..015189d --- /dev/null +++ b/Tests/AtprotoTypesTests/RepoWriteOutputDecodingTests.swift @@ -0,0 +1,99 @@ +// +// RepoWriteOutputDecodingTests.swift +// AtprotoTypes +// + +import AtprotoTypes +import Foundation +import GermConvenience +import GermConvenienceHTTP +import HTTPTypes +import Testing + +//The lexicons require only `uri` and `cid` on putRecord/createRecord output and +//nothing on deleteRecord output. A PDS omits `commit` when the write is a no-op +//(an identical record, or deleting a record that doesn't exist), and +//`validationStatus` is an open knownValues string. +struct RepoWriteOutputDecodingTests { + typealias PutRecord = Lexicon.Com.Atproto.Repo.PutRecord< + PutRecordSwapEncodingTests.Thing + > + typealias DeleteRecord = Lexicon.Com.Atproto.Repo.DeleteRecord< + PutRecordSwapEncodingTests.Thing + > + + static let uri = "at://did:plc:abcdefghijklmnopqrstuvwx/example.thing/self" + static let cid = PutRecordSwapEncodingTests.cidString + static let rev = "3lbwqrstuvwxy" + + static func ok(_ json: String) -> HTTPDataResponse { + .init(data: Data(json.utf8), response: .init(status: .ok)) + } + + static func parsed( + _: P.Type, _ json: String + ) throws -> P.Output { + let parsed = try P.parse(fullResponse: ok(json)) + guard case .ok(let output) = parsed else { + Issue.record("expected .ok, got \(parsed)") + throw ParseFailed() + } + return output + } + struct ParseFailed: Error {} + + @Test func putRecordNoOpWithoutCommitParses() throws { + let output = try Self.parsed( + PutRecord.self, + #"{"uri":"\#(Self.uri)","cid":"\#(Self.cid)","validationStatus":"valid"}"#) + #expect(output.uri == Self.uri) + #expect(output.cid == Self.cid) + #expect(output.commit == nil) + #expect(output.validationStatus == .valid) + } + + @Test func putRecordWithoutValidationStatusParses() throws { + let output = try Self.parsed( + PutRecord.self, + #"{"uri":"\#(Self.uri)","cid":"\#(Self.cid)","commit":{"cid":"\#(Self.cid)","rev":"\#(Self.rev)"}}"# + ) + #expect(output.cid == Self.cid) + #expect(output.validationStatus == nil) + } + + @Test func putRecordUnrecognizedValidationStatusParses() throws { + let output = try Self.parsed( + PutRecord.self, + #"{"uri":"\#(Self.uri)","cid":"\#(Self.cid)","commit":{"cid":"\#(Self.cid)","rev":"\#(Self.rev)"},"validationStatus":"deferred"}"# + ) + #expect(output.validationStatus?.rawValue == "deferred") + } + + @Test func putRecordWriteKeepsCommit() throws { + let output = try Self.parsed( + PutRecord.self, + #"{"uri":"\#(Self.uri)","cid":"\#(Self.cid)","commit":{"cid":"\#(Self.cid)","rev":"\#(Self.rev)"},"validationStatus":"valid"}"# + ) + #expect(output.commit?.rev.rawValue == Self.rev) + #expect(output.validationStatus == .valid) + } + + @Test func deleteRecordNoOpEmptyBodyParses() throws { + let output = try Self.parsed(DeleteRecord.self, "{}") + #expect(output.commit == nil) + } + + @Test func validationStatusEncodesAsBareString() throws { + let data = try JSONEncoder().encode( + Lexicon.Com.Atproto.Repo.PutRecordOutput.ValidationStatus.valid) + #expect(String(decoding: data, as: UTF8.self) == #""valid""#) + } + + @Test func absentCommitIsOmittedWhenEncoding() throws { + let output = Lexicon.Com.Atproto.Repo.PutRecordOutput( + uri: Self.uri, cid: Self.cid, commit: nil, validationStatus: nil) + let json = String(decoding: try JSONEncoder().encode(output), as: UTF8.self) + #expect(!json.contains("commit")) + #expect(!json.contains("validationStatus")) + } +} From 8fc88ee4d6ef9c955c558263d0bb5bdd02eb6d32 Mon Sep 17 00:00:00 2001 From: Anna M Date: Fri, 13 Nov 2026 15:39:59 -0800 Subject: [PATCH 2/2] Adapt optional-commit backport to 0.5.x and release 0.5.2 The test fixture came from 0.8.0's PutRecordSwapEncodingTests and its GermConvenienceHTTP import from 0.6.1; inline the fixture and drop the import. Adds the rsky shape (uri + cid only, on every write), which is what breaks Blacksky accounts. Changeset folded into CHANGELOG by hand: release automation only runs from main. Co-Authored-By: Claude Opus 5.5 --- .changeset/optional-write-commit.md | 5 --- CHANGELOG.md | 6 ++++ .../RepoWriteOutputDecodingTests.swift | 36 ++++++++++++++----- package.json | 2 +- 4 files changed, 35 insertions(+), 14 deletions(-) delete mode 100644 .changeset/optional-write-commit.md diff --git a/.changeset/optional-write-commit.md b/.changeset/optional-write-commit.md deleted file mode 100644 index 4a3c325..0000000 --- a/.changeset/optional-write-commit.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@germ-network/atprototypes": minor ---- - -`PutRecordOutput.commit`, `PutRecordOutput.validationStatus` and `DeleteRecordOutput.commit` are now optional, so a PDS no-op (identical record, or deleting a missing record) decodes. `PutRecordOutput.ValidationStatus` is now an open `RawRepresentable` struct with `.valid` and `.unknown`, so unrecognized values decode instead of throwing. diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d01791..ed6337b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @germ-network/atprototypes +## 0.5.2 + +### Patch Changes + +- Backport of [#75](https://github.com/germ-network/AtprotoTypes/pull/75) (`8d809ff`, released in 0.10.0) for consumers still on 0.5.x. `PutRecordOutput.commit`, `PutRecordOutput.validationStatus` and `DeleteRecordOutput.commit` are now optional, so a PDS no-op (identical record, or deleting a missing record) decodes. `PutRecordOutput.ValidationStatus` is now an open `RawRepresentable` struct with `.valid` and `.unknown`, so unrecognized values decode instead of throwing. + ## 0.5.1 ### Patch Changes diff --git a/Tests/AtprotoTypesTests/RepoWriteOutputDecodingTests.swift b/Tests/AtprotoTypesTests/RepoWriteOutputDecodingTests.swift index 015189d..472fd82 100644 --- a/Tests/AtprotoTypesTests/RepoWriteOutputDecodingTests.swift +++ b/Tests/AtprotoTypesTests/RepoWriteOutputDecodingTests.swift @@ -6,7 +6,6 @@ import AtprotoTypes import Foundation import GermConvenience -import GermConvenienceHTTP import HTTPTypes import Testing @@ -15,15 +14,27 @@ import Testing //(an identical record, or deleting a record that doesn't exist), and //`validationStatus` is an open knownValues string. struct RepoWriteOutputDecodingTests { - typealias PutRecord = Lexicon.Com.Atproto.Repo.PutRecord< - PutRecordSwapEncodingTests.Thing - > - typealias DeleteRecord = Lexicon.Com.Atproto.Repo.DeleteRecord< - PutRecordSwapEncodingTests.Thing - > + struct Thing: Atproto.Record { + struct Collection: Atproto.RecordType { + static var nsid: Atproto.NSID { .init(string: "example.thing") } + init() {} + init(from decoder: any Decoder) throws { self.init() } + func encode(to encoder: any Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(Self.nsid.rawValue) + } + } + typealias Key = Atproto.LiteralSelfRecordKey + var nsid: Collection { .init() } + var name = "x" + private enum CodingKeys: String, CodingKey { case name } + } + + typealias PutRecord = Lexicon.Com.Atproto.Repo.PutRecord + typealias DeleteRecord = Lexicon.Com.Atproto.Repo.DeleteRecord static let uri = "at://did:plc:abcdefghijklmnopqrstuvwx/example.thing/self" - static let cid = PutRecordSwapEncodingTests.cidString + static let cid = "bafyreibmcnkzbxtciyydktbatjlpgh5hollpov4zvpwtaaq353vyzfbxwu" static let rev = "3lbwqrstuvwxy" static func ok(_ json: String) -> HTTPDataResponse { @@ -52,6 +63,15 @@ struct RepoWriteOutputDecodingTests { #expect(output.validationStatus == .valid) } + //rsky (Blacksky's PDS) returns only these two fields on every write + @Test func putRecordUriAndCidOnlyParses() throws { + let output = try Self.parsed( + PutRecord.self, #"{"cid":"\#(Self.cid)","uri":"\#(Self.uri)"}"#) + #expect(output.uri == Self.uri) + #expect(output.commit == nil) + #expect(output.validationStatus == nil) + } + @Test func putRecordWithoutValidationStatusParses() throws { let output = try Self.parsed( PutRecord.self, diff --git a/package.json b/package.json index 0afbcf2..1be00f5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@germ-network/atprototypes", "private": true, - "version": "0.5.1", + "version": "0.5.2", "engines": { "node": ">=24" },