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

Builder classes for service and endpoint #1097

Conversation

GaryAghedo
Copy link
Contributor

@GaryAghedo GaryAghedo commented Jul 18, 2023

Closes #836.

Copy link
Member

@kubukoz kubukoz left a comment

Choose a reason for hiding this comment

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

Thanks for kicking this off! I took your code as a baseline and implemented the endpoint transformation function in the service mapper. I'm not sure it's fully correct, we'll have to get @Baccata's take on this, but I think we're onto something.

We'll need some tests before this can be merged, there are probably also other things...

modules/core/src/smithy4s/Service.scala Outdated Show resolved Hide resolved
def mapInput(f: Schema[I] => Schema[I]): Builder[I, E, O, SI, SO] =
copy(baseInput = f(baseInput))

def withOutput(output: Schema[O]): Builder[I, E, O, SI, SO] =
Copy link
Member

Choose a reason for hiding this comment

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

question: should we allow using a schema of a different type (another O, in this case)? I'm thinking yes, because it's certainly possible.

However, when that's used in conjunction with a service builder, I think we'd be pretty limited here - not only because PolyFunction5 forbids changing type parameters, but also I don't think we can change the operation type (which would be necessary to keep things like def endpoint: (I, Endpoint) working).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there could eventually be two flavours of builders :

  1. One for the static usecase, that respects all the types, which probably means that the only possible transformations will be hints and labels
  2. One that would be more useful in the context of dynamic services, where we could amend both the types involved in operations, and the list of operations

I believe this PR is only dealing with point 1 (which is totally fine). In this context, you shouldn't allow for different types.

@GaryAghedo GaryAghedo marked this pull request as ready for review July 21, 2023 16:05
modules/core/src/smithy4s/Endpoint.scala Show resolved Hide resolved
def mapEndpointEach(
mapper: PolyFunction5[Endpoint.ForOperation[Op]#e, Endpoint.ForOperation[Op]#e]
): Builder[Alg, Op] = copy(
endpointMapper = (endpointMapper.andThen(mapper)).unsafeCacheBy(
Copy link
Member

Choose a reason for hiding this comment

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

thought: this transformation is kind of lazy (only happens when you call .build), perhaps we should document that in its Scaladoc.

also, perhaps we should only cache it inside build, otherwise if you call mapEndpointEach multiple times you get multiple layers of caching.

Copy link
Contributor

Choose a reason for hiding this comment

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

NB : syncing with series 0.18  will remove unsafeCacheBy, but it's okay because the exposure of ordinals should remove the need to cache.

Copy link
Member

Choose a reason for hiding this comment

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

it did, because we got rid of def endpoint. We'll defer to the default impl, unless you prefer otherwise.

modules/core/src/smithy4s/Service.scala Show resolved Hide resolved
modules/core/src/smithy4s/Service.scala Outdated Show resolved Hide resolved
build.sbt Outdated Show resolved Hide resolved
@kubukoz kubukoz requested a review from Baccata August 14, 2023 21:24
@kubukoz
Copy link
Member

kubukoz commented Aug 17, 2023

@Baccata can you take another look?

Copy link
Contributor

@Baccata Baccata left a comment

Choose a reason for hiding this comment

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

Thanks !

@Baccata Baccata merged commit ca01208 into disneystreaming:series/0.18 Aug 18, 2023
10 checks passed
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.

Create Builder data classes for Service and Endpoint
3 participants