Skip to content

Commit 0672bcb

Browse files
angeloashmorexrutayisire
andauthoredMay 8, 2024··
feat: support groups in a slice's primary section (#338)
* feat: support groups in a slice's primary section * chore: use `@prismicio/types-internal` alpha * refactor: use `type` import * chore: release alpha as minor * fix: update `@prismicio/types-internal` * chore(release): 7.5.0-alpha.0 * fix: export `CustomTypeModelFieldForSlicePrimary` * chore(release): 7.5.0-alpha.1 * fix: update * chore(release): 7.5.0-alpha.2 * fix: update @prismicio/types-internal * chore(release): 7.5.0-alpha.3 --------- Co-authored-by: Xavier Rutayisire <xavier.rutayisire@gmail.com>
1 parent f141026 commit 0672bcb

11 files changed

+185
-35
lines changed
 

‎CHANGELOG.md

+56
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,62 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [7.5.0-alpha.3](https://github.com/prismicio/prismic-client/compare/v7.5.0-alpha.2...v7.5.0-alpha.3) (2024-05-07)
6+
7+
8+
### Bug Fixes
9+
10+
* update @prismicio/types-internal ([e75b4c2](https://github.com/prismicio/prismic-client/commit/e75b4c2fb6a6495543d66556d42e787e2ab226c9))
11+
12+
### [7.4.1](https://github.com/prismicio/prismic-client/compare/v7.4.0...v7.4.1) (2024-04-13)
13+
14+
15+
### Bug Fixes
16+
17+
* type error in `mapSliceZone` ([#339](https://github.com/prismicio/prismic-client/issues/339)) ([638e87a](https://github.com/prismicio/prismic-client/commit/638e87aeb97a04c0b8fbb160bd65a1d26028335e))
18+
19+
20+
### Chore
21+
22+
* **release:** 7.4.1 ([f141026](https://github.com/prismicio/prismic-client/commit/f141026309e21be8f7e2fbdcc9dea9c5dc4594b2))
23+
24+
## [7.5.0-alpha.2](https://github.com/prismicio/prismic-client/compare/v7.5.0-alpha.1...v7.5.0-alpha.2) (2024-04-26)
25+
26+
27+
### Bug Fixes
28+
29+
* update ([c28ae3a](https://github.com/prismicio/prismic-client/commit/c28ae3aa53a9c82573677d5ceaadf51b051b729d))
30+
31+
## [7.5.0-alpha.1](https://github.com/prismicio/prismic-client/compare/v7.5.0-alpha.0...v7.5.0-alpha.1) (2024-04-18)
32+
33+
34+
### Bug Fixes
35+
36+
* export `CustomTypeModelFieldForSlicePrimary` ([16739f6](https://github.com/prismicio/prismic-client/commit/16739f6ec00a244e51b008f98d243be739376c50))
37+
38+
## [7.5.0-alpha.0](https://github.com/prismicio/prismic-client/compare/v7.4.0...v7.5.0-alpha.0) (2024-04-17)
39+
40+
41+
### Features
42+
43+
* support groups in a slice's primary section ([98a44fa](https://github.com/prismicio/prismic-client/commit/98a44fa7a9da314f24d8b2ba518c921625391db2))
44+
45+
46+
### Bug Fixes
47+
48+
* update `@prismicio/types-internal` ([3ee1b06](https://github.com/prismicio/prismic-client/commit/3ee1b064f2ae5de7ddbbd2e69f93776ff0d9a0ad))
49+
50+
51+
### Refactor
52+
53+
* use `type` import ([46c4343](https://github.com/prismicio/prismic-client/commit/46c43439cce0ccf6626102a77918cea1e04736b7))
54+
55+
56+
### Chore
57+
58+
* release alpha as minor ([9bd6355](https://github.com/prismicio/prismic-client/commit/9bd6355d7098f45f221821e3485edc8bad05f29e))
59+
* use `@prismicio/types-internal` alpha ([df8f63d](https://github.com/prismicio/prismic-client/commit/df8f63d858227a246913dac33f15529294fc0515))
60+
561
### [7.4.1](https://github.com/prismicio/prismic-client/compare/v7.4.0...v7.4.1) (2024-04-13)
662

763

‎package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@prismicio/client",
3-
"version": "7.4.1",
3+
"version": "7.5.0-alpha.3",
44
"description": "The official JavaScript + TypeScript client library for Prismic",
55
"keywords": [
66
"typescript",
@@ -69,8 +69,8 @@
6969
"prepare": "npm run build",
7070
"release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
7171
"release:dry": "standard-version --dry-run",
72-
"release:alpha": "npm run test && standard-version --release-as major --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
73-
"release:alpha:dry": "standard-version --release-as major --prerelease alpha --dry-run",
72+
"release:alpha": "npm run test && standard-version --release-as minor --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
73+
"release:alpha:dry": "standard-version --release-as minor --prerelease alpha --dry-run",
7474
"lint": "eslint --ext .js,.ts .",
7575
"types": "tsc --noEmit",
7676
"unit": "vitest run --coverage",
@@ -83,7 +83,7 @@
8383
},
8484
"devDependencies": {
8585
"@prismicio/mock": "^0.3.1",
86-
"@prismicio/types-internal": "2.3.0",
86+
"@prismicio/types-internal": "^2.4.0",
8787
"@size-limit/preset-small-lib": "^9.0.0",
8888
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
8989
"@typescript-eslint/eslint-plugin": "^6.7.4",

‎src/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ export type { Slice } from "./types/value/slice";
228228
export type { SharedSlice } from "./types/value/sharedSlice";
229229
export type { SharedSliceVariation } from "./types/value/sharedSliceVariation";
230230

231-
export type { FieldState, AnyRegularField } from "./types/value/types";
231+
export type {
232+
FieldState,
233+
AnyRegularField,
234+
AnySlicePrimaryField,
235+
} from "./types/value/types";
232236

233237
// Models - Types representing Prismic content models.
234238
export { CustomTypeModelFieldType } from "./types/model/types";
@@ -300,6 +304,7 @@ export type { CustomTypeModelSeparatorField } from "./types/model/separator";
300304
export type {
301305
CustomTypeModelField,
302306
CustomTypeModelFieldForGroup,
307+
CustomTypeModelFieldForSlicePrimary,
303308
} from "./types/model/types";
304309

305310
// API - Types representing Prismic Rest API V2 responses.

‎src/types/model/sharedSliceVariation.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { CustomTypeModelFieldForGroup } from "./types";
1+
import type {
2+
CustomTypeModelFieldForGroup,
3+
CustomTypeModelFieldForSlicePrimary,
4+
} from "./types";
25

36
/**
47
* A shared Slice variation.
@@ -10,10 +13,10 @@ import type { CustomTypeModelFieldForGroup } from "./types";
1013
*/
1114
export interface SharedSliceModelVariation<
1215
ID extends string = string,
13-
PrimaryFields extends Record<string, CustomTypeModelFieldForGroup> = Record<
16+
PrimaryFields extends Record<
1417
string,
15-
CustomTypeModelFieldForGroup
16-
>,
18+
CustomTypeModelFieldForSlicePrimary
19+
> = Record<string, CustomTypeModelFieldForSlicePrimary>,
1720
ItemFields extends Record<string, CustomTypeModelFieldForGroup> = Record<
1821
string,
1922
CustomTypeModelFieldForGroup

‎src/types/model/types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ export type CustomTypeModelField =
6767
| CustomTypeModelSliceZoneField
6868
| CustomTypeModelFieldForGroup;
6969

70+
/**
71+
* Any custom type field that is valid for a slice's primary section.
72+
*/
73+
export type CustomTypeModelFieldForSlicePrimary =
74+
| CustomTypeModelGroupField
75+
| CustomTypeModelFieldForGroup;
76+
7077
/**
7178
* Any custom type field that is valid for a group field.
7279
*/

‎src/types/value/sharedSliceVariation.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type { AnyRegularField } from "./types";
1+
import type { AnyRegularField, AnySlicePrimaryField } from "./types";
22

33
/**
44
* A shared Slice variation.
55
*/
66
export interface SharedSliceVariation<
77
Variation = string,
8-
PrimaryFields extends Record<string, AnyRegularField> = Record<
8+
PrimaryFields extends Record<string, AnySlicePrimaryField> = Record<
99
string,
10-
AnyRegularField
10+
AnySlicePrimaryField
1111
>,
1212
ItemsFields extends Record<string, AnyRegularField> = Record<
1313
string,

‎src/types/value/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ContentRelationshipField } from "./contentRelationship";
44
import type { DateField } from "./date";
55
import type { EmbedField } from "./embed";
66
import type { GeoPointField } from "./geoPoint";
7+
import type { GroupField } from "./group";
78
import type { ImageField } from "./image";
89
import type { IntegrationField } from "./integration";
910
import type { KeyTextField } from "./keyText";
@@ -46,6 +47,11 @@ export type AnyRegularField =
4647
| GeoPointField
4748
| IntegrationField;
4849

50+
/**
51+
* Any field that can be used in a slice's primary section.
52+
*/
53+
export type AnySlicePrimaryField = GroupField | AnyRegularField;
54+
4955
/**
5056
* Useful to flatten the type output to improve type hints shown in editors. And
5157
* also to transform an interface into a type to aide with assignability.

‎test/types/customType-sharedSliceModelVariation.types.ts

+43-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ expectType<prismic.SharedSliceModelVariation<"foo">>({
7676
expectType<
7777
prismic.SharedSliceModelVariation<
7878
string,
79-
{ foo: prismic.CustomTypeModelBooleanField }
79+
{
80+
foo: prismic.CustomTypeModelBooleanField;
81+
bar: prismic.CustomTypeModelGroupField<{
82+
baz: prismic.CustomTypeModelBooleanField;
83+
}>;
84+
}
8085
>
8186
>({
8287
id: "foo",
@@ -91,8 +96,22 @@ expectType<
9196
label: "string",
9297
},
9398
},
94-
// @ts-expect-error - Only given fields are valid.
9599
bar: {
100+
type: prismic.CustomTypeModelFieldType.Group,
101+
config: {
102+
label: "string",
103+
fields: {
104+
baz: {
105+
type: "Boolean",
106+
config: {
107+
label: "string",
108+
},
109+
},
110+
},
111+
},
112+
},
113+
// @ts-expect-error - Only given fields are valid.
114+
qux: {
96115
type: prismic.CustomTypeModelFieldType.Boolean,
97116
config: {
98117
label: "string",
@@ -137,6 +156,28 @@ expectType<
137156
imageUrl: "string",
138157
});
139158

159+
/**
160+
* Does not support groups in items section.
161+
*/
162+
expectType<
163+
prismic.SharedSliceModelVariation<
164+
string,
165+
Record<string, never>,
166+
// @ts-expect-error - Group fields are not supported.
167+
{ foo: prismic.CustomTypeModelGroupField }
168+
>
169+
>({
170+
id: "foo",
171+
name: "string",
172+
docURL: "string",
173+
version: "string",
174+
description: "string",
175+
primary: {},
176+
// @ts-expect-error - We don't care about the actual value.
177+
items: {},
178+
imageUrl: "string",
179+
});
180+
140181
/**
141182
* `@prismicio/types` extends `@prismicio/types-internal`
142183
*/

‎test/types/fields-sharedSliceVariation.types.ts

+34-15
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,36 @@ expectType<prismic.SharedSliceVariation<"foo">>({
4545
/**
4646
* Supports custom primary fields type.
4747
*/
48-
expectType<prismic.SharedSliceVariation<string, { foo: prismic.BooleanField }>>(
49-
{
50-
variation: "string",
51-
version: "string",
52-
primary: {
53-
foo: true,
54-
// @ts-expect-error - Only given fields are valid.
55-
bar: false,
56-
},
57-
items: [],
48+
expectType<
49+
prismic.SharedSliceVariation<
50+
string,
51+
{ foo: prismic.BooleanField; bar: prismic.GroupField }
52+
>
53+
>({
54+
variation: "string",
55+
version: "string",
56+
primary: {
57+
foo: true,
58+
bar: [],
59+
// @ts-expect-error - Only given fields are valid.
60+
baz: false,
5861
},
59-
);
62+
items: [],
63+
});
6064

6165
/**
6266
* Supports custom items fields type.
6367
*/
6468
expectType<
6569
prismic.SharedSliceVariation<
6670
string,
67-
{ foo: prismic.BooleanField },
71+
Record<never, never>,
6872
{ bar: prismic.KeyTextField }
6973
>
7074
>({
7175
variation: "string",
7276
version: "string",
73-
primary: {
74-
foo: true,
75-
},
77+
primary: {},
7678
items: [
7779
{
7880
bar: "string",
@@ -81,3 +83,20 @@ expectType<
8183
},
8284
],
8385
});
86+
87+
/**
88+
* Does not support groups in items section.
89+
*/
90+
expectType<
91+
prismic.SharedSliceVariation<
92+
string,
93+
Record<never, never>,
94+
// @ts-expect-error - Group fields are not supported.
95+
{ foo: prismic.GroupField }
96+
>
97+
>({
98+
variation: "string",
99+
version: "string",
100+
primary: {},
101+
items: [],
102+
});

‎test/types/fields.types.ts

+13
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,16 @@ expectType<TypeOf<prismic.AnyRegularField, prismic.TitleField>>(true);
4545
*/
4646
expectType<TypeOf<prismic.AnyRegularField, prismic.SliceZone>>(false);
4747
expectType<TypeOf<prismic.AnyRegularField, prismic.GroupField>>(false);
48+
49+
/**
50+
* AnySlicePrimaryField supports any field compatible with a slice's primary
51+
* section.
52+
*/
53+
expectType<TypeOf<prismic.AnySlicePrimaryField, prismic.GroupField>>(true);
54+
expectType<TypeOf<prismic.AnySlicePrimaryField, prismic.AnyRegularField>>(true);
55+
56+
/**
57+
* AnySlicePrimaryField excludes any fields not compatible with a slice's
58+
* primary section.
59+
*/
60+
expectType<TypeOf<prismic.AnySlicePrimaryField, prismic.SliceZone>>(false);

0 commit comments

Comments
 (0)
Please sign in to comment.