feat(WEB-209): revalidate my pages navigation on demand

This commit is contained in:
Simon Emanuelsson
2024-04-16 12:42:44 +02:00
committed by Michael Zetterberg
parent 16634abbbf
commit 1bffbc837e
40 changed files with 600 additions and 144 deletions

View File

@@ -38,6 +38,7 @@ export async function getContentTypeByPathName(
)
if (!validatedContentTypeUid.success) {
console.error("Bad validation for `validatedContentTypeUid`")
console.error(validatedContentTypeUid.error)
return null
}

56
utils/generateTag.ts Normal file
View File

@@ -0,0 +1,56 @@
import type { Edges } from "@/types/requests/utils/edges"
import type { Lang } from "@/constants/languages"
import type { NodeRefs } from "@/types/requests/utils/refs"
/**
* Function to generate tag for initial refs request
*
* @param lang
* @param identifier Should be uri for all pages and content_type_uid for
* everything else
* @returns string
*/
export function generateRefsResponseTag(lang: Lang, identifier: string) {
return `${lang}:${identifier}:refs`
}
/**
* Function to generate all tags to references on entity
*
* @param lang Lang
* @param contentTypeUid content_type_uid of reference
* @param uid system.uid of reference
* @returns string
*/
export function generateRefTag(
lang: Lang,
contentTypeUid: string,
uid: string
) {
return `${lang}:ref:${contentTypeUid}:${uid}`
}
/**
* Function to generate tag for entity being requested
*
* @param lang Lang
* @param uid system.uid of entity
* @returns string
*/
export function generateTag(lang: Lang, uid: string) {
return `${lang}:${uid}`
}
export function generateTags(lang: Lang, connections: Edges<NodeRefs>[]) {
return connections
.map((connection) => {
return connection.edges.map(({ node }) => {
return generateRefTag(
lang,
node.system.content_type_uid,
node.system.uid
)
})
})
.flat()
}