@@ -26,6 +26,7 @@ import {
26
26
type CacheFunctionOptions ,
27
27
cache ,
28
28
cacheResponse ,
29
+ getResponseCacheTags ,
29
30
noCacheFetchOptions ,
30
31
parseCacheResponse ,
31
32
} from './cache' ;
@@ -370,6 +371,18 @@ interface GetRevisionOptions {
370
371
* These options don't impact the cache key and it means revisions can be shared between different fetches with different metadata options.
371
372
*/
372
373
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 [ ] ;
373
386
}
374
387
375
388
const getAPIContextId = async ( ) => {
@@ -381,10 +394,16 @@ const getAPIContextId = async () => {
381
394
* Get a revision by its ID.
382
395
*/
383
396
export 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 ,
388
407
getKeySuffix : getAPIContextId ,
389
408
get : async (
390
409
spaceId : string ,
@@ -405,7 +424,13 @@ export const getRevision = cache({
405
424
}
406
425
) ;
407
426
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
+ } ) ;
409
434
} ,
410
435
getKeyArgs : ( args ) => [ args [ 0 ] , args [ 1 ] ] ,
411
436
} ) ;
@@ -414,10 +439,16 @@ export const getRevision = cache({
414
439
* Get all the pages in a revision of a space.
415
440
*/
416
441
export 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 ,
421
452
getKeySuffix : getAPIContextId ,
422
453
get : async (
423
454
spaceId : string ,
@@ -440,7 +471,7 @@ export const getRevisionPages = cache({
440
471
441
472
return cacheResponse ( response , {
442
473
...( fetchOptions . metadata ? cacheTtl_7days : cacheTtl_1day ) ,
443
- data : response . data . pages ,
474
+ data : { pages : response . data . pages , tags : getResponseCacheTags ( response ) } ,
444
475
} ) ;
445
476
} ,
446
477
getKeyArgs : ( args ) => [ args [ 0 ] , args [ 1 ] ] ,
@@ -632,7 +663,7 @@ export const getRevisionFile = batch<[string, string, string], RevisionFile | nu
632
663
let files : Record < string , RevisionFile > = { } ;
633
664
634
665
if ( hasRevisionInMemory ) {
635
- const revision = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
666
+ const { revision } = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
636
667
files = { } ;
637
668
revision . files . forEach ( ( file ) => {
638
669
files [ file . id ] = file ;
@@ -678,7 +709,7 @@ export const getReusableContent = async (
678
709
} ) ;
679
710
680
711
if ( hasRevisionInMemory ) {
681
- const revision = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
712
+ const { revision } = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
682
713
return (
683
714
revision . reusableContents . find (
684
715
( reusableContent ) => reusableContent . id === reusableContentId
0 commit comments