Skip to content
This repository was archived by the owner on Feb 3, 2026. It is now read-only.

chore: update api versions to 2025-10-15 to support raw perspective#107

Merged
SamHemingway merged 1 commit intomainfrom
chore/update-api-version
Oct 17, 2025
Merged

chore: update api versions to 2025-10-15 to support raw perspective#107
SamHemingway merged 1 commit intomainfrom
chore/update-api-version

Conversation

@SamHemingway
Copy link
Contributor

Description

What it says on the tin: updates the API version used by the plug-in.

This is for me :)

I have a scenario where I'm creating new locales inside of a release.

As it stands, the old api version doesn't support the raw perspective; so if the consumer of the plugin passes a async function for resolving languages (say like the below) that uses the raw perspective, then it won't work.

export async function fetchLocalesFromSanity(client: SanityClient): Promise<Locale[]> {
  try {
    // Fetch all locales including drafts and versions in releases
    // Use 'raw' perspective to get everything including versioned documents in releases
    const allLocales = await client.fetch<Array<Locale & {_id: string}>>(
      `*[_type == "locale"] | order(tag asc) { 
        _id,
        "id": tag, 
        title, 
        flag,
        "fallbackLocale": fallback->tag,
        "releaseId": select(
          _id match "versions.*" => string::split(_id, ".")[1],
          null
        ),
        "status": select(
          _id match "versions.*" => "in_release",
          _id match "drafts.*" => "draft", 
          "published"
        )
      }`,
      {},
      {perspective: 'raw'}, // Raw perspective includes published + drafts + versions
    )

    // Deduplicate by locale tag (id): prefer release version over draft, draft over published
    const localeMap = new Map<string, Locale>()

    for (const locale of allLocales) {
      const isDraft = locale._id.startsWith('drafts.')
      const isInRelease = locale._id.startsWith('versions.')
      const existingLocale = localeMap.get(locale.id)

      // Prefer release over draft, and draft over published
      const shouldReplace =
        !existingLocale ||
        (isInRelease && existingLocale.status !== 'in_release') ||
        (isDraft && existingLocale.status === 'published')

      if (shouldReplace) {
        const {_id, ...localeWithoutId} = locale
        localeMap.set(locale.id, localeWithoutId)
      }
    }

    const uniqueLocales = Array.from(localeMap.values())

    return uniqueLocales.length > 0 ? uniqueLocales : SUPPORTED_LANGUAGES
  } catch (error) {
    console.error('Failed to fetch locales:', error)
    return SUPPORTED_LANGUAGES // Fallback
  }
}

What to review

Would this be a breaking change for any reason?

Copy link
Contributor

@SimeonGriggs SimeonGriggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@SamHemingway SamHemingway merged commit 8864f5a into main Oct 17, 2025
9 checks passed
@SamHemingway SamHemingway deleted the chore/update-api-version branch October 17, 2025 12:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants