@@ -12,6 +12,7 @@ import { NodeDiffService } from "./node-diff.service";
1212import { NodeDependencyService } from "./node-dependency.service" ;
1313import { PackageVersionCommandService } from "./package-version-command.service" ;
1414import { PackageValidationService } from "./package-validation.service" ;
15+ import { fileService } from "../../core/utils/file-service" ;
1516
1617class Module extends IModule {
1718
@@ -116,6 +117,32 @@ class Module extends IModule {
116117 . option ( "--json" , "Return the response as a JSON file" )
117118 . action ( this . findNode ) ;
118119
120+ nodesCommand . command ( "create" )
121+ . description ( "Create a new staging node in a package" )
122+ . requiredOption ( "--packageKey <packageKey>" , "Identifier of the package" )
123+ . option ( "--body <body>" , "Node payload as JSON string" )
124+ . option ( "-f, --file <file>" , "Path to a JSON file containing the node payload" )
125+ . option ( "--validate" , "Only validate the payload without persisting. Returns success if valid." , false )
126+ . option ( "--json" , "Return the response as a JSON file" )
127+ . action ( this . createNode ) ;
128+
129+ nodesCommand . command ( "update" )
130+ . description ( "Update a staging node in a package" )
131+ . requiredOption ( "--packageKey <packageKey>" , "Identifier of the package" )
132+ . requiredOption ( "--nodeKey <nodeKey>" , "Identifier of the node" )
133+ . option ( "--body <body>" , "Node payload as JSON string" )
134+ . option ( "-f, --file <file>" , "Path to a JSON file containing the node payload" )
135+ . option ( "--validate" , "Only validate the payload without persisting. Returns success if valid." , false )
136+ . option ( "--json" , "Return the response as a JSON file" )
137+ . action ( this . updateNode ) ;
138+
139+ nodesCommand . command ( "delete" )
140+ . description ( "Delete (archive) a staging node in a package" )
141+ . requiredOption ( "--packageKey <packageKey>" , "Identifier of the package" )
142+ . requiredOption ( "--nodeKey <nodeKey>" , "Identifier of the node" )
143+ . option ( "--force" , "Force delete even if the node has dependants" , false )
144+ . action ( this . archiveNode ) ;
145+
119146 nodesCommand . command ( "list" )
120147 . description ( "List nodes in a specific package version" )
121148 . requiredOption ( "--packageKey <packageKey>" , "Identifier of the package" )
@@ -249,6 +276,33 @@ class Module extends IModule {
249276 await new NodeService ( context ) . findNode ( options . packageKey , options . nodeKey , options . withConfiguration , options . packageVersion ?? null , options . json ) ;
250277 }
251278
279+ private async createNode ( context : Context , command : Command , options : OptionValues ) : Promise < void > {
280+ const body = Module . resolveBody ( options . body , options . file ) ;
281+ await new NodeService ( context ) . createNode ( options . packageKey , body , options . validate , options . json ) ;
282+ }
283+
284+ private async updateNode ( context : Context , command : Command , options : OptionValues ) : Promise < void > {
285+ const body = Module . resolveBody ( options . body , options . file ) ;
286+ await new NodeService ( context ) . updateNode ( options . packageKey , options . nodeKey , body , options . validate , options . json ) ;
287+ }
288+
289+ private static resolveBody ( body : string | undefined , file : string | undefined ) : string {
290+ if ( body && file ) {
291+ throw new Error ( "Please provide either --body or --file, but not both." ) ;
292+ }
293+ if ( ! body && ! file ) {
294+ throw new Error ( "Please provide either --body or --file." ) ;
295+ }
296+ if ( file ) {
297+ return fileService . readFile ( file ) ;
298+ }
299+ return body ! ;
300+ }
301+
302+ private async archiveNode ( context : Context , command : Command , options : OptionValues ) : Promise < void > {
303+ await new NodeService ( context ) . archiveNode ( options . packageKey , options . nodeKey , options . force ) ;
304+ }
305+
252306 private async listNodes ( context : Context , command : Command , options : OptionValues ) : Promise < void > {
253307 await new NodeService ( context ) . listNodes ( options . packageKey , options . packageVersion , options . limit , options . offset , options . withConfiguration , options . json ) ;
254308 }
0 commit comments