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

Use shapeless records to parse `properties` and extensions #128

Open
jisantuc opened this issue Jun 13, 2019 · 0 comments

Comments

@jisantuc
Copy link
Member

commented Jun 13, 2019

According to the STAC spec for items, datetime is required, and title is common. Other extensions define more fields that should be in properties. In the current implementation, we just say "hey man, it's an object, best of luck" -- https://github.com/geotrellis/geotrellis-server/pull/122/files#diff-fe86990cd1594794f235a75cdf28870c -- which isn't super helpful for end users. We can't however just say "it's one of these case classes and only one of these case classes," because any number of extensions should be available.

However! There's a light at the end of this tunnel. Because extensions have specific shapes that they expect in properties, we can build shapeless records to match those shapes, try to decode all of them, and then just ++ them up at the end, parameterizing StacItem over the type of properties, and just asking that we know how to encode and decode whatever the type of properties is.

The record types we build should be aliased, because otherwise we'll end up surfacing this absolute trainwreck to end-users:

@ val y = ("baz" ->> "yup") :: HNil
@ typeOf(y) 
res9: reflect.runtime.package.universe.Type = TypeRef(
  ThisType(package shapeless),
  class ::,
  List(
    RefinedType(
      List(
        TypeRef(ThisType(package lang), class String, List()),
        TypeRef(SingleType(ThisType(package shapeless), object labelled), trait KeyTag, List(ConstantType(Constant("baz")), TypeRef(ThisType(package lang), class String, List())))
      ),
      SynchronizedOps()
    ),
    TypeRef(ThisType(package shapeless), trait HNil, List())
  )
)
@jisantuc jisantuc added the STAC label Jun 13, 2019
jisantuc added a commit to jisantuc/geotrellis-server that referenced this issue Sep 6, 2019
This is done not the right way exactly, since all STAC links,
regardless of enabled extensions, require the fields. But there's not
a great way around that with handling other extensions until we solve
a hard problem (see geotrellis#128)
jisantuc added a commit that referenced this issue Sep 10, 2019
* Add Source StacLinkType

see label extension docs:
https://github.com/radiantearth/stac-spec/tree/dev/extensions/label#links-source-imagery

* Make StacItem uri -> cogUri, and an option

* Include source in serde tests

* Update changelog

* Mark stac item change as breaking

* Add new required fields stac_version and stac_extensions

* Add item collection

* Fixup test implicits for item and item collection

* Add label:assets to stac links

This is done not the right way exactly, since all STAC links,
regardless of enabled extensions, require the fields. But there's not
a great way around that with handling other extensions until we solve
a hard problem (see #128)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.