@@ -26,6 +26,7 @@ import {
2626 type CacheFunctionOptions ,
2727 cache ,
2828 cacheResponse ,
29+ getResponseCacheTags ,
2930 noCacheFetchOptions ,
3031 parseCacheResponse ,
3132} from './cache' ;
@@ -370,6 +371,18 @@ interface GetRevisionOptions {
370371 * These options don't impact the cache key and it means revisions can be shared between different fetches with different metadata options.
371372 */
372373 metadata : boolean ;
374+
375+ /**
376+ * Whether to fetch the revision as a computed revision.
377+ * @default true
378+ */
379+ computed ?: boolean ;
380+
381+ /**
382+ * Additional tags to add to the cache entry.
383+ * It's only used for v1, once in v2 we can get rid of it.
384+ */
385+ tags ?: string [ ] ;
373386}
374387
375388const getAPIContextId = async ( ) => {
@@ -381,10 +394,16 @@ const getAPIContextId = async () => {
381394 * Get a revision by its ID.
382395 */
383396export const getRevision = cache ( {
384- name : 'api.getRevision.v2' ,
385- tag : ( spaceId , revisionId ) =>
386- getCacheTag ( { tag : 'revision' , space : spaceId , revision : revisionId } ) ,
387- tagImmutable : true ,
397+ name : 'api.getRevision.v3' ,
398+ tag : ( spaceId , revisionId , fetchOptions ) =>
399+ // Temporary hack to make it work with OpenAPI on v1
400+ fetchOptions . tags ?. [ 0 ] ??
401+ getCacheTag ( {
402+ tag : 'revision' ,
403+ space : spaceId ,
404+ revision : revisionId ,
405+ } ) ,
406+ tagImmutable : false ,
388407 getKeySuffix : getAPIContextId ,
389408 get : async (
390409 spaceId : string ,
@@ -405,7 +424,13 @@ export const getRevision = cache({
405424 }
406425 ) ;
407426
408- return cacheResponse ( response , fetchOptions . metadata ? cacheTtl_7days : cacheTtl_1day ) ;
427+ return cacheResponse ( response , {
428+ ...( fetchOptions . metadata ? cacheTtl_7days : cacheTtl_1day ) ,
429+ data : {
430+ revision : response . data ,
431+ tags : getResponseCacheTags ( response ) ,
432+ } ,
433+ } ) ;
409434 } ,
410435 getKeyArgs : ( args ) => [ args [ 0 ] , args [ 1 ] ] ,
411436} ) ;
@@ -414,10 +439,16 @@ export const getRevision = cache({
414439 * Get all the pages in a revision of a space.
415440 */
416441export const getRevisionPages = cache ( {
417- name : 'api.getRevisionPages.v4' ,
418- tag : ( spaceId , revisionId ) =>
419- getCacheTag ( { tag : 'revision' , space : spaceId , revision : revisionId } ) ,
420- tagImmutable : true ,
442+ name : 'api.getRevisionPages.v5' ,
443+ tag : ( spaceId , revisionId , fetchOptions ) =>
444+ // Temporary hack to make it work with OpenAPI on v1
445+ fetchOptions . tags ?. [ 0 ] ??
446+ getCacheTag ( {
447+ tag : 'revision' ,
448+ space : spaceId ,
449+ revision : revisionId ,
450+ } ) ,
451+ tagImmutable : false ,
421452 getKeySuffix : getAPIContextId ,
422453 get : async (
423454 spaceId : string ,
@@ -440,7 +471,7 @@ export const getRevisionPages = cache({
440471
441472 return cacheResponse ( response , {
442473 ...( fetchOptions . metadata ? cacheTtl_7days : cacheTtl_1day ) ,
443- data : response . data . pages ,
474+ data : { pages : response . data . pages , tags : getResponseCacheTags ( response ) } ,
444475 } ) ;
445476 } ,
446477 getKeyArgs : ( args ) => [ args [ 0 ] , args [ 1 ] ] ,
@@ -632,7 +663,7 @@ export const getRevisionFile = batch<[string, string, string], RevisionFile | nu
632663 let files : Record < string , RevisionFile > = { } ;
633664
634665 if ( hasRevisionInMemory ) {
635- const revision = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
666+ const { revision } = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
636667 files = { } ;
637668 revision . files . forEach ( ( file ) => {
638669 files [ file . id ] = file ;
@@ -678,7 +709,7 @@ export const getReusableContent = async (
678709 } ) ;
679710
680711 if ( hasRevisionInMemory ) {
681- const revision = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
712+ const { revision } = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
682713 return (
683714 revision . reusableContents . find (
684715 ( reusableContent ) => reusableContent . id === reusableContentId
0 commit comments