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

Schema for key-value lists? #53

Open
m-haug opened this issue Feb 6, 2025 · 3 comments
Open

Schema for key-value lists? #53

m-haug opened this issue Feb 6, 2025 · 3 comments

Comments

@m-haug
Copy link

m-haug commented Feb 6, 2025

I've had a few cases of schemas where I want users to specify a list of key-value pairs with unique keys as a dictionary. Apart from being unique, I don't have any requirements on the keys, but all values should follow a common schema.

However, valkyrie does not support this use case currently, as it seems. Would this be something you would consider?

@tingerrr
Copy link
Member

tingerrr commented Feb 6, 2025

Can you show an example of what you mean? A dictionary schema should already suffice if I understand correctly.

@m-haug
Copy link
Author

m-haug commented Feb 7, 2025

I want users to specify something like

(
  monday: (location: "home", mood: "good"),
  tuesday: (location: "office", mood: "neutral"),
  "thursday afternoon": (location: "dentist", mood: "anxious"),
)

Essentially, I want to apply a schema to the dictionary's values, regardless of the key. In most cases, the keys are chosen by users, so they can't be known beforehand. The existing dictionary schema requires naming keys explicitly, AFAIK.

So far, I have been working around it with a two schemas in parse, the first ensuring it is a dictionary and converting using dict.pairs() and then the second verifying the value schema against that.

@tingerrr
Copy link
Member

tingerrr commented Feb 7, 2025

Ok, I see. I'm sure we could add this as a new schema type, but in theory the building blocks should already be there by creating your own schema. I've tried around a bit, but I must admit that I couldn't really get it to work correctly at the moment.

We'll see if @jamesrswift responds in the near future regarding the next release in wake of Typst 0.13, valkyrie ought to get a proper manual.

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

No branches or pull requests

2 participants