feat(Schema): preserve encodedKey across field reuse, spread, and mapFields#2198
Open
patroza wants to merge 8 commits into
Open
feat(Schema): preserve encodedKey across field reuse, spread, and mapFields#2198patroza wants to merge 8 commits into
patroza wants to merge 8 commits into
Conversation
Agent-Logs-Url: https://github.com/patroza/effect-smol/sessions/32848271-8151-4553-9929-2451da3e02ef Co-authored-by: patroza <42661+patroza@users.noreply.github.com>
Agent-Logs-Url: https://github.com/patroza/effect-smol/sessions/32848271-8151-4553-9929-2451da3e02ef Co-authored-by: patroza <42661+patroza@users.noreply.github.com>
Agent-Logs-Url: https://github.com/patroza/effect-smol/sessions/32848271-8151-4553-9929-2451da3e02ef Co-authored-by: patroza <42661+patroza@users.noreply.github.com>
Agent-Logs-Url: https://github.com/patroza/effect-smol/sessions/32848271-8151-4553-9929-2451da3e02ef Co-authored-by: patroza <42661+patroza@users.noreply.github.com>
Agent-Logs-Url: https://github.com/patroza/effect-smol/sessions/32848271-8151-4553-9929-2451da3e02ef Co-authored-by: patroza <42661+patroza@users.noreply.github.com>
Agent-Logs-Url: https://github.com/patroza/effect-smol/sessions/4ae338a3-dc81-4aa5-a0de-1d7b81d2919a Co-authored-by: patroza <42661+patroza@users.noreply.github.com>
Agent-Logs-Url: https://github.com/patroza/effect-smol/sessions/4ae338a3-dc81-4aa5-a0de-1d7b81d2919a Co-authored-by: patroza <42661+patroza@users.noreply.github.com>
🦋 Changeset detectedLatest commit: d483e23 The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Nice to see this come back. Would this work on classes too or only structs? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In effect v3, a struct field's encoded key rename traveled with the field. In effect-smol, renames only existed as a top-level
encodeKeysmapping on the struct AST, so:Struct.fields.xexposed the un-renamed encoded shapemapFields/Class.mapFieldsdropped the renameThis PR moves the rename from a struct-level concern to a field-local annotation and threads it through the type system so it survives reuse, spreading,
mapFields,encodeKeys, andflip ∘ flip.Approach
Two alternatives were considered:
encodedFields/encodedMapFieldson the struct or addingfields/mapFieldsto the return value ofS.encodedKeys. Keeps the rename at the struct level, still does not help when a single field schema is consumed by an unrelated struct.Schema.encodedKey("foo")combinator attaches anencodedKeyannotation to the field'sKeyannotation bag.Struct(...)discovers those annotations at construction time and folds them into anencodeKeys(...)mapping automatically. Field reuse, spread, andmapFieldsthen "just work" because the rename rides on the field.Option 2 won — same author ergonomics, no new struct API, and the rename is preserved through any operation that preserves the field schema.
Type-level plumbing
A new
EncodedKey extends PropertyKeyparameter is appended toBottom: