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

Static Schema Index #1364

Closed
kubukoz opened this issue Jan 16, 2024 · 2 comments
Closed

Static Schema Index #1364

kubukoz opened this issue Jan 16, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@kubukoz
Copy link
Member

kubukoz commented Jan 16, 2024

Currently, we have DynamicSchemaIndex which has roughly these functions:

  • schemas: List[Schema[_]]
  • services: List[Service[_]]
  • metadata: Map[String, Document]

It's only useful in Dynamic, of course, which implies that you have a runtime instance of dynamic.Model, which is hard to construct if you don't have a JSON dump of a model, or you're on the JVM and have a smithy-model Model.

Looking up schemas at runtime could be useful in certain usecases, like if you have an idRef trait somewhere and want to do more with it. To me, the really useful bit would be looking up metadata: currently, any metadata you want to access at runtime in the "static" world of Smithy4s has to be copied into a trait (so that it's available as a hint).

A potential solution to this inconvenience would be to have some sort of "static schema index" type. Its interface could be well-defined in smithy4s (and quite similar to DSI, if not the same type), and we'd generate an object implementing it, somewhere - this could be like BuildInfo.

There are a couple problems with this:

  • users would have to pass this (static) SchemaIndex (let's call it SSI from now on) to the interpreters somehow, and even if it's an implicit, it'd be an orphan instance - so an import would be necessary
  • "staged" codegen: smithy4s allows generating some code in one module, then some more code in another module, then some more. In fact, these modules needn't be aware of each other, and could be pulled in by an application that doesn't even use codegen. How do we "gather" all the "sub-indexes"?
  • (possibly simpler) where do we put this object? Especially if there's going to be more than one of these on the classpath.

Random ideas:

  • assume we only support apps that do have the codegen plugin? (so that there's always "a place to gather things in and generate")
  • store a list of shapes/services/metadata in the smithy4sGenerated.smithy file, and then render a file made from that?
  • file size: a static schema index is likely going to be an enormous string, and we have to be mindful of the limitations of Scala, the JVM, as well as JS/native.

The more I write about it the more I think this is an insane and overcomplicated idea, but it's good to at least have some reasons written down for why it's going to be a problem.

@kubukoz kubukoz added the enhancement New feature or request label Jan 16, 2024
@Baccata
Copy link
Contributor

Baccata commented Jan 16, 2024

That's a big no for me, in that it's a fair bit of maintenance burden for a usecase that has yet to find proper motivation. The only point that I'd consider accepting at this time, in smithy4s is this :

store a list of shapes/services/metadata in the smithy4sGenerated.smithy file

I think that'd be acceptable : we could render aMap[ShapeId, FQN] in the metadata. This would empower you to develop a third party build plugin downstream to render your static schema indexes without requiring tribal knowledge of how things get rendered and what are the escaping rules. Later on, if/when you prove the relevance of the idea, we could revisit upstreaming it here.

@kubukoz
Copy link
Member Author

kubukoz commented Mar 11, 2024

Replacing with #1436

@kubukoz kubukoz closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants