Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation warnings for package-internal APIs #315

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Libraries/Connect/PackageInternal/ConnectError+GRPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ extension ConnectError {
/// passed in the headers block for gRPC-Web.
///
/// - returns: A tuple containing the gRPC status code and an optional error.
@available(
swift,
deprecated: 100.0,
Copy link
Member

Choose a reason for hiding this comment

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

This could be misleading. Is it dangerous to use 1.1 instead? If we end up needing a minor release before we're actually ready to use Swift 6 package visibility, could we just bump this out to 1.2? Would that cause havoc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This refers to the version of Swift that this will be deprecated in - it's just an arbitrarily high number which doesn't show up in the warning message. Unfortunately, we cannot specify which version of the package something will be deprecated in as part of this macro

Copy link
Member

Choose a reason for hiding this comment

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

Oh. So why not set it to 6?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tested this out, but it triggers warnings if a consuming project upgrades their Package.swift to use Swift 6, which we don't want:

Screenshot 2024-10-19 at 8 42 01 AM

message: "This is an internal-only API which will be made package-private in Swift 6."
)
public static func parseGRPCHeaders(
_ headers: Headers?, trailers: Trailers?
) -> (grpcCode: Code, error: ConnectError?) {
Expand Down
30 changes: 30 additions & 0 deletions Libraries/Connect/PackageInternal/Envelope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ import SwiftProtobuf
/// to change. When the compiler supports it, this should be package-internal.**
///
/// Provides functionality for packing and unpacking (headers and length prefixed) messages.
@available(
swift,
deprecated: 100.0,
message: "This is an internal-only API which will be made package-private in Swift 6."
)
public enum Envelope {
/// The total number of bytes that will prefix a message.
@available(
swift,
deprecated: 100.0,
message: "This is an internal-only API which will be made package-private in Swift 6."
)
public static var prefixLength: Int {
return 5 // Header flags (1 byte) + message length (4 bytes)
}
Expand All @@ -35,6 +45,11 @@ public enum Envelope {
/// - parameter compression: Configuration to use for compressing the message.
///
/// - returns: Serialized/enveloped data for transmission.
@available(
swift,
deprecated: 100.0,
message: "This is an internal-only API which will be made package-private in Swift 6."
)
public static func packMessage(
_ source: Data, using compression: ProtocolClientConfig.RequestCompression?
) -> Data {
Expand Down Expand Up @@ -70,6 +85,11 @@ public enum Envelope {
///
/// - returns: A tuple that includes the header byte and the un-prefixed and decompressed
/// message.
@available(
swift,
deprecated: 100.0,
message: "This is an internal-only API which will be made package-private in Swift 6."
)
public static func unpackMessage(
_ source: Data, compressionPool: CompressionPool?
) throws -> (headerByte: UInt8, unpacked: Data) {
Expand All @@ -96,6 +116,11 @@ public enum Envelope {
/// - parameter packedData: The packed data to analyze.
///
/// - returns: True if the data is compressed.
@available(
swift,
deprecated: 100.0,
message: "This is an internal-only API which will be made package-private in Swift 6."
)
public static func isCompressed(_ packedData: Data) -> Bool {
return !packedData.isEmpty && (0b00000001 & packedData[0] != 0)
}
Expand All @@ -111,6 +136,11 @@ public enum Envelope {
/// - returns: The length of the next expected message in the packed data. If multiple chunks
/// are specified, this will return the length of the first. Returns -1 if there is
/// not enough prefix data to determine the message length.
@available(
swift,
deprecated: 100.0,
message: "This is an internal-only API which will be made package-private in Swift 6."
)
public static func messageLength(forPackedData data: Data) -> Int {
guard data.count >= self.prefixLength else {
return -1
Expand Down
5 changes: 5 additions & 0 deletions Libraries/Connect/PackageInternal/Headers+GRPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ extension Headers {
/// - parameter grpcWeb: Should be true if using gRPC-Web, false if gRPC.
///
/// - returns: A set of updated headers.
@available(
swift,
deprecated: 100.0,
message: "This is an internal-only API which will be made package-private in Swift 6."
)
public func addingGRPCHeaders(using config: ProtocolClientConfig, grpcWeb: Bool) -> Self {
var headers = self
headers[HeaderConstants.grpcAcceptEncoding] = config
Expand Down
5 changes: 5 additions & 0 deletions Libraries/Connect/PackageInternal/Trailers+gRPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ extension Trailers {
/// Identifies the status code from gRPC and gRPC-Web trailers.
///
/// - returns: The gRPC status code, if specified.
@available(
swift,
deprecated: 100.0,
message: "This is an internal-only API which will be made package-private in Swift 6."
)
public func grpcStatus() -> Code? {
return self[HeaderConstants.grpcStatus]?
.first
Expand Down
Loading