import { AbstractSession , IHeaderContent , ImperativeExpect , Logger } from "@zowe/imperative" ; import { posix } from "path" ; import { ZosmfRestClient , 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 { IListOptions } from "./doc/IListOptions" ; import { IUSSListOptions } from "./doc/IUSSListOptions" ; import { IFsOptions } from "./doc/IFsOptions" ; /**
 * This class holds helper functions that are used to list data sets and its members through the z/OS MF APIs
 */ export class List { param { AbstractSession } session param { string } dataSetName param { IListOptions } options returns { Promise < IZosFilesResponse > } throws throws {Error} When the  ZosmfRestClient throws an error
     *
     *  see https public static async allMembers ( 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 , dataSetName , ZosFilesConstants . RES_DS_MEMBERS ) ; if ( options . pattern ) { endpoint += `?pattern=${ options . pattern }` ; } const reqHeaders = [ ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options . attributes ) { reqHeaders . push ( ZosmfHeaders . X_IBM_ATTRIBUTES_BASE ) ; } if ( options . maxLength ) { reqHeaders . push ( { "X-IBM-Max-Items" : `${ options . maxLength }` } ) ; } else { reqHeaders . push ( ZosmfHeaders . X_IBM_MAX_ITEMS ) ; } if ( options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } this . log . debug ( `Endpoint: ${ endpoint }` ) ; const response = await ZosmfRestClient . getExpectJSON ( session , endpoint , reqHeaders ) ; return { success : true , commandResponse : null , apiResponse : response } ; } catch ( error ) { this . log . error ( error ) ; throw error ; } } param { AbstractSession } session param { string } dataSetName param { IListOptions } options returns { Promise < IZosFilesResponse > } throws throws {Error} When the  ZosmfRestClient throws an error
      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 }?${ ZosFilesConstants . RES_DS_LEVEL }=${ dataSetName }` ) ; if ( options . volume ) { endpoint = `${ endpoint }&volser=${ options . volume }` ; } if ( options . start ) { endpoint = `${ endpoint }&start=${ options . start }` ; } const reqHeaders = [ ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options . attributes ) { reqHeaders . push ( ZosmfHeaders . X_IBM_ATTRIBUTES_BASE ) ; } if ( options . maxLength ) { reqHeaders . push ( { "X-IBM-Max-Items" : `${ options . maxLength }` } ) ; } else { reqHeaders . push ( ZosmfHeaders . X_IBM_MAX_ITEMS ) ; } if ( options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } if ( options . recall ) { switch ( options . recall . toLowerCase ( ) ) { case "wait" : reqHeaders . push ( ZosmfHeaders . X_IBM_MIGRATED_RECALL_WAIT ) ; break ; case "nowait" : reqHeaders . push ( ZosmfHeaders . X_IBM_MIGRATED_RECALL_NO_WAIT ) ; break ; case "error" : reqHeaders . push ( ZosmfHeaders . X_IBM_MIGRATED_RECALL_ERROR ) ; break ; } } this . log . debug ( `Endpoint: ${ endpoint }` ) ; const response = await ZosmfRestClient . getExpectJSON ( session , endpoint , reqHeaders ) ; return { success : true , commandResponse : null , apiResponse : response } ; } catch ( error ) { this . log . error ( error ) ; throw error ; } } param { AbstractSession } session param { string } path param { IUSSListOptions } options returns { Promise < IZosFilesResponse > } throws throws {Error} When the  ZosmfRestClient throws an error
      public static async fileList ( session , path , options = { } ) { ImperativeExpect . toNotBeNullOrUndefined ( path , ZosFilesMessages . missingUSSFileName . message ) ; ImperativeExpect . toNotBeEqual ( path , "" , ZosFilesMessages . missingUSSFileName . message ) ; try { const endpoint = posix . join ( ZosFilesConstants . RESOURCE , `${ ZosFilesConstants . RES_USS_FILES }?${ ZosFilesConstants . RES_PATH }=${ encodeURIComponent ( path ) }` ) ; const reqHeaders = [ ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options . maxLength ) { reqHeaders . push ( { "X-IBM-Max-Items" : `${ options . maxLength }` } ) ; } else { reqHeaders . push ( ZosmfHeaders . X_IBM_MAX_ITEMS ) ; } if ( options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } this . log . debug ( `Endpoint: ${ endpoint }` ) ; const response = await ZosmfRestClient . getExpectJSON ( session , endpoint , reqHeaders ) ; return { success : true , commandResponse : null , apiResponse : response } ; } catch ( error ) { this . log . error ( error ) ; throw error ; } } param { AbstractSession } session param { IZfsOptions } options returns { Promise < IZosFilesResponse > } throws throws {Error} When the  ZosmfRestClient throws an error
      public static async fs ( session , options = { } ) { try { let endpoint = posix . join ( ZosFilesConstants . RESOURCE , `${ ZosFilesConstants . RES_MFS }` ) ; if ( options . fsname ) { endpoint = posix . join ( endpoint , `?${ ZosFilesConstants . RES_FSNAME }=${ encodeURIComponent ( options . fsname ) }` ) ; } const reqHeaders = [ ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options . maxLength ) { reqHeaders . push ( { "X-IBM-Max-Items" : `${ options . maxLength }` } ) ; } else { reqHeaders . push ( ZosmfHeaders . X_IBM_MAX_ITEMS ) ; } if ( options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } this . log . debug ( `Endpoint: ${ endpoint }` ) ; const response = await ZosmfRestClient . getExpectJSON ( session , endpoint , reqHeaders ) ; return { success : true , commandResponse : null , apiResponse : response } ; } catch ( error ) { this . log . error ( error ) ; throw error ; } } param { AbstractSession } session param { IZfsOptions } options returns { Promise < IZosFilesResponse > } throws throws {Error} When the  ZosmfRestClient throws an error
      public static async fsWithPath ( session , options = { } ) { try { let endpoint = posix . join ( ZosFilesConstants . RESOURCE , `${ ZosFilesConstants . RES_MFS }` ) ; if ( options . path ) { endpoint = posix . join ( endpoint , `?${ ZosFilesConstants . RES_PATH }=${ encodeURIComponent ( options . path ) }` ) ; } const reqHeaders = [ ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options . maxLength ) { reqHeaders . push ( { "X-IBM-Max-Items" : `${ options . maxLength }` } ) ; } else { reqHeaders . push ( ZosmfHeaders . X_IBM_MAX_ITEMS ) ; } if ( options . responseTimeout != null ) { reqHeaders . push ( { [ ZosmfHeaders . X_IBM_RESPONSE_TIMEOUT ] : options . responseTimeout . toString ( ) } ) ; } this . log . debug ( `Endpoint: ${ endpoint }` ) ; const response = await ZosmfRestClient . getExpectJSON ( session , endpoint , reqHeaders ) ; return { success : true , commandResponse : null , apiResponse : response } ; } catch ( error ) { this . log . error ( error ) ; throw error ; } } private static get log ( ) { return Logger . getAppLogger ( ) ; } }