@@ -25,7 +25,7 @@ import {
2525 WrappedResult ,
2626} from "./types.ts" ;
2727
28- import { DESCENDANT_LIMIT } from "../constants.ts" ;
28+ import { DESCENDANT_LIMIT , V2EDITOR_METADATA } from "../constants.ts" ;
2929import { logError , trace } from "../confluence-logger.ts" ;
3030
3131export class ConfluenceClient {
@@ -53,14 +53,23 @@ export class ConfluenceClient {
5353
5454 public getDescendants (
5555 id : string ,
56- expand = [ "metadata.properties" ]
56+ expand = [ "metadata.properties" , "ancestors" ]
5757 ) : Promise < WrappedResult < ContentSummary > > {
5858 const url = `content/${ id } /descendant/page?limit=${ DESCENDANT_LIMIT } &expand=${ expand } ` ;
5959 return this . get < WrappedResult < ContentSummary > > ( url ) ;
6060 }
6161
62- public async isTitleInSpace ( title : string , space : Space ) : Promise < boolean > {
62+ public async isTitleInSpace (
63+ title : string ,
64+ space : Space ,
65+ idToIgnore : string = ""
66+ ) : Promise < boolean > {
6367 const result = await this . fetchMatchingTitlePages ( title , space ) ;
68+
69+ if ( result . length === 1 && result [ 0 ] . id === idToIgnore ) {
70+ return false ;
71+ }
72+
6473 return result . length > 0 ;
6574 }
6675
@@ -75,24 +84,42 @@ export class ConfluenceClient {
7584 return result ?. results ?? [ ] ;
7685 }
7786
78- public createContent ( content : ContentCreate ) : Promise < Content > {
87+ public createContent (
88+ content : ContentCreate ,
89+ metadata : Record < string , any > = V2EDITOR_METADATA
90+ ) : Promise < Content > {
91+ const toCreate = {
92+ ...content ,
93+ ...metadata ,
94+ } ;
95+
96+ trace ( "to create" , toCreate ) ;
7997 trace ( "createContent body" , content . body . storage . value ) ;
80- const createBody = JSON . stringify ( content ) ;
98+ const createBody = JSON . stringify ( toCreate ) ;
8199 return this . post < Content > ( "content" , createBody ) ;
82100 }
83101
102+ public updateContent (
103+ content : ContentUpdate ,
104+ metadata : Record < string , any > = V2EDITOR_METADATA
105+ ) : Promise < Content > {
106+ const toUpdate = {
107+ ...content ,
108+ ...metadata ,
109+ } ;
110+ trace ( "updateContent" , toUpdate ) ;
111+ return this . put < Content > ( `content/${ content . id } ` , JSON . stringify ( toUpdate ) ) ;
112+ }
113+
84114 public createContentProperty ( id : string , content : any ) : Promise < Content > {
85115 return this . post < Content > (
86116 `content/${ id } /property` ,
87117 JSON . stringify ( content )
88118 ) ;
89119 }
90120
91- public updateContent ( content : ContentUpdate ) : Promise < Content > {
92- return this . put < Content > ( `content/${ content . id } ` , JSON . stringify ( content ) ) ;
93- }
94-
95121 public deleteContent ( content : ContentDelete ) : Promise < Content > {
122+ trace ( "deleteContent" , content ) ;
96123 return this . delete < Content > ( `content/${ content . id } ` ) ;
97124 }
98125
0 commit comments