import { AbstractSession , ImperativeExpect , Logger } from "@zowe/imperative" ; import { posix } from "path" ; import { ZosmfRestClient , IHeaderContent , ZosmfHeaders } from "@zowe/core-for-zowe-sdk" ; import { ZosFilesConstants } from "../../constants/ZosFiles.constants" ; import { ZosFilesMessages } from "../../constants/ZosFiles.messages" ; import { IZosFilesResponse } from "../../doc/IZosFilesResponse" ; import { Invoke } from "../invoke" ; import { IDeleteDatasetOptions } from "./doc/IDeleteDatasetOptions" ; import { IDeleteVsamOptions } from "./doc/IDeleteVsamOptions" ; import { IDeleteVsamResponse } from "./doc/IDeleteVsamResponse" ; import { ZosFilesUtils } from "../../utils/ZosFilesUtils" ; import { IZosFilesOptions } from "../../doc/IZosFilesOptions" ; /**
 * This class holds helper functions that are used to delete files through the
 * z/OSMF APIs.
 */ export class Delete { param { AbstractSession } session param { string } dataSetName param { IDeleteDatasetOptions } options returns { Promise < IZosFilesResponse > } throws throws {Error} When the  ZosmfRestClient throws an error
     *
     *  see https public static async dataSet ( session , dataSetName , options = { } ) { ImperativeExpect . toNotBeNullOrUndefined ( dataSetName , ZosFilesMessages . missingDatasetName . message ) ; ImperativeExpect . toNotBeEqual ( dataSetName , "" , ZosFilesMessages . missingDatasetName . message ) ; try { let endpoint = posix . join ( ZosFilesConstants . RESOURCE , ZosFilesConstants . RES_DS_FILES ) ; if ( options . volume ) { endpoint = posix . join ( endpoint , `-(${ options . volume })` ) ; } const reqHeaders = [ ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options && options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } endpoint = posix . join ( endpoint , dataSetName ) ; Logger . getAppLogger ( ) . debug ( `Endpoint: ${ endpoint }` ) ; await ZosmfRestClient . deleteExpectString ( session , endpoint , reqHeaders ) ; return { success : true , commandResponse : ZosFilesMessages . datasetDeletedSuccessfully . message } ; } catch ( error ) { Logger . getAppLogger ( ) . error ( error ) ; throw error ; } } param { AbstractSession } session param { string } dataSetName param { IDeleteVsamOptions } options returns { Promise < IDeleteVsamResponse > } throws see https public static async vsam ( session , dataSetName , options = { } ) { ImperativeExpect . toNotBeNullOrUndefined ( dataSetName , ZosFilesMessages . missingDatasetName . message ) ; ImperativeExpect . toNotBeEqual ( dataSetName , "" , ZosFilesMessages . missingDatasetName . message ) ; const amsControlStatements = [ "DELETE -" , `${ dataSetName } -` , "CLUSTER -" , `${ options . erase ? "ERASE" : "NOERASE" } -` , options . purge ? "PURGE" : "NOPURGE" ] ; try { const response = await Invoke . ams ( session , amsControlStatements , { responseTimeout : options . responseTimeout } ) ; return { success : true , commandResponse : ZosFilesMessages . datasetDeletedSuccessfully . message , apiResponse : response } ; } catch ( error ) { Logger . getAppLogger ( ) . error ( error ) ; throw error ; } } param { AbstractSession } session param { string } fileName param { boolean } recursive returns { Promise < IDeleteVsamResponse > } throws see https public static async ussFile ( session , fileName , recursive ? , options ? ) { ImperativeExpect . toNotBeNullOrUndefined ( fileName , ZosFilesMessages . missingUSSFileName . message ) ; ImperativeExpect . toNotBeEqual ( fileName , "" , ZosFilesMessages . missingUSSFileName . message ) ; let endpoint = posix . join ( ZosFilesConstants . RESOURCE , ZosFilesConstants . RES_USS_FILES ) ; fileName = posix . normalize ( fileName ) ; fileName = ZosFilesUtils . formatUnixFilepath ( fileName ) ; fileName = encodeURIComponent ( fileName ) ; endpoint = posix . join ( endpoint , fileName ) ; Logger . getAppLogger ( ) . debug ( `Endpoint: ${ endpoint }` ) ; const reqHeaders = [ ZosmfHeaders . ACCEPT_ENCODING ] ; if ( recursive && recursive === true ) { reqHeaders . push ( { "X-IBM-Option" : "recursive" } ) ; } if ( options && options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } try { await ZosmfRestClient . deleteExpectString ( session , endpoint , reqHeaders ) ; return { success : true , commandResponse : ZosFilesMessages . ussFileDeletedSuccessfully . message } ; } catch ( error ) { Logger . getAppLogger ( ) . error ( error ) ; throw error ; } } param { AbstractSession } session param { string } fileSystemName throws see https public static async zfs ( session , fileSystemName , options ? ) { ImperativeExpect . toNotBeNullOrUndefined ( fileSystemName , ZosFilesMessages . missingFileSystemName . message ) ; ImperativeExpect . toNotBeEqual ( fileSystemName , "" , ZosFilesMessages . missingFileSystemName . message ) ; const endpoint = ZosFilesConstants . RESOURCE + ZosFilesConstants . RES_ZFS_FILES + "/" + fileSystemName ; const reqHeaders = [ ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options && options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } const data = await ZosmfRestClient . deleteExpectString ( session , endpoint , reqHeaders ) ; return { success : true , commandResponse : ZosFilesMessages . zfsDeletedSuccessfully . message , apiResponse : data } ; } }