import { AbstractSession , ImperativeExpect , Logger , Headers } from "@zowe/imperative" ; import { posix } from "path" ; import { ZosmfRestClient , ZosmfHeaders , IHeaderContent } from "@zowe/core-for-zowe-sdk" ; import { ZosFilesConstants } from "../../constants/ZosFiles.constants" ; import { ZosFilesMessages } from "../../constants/ZosFiles.messages" ; import { IZosFilesResponse } from "../../doc/IZosFilesResponse" ; import { IDataSet } from "../../doc/IDataSet" ; import { ICopyDatasetOptions } from "./doc/ICopyDatasetOptions" ; /**
 * This class holds helper functions that are used to copy the contents of datasets through the
 * z/OSMF APIs.
 */ export class Copy { param { AbstractSession } session param { IDataSet } toDataSet param { IDataSetOptions } options returns { Promise < IZosFilesResponse > } throws throws {Error} When the  ZosmfRestClient throws an error
     *
     *  see https public static async dataSet ( session , { dataSetName : toDataSetName , memberName : toMemberName } , options ) { ImperativeExpect . toBeDefinedAndNonBlank ( options . fromDataSet . dataSetName , "fromDataSetName" ) ; ImperativeExpect . toBeDefinedAndNonBlank ( toDataSetName , "toDataSetName" ) ; const endpoint = posix . join ( ZosFilesConstants . RESOURCE , ZosFilesConstants . RES_DS_FILES , toMemberName == null ? toDataSetName : `${ toDataSetName }(${ toMemberName })` ) ; Logger . getAppLogger ( ) . debug ( `Endpoint: ${ endpoint }` ) ; const payload = { "request" : "copy" , "from-dataset" : { dsn : options . fromDataSet . dataSetName , member : options . fromDataSet . memberName } , ... options } ; delete payload . fromDataSet ; const reqHeaders = [ Headers . APPLICATION_JSON , { [ Headers . CONTENT_LENGTH ] : JSON . stringify ( payload ) . length . toString ( ) } , ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } try { await ZosmfRestClient . putExpectString ( session , endpoint , reqHeaders , payload ) ; return { success : true , commandResponse : ZosFilesMessages . datasetCopiedSuccessfully . message } ; } catch ( error ) { Logger . getAppLogger ( ) . error ( error ) ; throw error ; } } }