Skip to content

Commit

Permalink
Merge branch 'dani/repeatable-links-alt1' of github.com:prismicio/pri…
Browse files Browse the repository at this point in the history
…smic-client into dani/repeatable-links-alt1
  • Loading branch information
dani-mp committed Nov 27, 2024
2 parents 918dc3b + 026e094 commit 251f1b3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
9 changes: 4 additions & 5 deletions src/helpers/isFilled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import type { KeyTextField } from "../types/value/keyText"
import type { LinkField } from "../types/value/link"
import type { LinkToMediaField } from "../types/value/linkToMedia"
import type { NumberField } from "../types/value/number"
import type { Repeatable } from "../types/value/repeatable"
import type { RichTextField } from "../types/value/richText"
import type { SelectField } from "../types/value/select"
import type { SharedSlice } from "../types/value/sharedSlice"
import type { Slice } from "../types/value/slice"
import type { SliceZone } from "../types/value/sliceZone"
import type { TimestampField } from "../types/value/timestamp"
import type { TitleField } from "../types/value/title"
import type { AnyRegularField, AnyRepeatableField } from "../types/value/types"
import type { AnyRegularField, Repeatable } from "../types/value/types"

/**
* Determines if a value is not nullish (i.e. not `null` or `undefined`). This
Expand Down Expand Up @@ -276,9 +275,9 @@ export const integrationFields = integrationField
* otherwise.
*/

export const repeatable = (
repeatable: Repeatable | null | undefined,
): repeatable is Repeatable<Array<AnyRepeatableField>, "filled"> => {
export const repeatable = <T extends LinkField>(
repeatable: Repeatable<T> | null | undefined,
): repeatable is Repeatable<T, "filled"> => {
return isNonNullish(repeatable) && isNonEmptyArray(repeatable)
}

Expand Down
8 changes: 7 additions & 1 deletion src/types/value/link.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AnyRegularField, FieldState } from "./types"
import type { AnyRegularField, FieldState, Repeatable } from "./types"

import type { ContentRelationshipField } from "./contentRelationship"
import type { GroupField } from "./group"
Expand Down Expand Up @@ -59,3 +59,9 @@ export type LinkField<
| ContentRelationshipField<TypeEnum, LangEnum, DataInterface, State>
| FilledLinkToWebField
| LinkToMediaField<State>

/**
* A repeatable link field.
*/

export type RepeatableLinkField = Repeatable<LinkField>
9 changes: 0 additions & 9 deletions src/types/value/repeatable.ts

This file was deleted.

17 changes: 10 additions & 7 deletions src/types/value/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { GroupField } from "./group"
import type { ImageField } from "./image"
import type { IntegrationField } from "./integration"
import type { KeyTextField } from "./keyText"
import type { LinkField } from "./link"
import type { LinkField, RepeatableLinkField } from "./link"
import type { LinkToMediaField } from "./linkToMedia"
import type { NumberField } from "./number"
import type { Repeatable } from "./repeatable"
Expand All @@ -27,11 +27,6 @@ export type EmptyObjectField = Record<string, never>
*/
export type FieldState = "empty" | "filled"

/**
* Any field that can be repeated.
*/
export type AnyRepeatableField = LinkField

/**
* Any regular field that can be nested in a group-like field.
*/
Expand All @@ -41,6 +36,7 @@ export type AnyRegularField =
| ImageField
| ContentRelationshipField
| LinkField
| RepeatableLinkField
| LinkToMediaField
| EmbedField
| DateField
Expand All @@ -52,13 +48,20 @@ export type AnyRegularField =
| BooleanField
| GeoPointField
| IntegrationField
| Repeatable

/**
* Any field that can be used in a slice's primary section.
*/
export type AnySlicePrimaryField = GroupField | AnyRegularField

/**
* A list of repeatable fields.
*/
export type Repeatable<
Field extends LinkField,
State extends FieldState = FieldState,
> = State extends "empty" ? [] : [Field, ...Field[]]

/**
* Useful to flatten the type output to improve type hints shown in editors. And
* also to transform an interface into a type to aide with assignability.
Expand Down

0 comments on commit 251f1b3

Please sign in to comment.