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

Allow nested seed packets #2

Open
5 tasks
jkomoros opened this issue Jun 17, 2023 · 3 comments
Open
5 tasks

Allow nested seed packets #2

jkomoros opened this issue Jun 17, 2023 · 3 comments

Comments

@jkomoros
Copy link
Owner

jkomoros commented Jun 17, 2023

A SeedPacket where the seeds have instead of SeedRef, a SeedData, which is expanded to be a topline seed.

  • Add a id field to seeds (which is validated to verify it matches the local ID) since some seeds will otherwise have implied IDs. If it's not filled in then it will be filled in with a generic and deterministic ID so you don't HAVE to create one
  • expandSeedData should actually unroll seeds
  • Add tests for nested data (and all ID auto-generating behavior)
  • Clean up naming (e.g. Nested for nested types, versus the current of empty for input and Expanded (confusingly) for ones that aren't nested)
  • Document
jkomoros added a commit that referenced this issue Jun 24, 2023
jkomoros added a commit that referenced this issue Jun 24, 2023
Currently they're the same exact types, just aliases.

The idea is that the non-expanded are the raw packet, and might include nested seeds.

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
…ough, but will soon allow nested seeds.

Part of #2.
@jkomoros
Copy link
Owner Author

This is being developed on branch nested-seeds. It's really finicky to do automatic type squanching to not repeat yourself with the seed data types (and also they need to be self-referencing!)

@jkomoros
Copy link
Owner Author

First look at how zod.required works.

Replicate that with a thing that puts a distinctive sentinel in place every time it finds a seedReference.

Then process the union of seed data and make the nested one too automatically

Then do the lazy/recursive thing. Make expandSeedData throw if it finds one that doesn’t work.

Then make expandSeedData work with nested data (if id is set, use that. If not, use the id from parent plus a dash and the parent peppery name

jkomoros added a commit that referenced this issue Jun 24, 2023
It's a no op in terms of typing.

Having a helper like this makes it a step more likely to automatically factor out making nested versions.

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
…shape.

No semantic difference yet, but getting more of the type construction automated.

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
…alue automatically.

No semantic difference, just the type construction for seed data is automated.

There's a cast in there (as Shape) that doesn't feel right, but it still works so 🤷

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
Everything builds and runs, but if you try to grow a sub-seed that was nested, it will fail with an invalid id warning because expandSeedData doesn't yet know how to properly unroll nested seeds.

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
jkomoros added a commit that referenced this issue Jun 24, 2023
jkomoros added a commit that referenced this issue Jun 24, 2023
…ypes.

makeNestedSeedData is harder to do because of the recursive typing.

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
Just do the same typescript rewriting as done for makeSeedData. Left a comment in a few of the places where the typescript type is wrong to remind myself.

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
This will help enumerate through keys in expandSeedData.

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
…ted seed.

For now it just barfs with an error. Note this means that tests currently pass, but if you run `garden` it will bail because `default.json` has a nested seed, so the seed packet will fail to parse.

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
Actually, I don't know why this works, but it does seem to work in the `garden` command at least for `nested-example`.

Part of #2.
jkomoros added a commit that referenced this issue Jun 24, 2023
jkomoros added a commit that referenced this issue Jun 24, 2023
jkomoros added a commit that referenced this issue Jun 25, 2023
jkomoros added a commit that referenced this issue Jun 25, 2023
One doesn't yet pass so commented out.

Part of #2.
jkomoros added a commit that referenced this issue Jun 25, 2023
Before, the seedRference would notice things with an 'id' and match first. But we want to check for the more restrictive seedData first, because if seedReference is matched first we won't find named
sub-seeds, they'll be removed by the seedPacket.parse.

Part of #2.
jkomoros added a commit that referenced this issue Jun 25, 2023
jkomoros added a commit that referenced this issue Jun 25, 2023
jkomoros added a commit that referenced this issue Jun 25, 2023
Part of #2.

Merge branch 'nested-seeds'

* nested-seeds: (25 commits)
  Document nested seeds in README.
  Add another matching test for behavior from two commits ago.
  Add a test that now behaves correctly from last commit.
  Change order of union of types in makeNestedSeedReferenceProperty.
  Add a bunch of expandSeedPacket tests.
  Add a basic test for nested examples.
  Document the makeNestedSeedData problem, pointing at issue #16.
  In expandSeedData, leave behind nested seeds with proper SeedReference.
  Make expandSeedID return the ID it actually chose.
  Made expandSeedData correctly recurse into nested seeds and unroll them.
  Made it so expandSeedData will use the override id set within a seed if set.
  expandSeedData recurses through items and detects when it finds a nested seed.
  Create SeedDataReservedKeys.
  Do a hack of a fix in makeNestedSeedData.
  Fix typescript typing of makeSeedData to have the proper typescript types.
  Add a TODO based on a bug I just realized in typing.
  Clean up proper types of SeedData and expandSeedData.
  Redefine SeedPacket to actually allow nesting of any seed reference.
  Unexport the seedData* Zod types, since we'll have a larger number now.
  Make it so makeSeedData runs the makeSeedReferenceProperty on every value automatically.
  ...
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

1 participant