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

feat: Open Source Schema #117

Merged
merged 4 commits into from
Jan 14, 2022
Merged

feat: Open Source Schema #117

merged 4 commits into from
Jan 14, 2022

Conversation

betterengineering
Copy link
Contributor

Overview

Internally, we've used schema to tell the mobile app what options to display to end users. We store the results in a database and that's how we populate config that's passed into main. This change puts that code in the public as it's the last piece required to get community apps ready for everyone.

Considerations

There's a few considerations here:

  • Schema defines the contract between starlark apps and the Tidbyt mobile app. New fields will require us to update the mobile app before they can be used in applets which makes it a bit wonky for an open source project. However, the benefit of having these fields available is that anyone can write applets that can be published to all Tidbyt users.
  • This code is pretty gnarly in places. The starlark bindings on go structs that embed other structs that do the validation is less than ideal - but the result is desirable. We have a module that looks very similar to the render module but still works with our internal apps that define schema somewhat differently. Getting everything cleaned up over time felt like a better tradeoff then waiting to get it right.
  • Not all fields are documented or have the syntactic sugar applied to them. I'm going to work on getting the rest of the fields populated over the next few days.

Changes

  • Open source starlarkutils.
    • This commit open sources starlarkutils that attaches a context to a running starlark thread. We need it to call schema handlers with a context.
  • Open source schema package.
    • This commit adds the schema package to the pixlet repo. Schema has an interface similar to render.
  • Added schema methods to applet.
    • This commit adds the necessary methods to runtime. Applet to be able to manage schema.
  • Added schema documentation.
    • This commit adds schema documentation.

Tests

These packages are pretty well tested - both with unit tests and through writing apps internally. But I also tested the integration by making sure the schema.star module loads and validates using pixlet:

mark@dev-mark:~/code/src/tidbyt.dev/pixlet|mark/open-source-schema ⇒  make build                                      
rm -f pixlet
rm -rf ./build
go build -o pixlet tidbyt.dev/pixlet
mark@dev-mark:~/code/src/tidbyt.dev/pixlet|mark/open-source-schema ⇒  ./pixlet render examples/schema_hello_world.star
mark@dev-mark:~/code/src/tidbyt.dev/pixlet|mark/open-source-schema ⇒  echo $?
0

This commit open sources starlarkutils that attaches a context to a
running starlark thread. We need it to call schema handlers with a
context.
This commit adds the schema package to the pixlet repo. Schema has an
interface similar to render.
This commit adds the necessary methods to runtime.Applet to be able to
manage schema.
This commit adds schema documentation.
@betterengineering betterengineering merged commit f8f71a2 into main Jan 14, 2022
@betterengineering betterengineering deleted the mark/open-source-schema branch January 14, 2022 03:41
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