Skip to content

fix: improve FunctionRegion type safety and API consistency #759

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

grdsdev
Copy link
Collaborator

@grdsdev grdsdev commented Jul 30, 2025

Summary

  • Change FunctionRegion from enum to struct with RawRepresentable for better extensibility
  • Add ExpressibleByStringLiteral conformance for improved ergonomics
  • Update FunctionsClient to use FunctionRegion? instead of String? for type safety
  • Remove duplicate initializers and @_disfavoredOverload annotations
  • Update tests to work with new type structure

Previously, we maintained method overloads to accept both String (for regions not yet supported by the client) and FunctionRegion. With these changes, we now have a single FunctionRegion type that, due to its ExpressibleByStringLiteral conformance, allows passing any new region string, even if not yet supported by the client.

This eliminates the need for duplicate method overloads while maintaining the same functionality and improving type safety across the API.

Breaking Changes and Migration

This changes brings more maintainability for the codebase, but it may introduce some breaking changes dependending on how it is being used by customers.

  • When using String from a variable and not a literal
let region = "custom-region"
try await functions.invoke(
  "hello",
  options: .init(region: region) // ❌ Compiler error
)

Solution

try await functions.invoke(
  "hello",
  options: .init(region: "custom-region") // ✅ Use literal string directly
)

Or

let region = "custom-region" as FunctionRegion // ✅ Cast string to FunctionRegion
try await functions.invoke(
  "hello",
  options: .init(region: region)
)

Test plan

  • Run existing unit tests to ensure backward compatibility
  • Verify function invocation with different regions still works
  • Test string literal assignment to FunctionRegion works as expected

🤖 Generated with Claude Code

@grdsdev grdsdev changed the title refactor: improve FunctionRegion type safety and API consistency fix: improve FunctionRegion type safety and API consistency Jul 30, 2025
- Change FunctionRegion from enum to struct with RawRepresentable
- Add ExpressibleByStringLiteral conformance for better ergonomics
- Update FunctionsClient to use FunctionRegion? instead of String?
- Remove duplicate initializers and @_disfavoredOverload annotations
- Update tests to work with new type structure

This change improves type safety while maintaining backward compatibility
and provides a cleaner API surface for function region configuration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@grdsdev grdsdev force-pushed the refactor/function-region-type branch from d546438 to f83ccfd Compare July 30, 2025 15:08
@grdsdev grdsdev requested review from mandarini and o-santi July 30, 2025 15:30
@grdsdev grdsdev marked this pull request as draft July 30, 2025 16:00
@grdsdev grdsdev removed request for mandarini and o-santi July 30, 2025 16:00
@grdsdev grdsdev added this to the v3 milestone Jul 31, 2025
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