-
Notifications
You must be signed in to change notification settings - Fork 62
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: support fields
slice variation config
#337
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #337 +/- ##
=======================================
Coverage 99.97% 99.97%
=======================================
Files 61 61
Lines 6905 6924 +19
Branches 381 381
=======================================
+ Hits 6903 6922 +19
Misses 2 2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as per the current specs however please ignore it all depending on the outcome of this discussion: https://prismic-team.slack.com/archives/C02L3FN3AJK/p1712751482676019
Also I get it we want models to be defined with fields
and value with data
. On custom types they call it json
(which I think is a weird name) instead of fields
so it looks like we have no standards here, I'd be happy with fields
being the standard moving forward.
@@ -4,6 +4,7 @@ import type { ContentRelationshipField } from "./contentRelationship"; | |||
import type { DateField } from "./date"; | |||
import type { EmbedField } from "./embed"; | |||
import type { GeoPointField } from "./geoPoint"; | |||
import { GroupField } from "./group"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { GroupField } from "./group"; | |
import type { GroupField } from "./group"; |
/** | ||
* A shared slice variation. | ||
*/ | ||
export type SharedSliceVariation< | ||
Variation extends string = string, | ||
Fields extends Record<string, SliceField> = Record<string, SliceField>, | ||
ItemsFields extends Record<string, AnyRegularField> = Record< | ||
string, | ||
AnyRegularField | ||
>, | ||
> = SharedSliceVariationWithData<Variation, Fields> & | ||
SharedSliceVariationWithPrimaryAndItems<Variation, Fields, ItemsFields>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is more of an internal type right (in the spirit)? I don't really see how the returned type could be helpful to users since it awkwardly has both primary
and data
with primary
potentially containing illegal group fields 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type was intended to be a backward-compatible version since all current generated types use SharedSliceVariation
. Future type generations would use the more specific types instead. So not really "internal," but definitely temporarily used.
Anyway, we are going away from this PR so we can avoid this weird, dirty type. 😅
Closing in favor of #338. We decided not to use |
Types of changes
Description
This PR adds support for the
fields
slice variation config.fields
is an upcoming feature that allows slices to use group fields.fields
property toSharedSliceModelVariation
.data
property toSharedSliceVariation
.SharedSliceVariationWithData
which represents a slice using thedata
property.SharedSliceVariationWithPrimaryAndItems
which represents a slice using theprimary
anditems
properties.The
fields
config is preferred over theprimary
anditems
config.primary
anditems
will continue to be supported, but new slices will usefields
.Related: DT-2078
Backward compatibility
There are no breaking changes in this PR. Some of the implementation may look strange, like
SharedSliceVariation
. Some concessions were necessary to be backward compatible with the current API.prismic-ts-codegen
will be updated to useSharedSliceVariationWithData
andSharedSliceVariationWithPrimaryAndItems
only (i.e. no use ofSharedSliceVariation
), which will prevent users from interacting with slightly inaccurate types.Example
Checklist: