Skip to content

Commit

Permalink
address VSCE breaking changes
Browse files Browse the repository at this point in the history
Signed-off-by: zFernand0 <[email protected]>
  • Loading branch information
zFernand0 committed Mar 8, 2024
1 parent 6f5de49 commit e568aca
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 46 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ All notable changes to the z/OS FTP Plug-in for Zowe CLI will be documented in t
- Removed the following constants, interfaces, and other values:
- `IGetSpoolFileOption.jobName`
- `JobUtils.parseJobDetails`
- Added proper typing to the parameters of the following functions:
- `CoreUtils.addLowerCaseKeysToObject`
- Return type changed: `any --> IDatasetEntry`
- Added proper typing to the parameters of the following functions:
- `CreateDataset.create`
- `DataSetUtils.listDataSets`
- `FTPConfig.connectFromArguments`
Expand Down
26 changes: 6 additions & 20 deletions src/api/CoreUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

import { ICommandProfileTypeConfiguration, IImperativeError, Logger } from "@zowe/imperative";
import * as stream from "stream";
import { IDatasetEntry } from "./doc/DataSetInterface";
import { ITransferMode, IUSSEntry } from "./doc";
import { ITransferMode } from "./doc";

export class CoreUtils {

Expand Down Expand Up @@ -71,19 +70,6 @@ export class CoreUtils {
});
}

public static addLowerCaseKeysToObject(obj: IDatasetEntry | IUSSEntry): IDatasetEntry | IUSSEntry {

const result: { [key: string]: string } = {};
for (const key of Object.keys(obj)) {
// turn the object into a similar format to that returned by
// z/osmf so that users who use the list ds command in main
// zowe can use the same filtering options
this.log.trace("Remapping key for data set to match core CLI. Old key '%s' New key '%s'", key, key.toLowerCase());
result[key.toLowerCase()] = obj[key];
}
return result as typeof obj;
}

public static async getProfileMeta(): Promise<ICommandProfileTypeConfiguration[]> {
const ftpProfile = await require("../imperative").profiles as ICommandProfileTypeConfiguration[];
return ftpProfile;
Expand All @@ -93,10 +79,10 @@ export class CoreUtils {
return Logger.getAppLogger();
}

/**
* @internal
*/
public static getBinaryTransferModeOrDefault(isBinary: boolean): ITransferMode {
return (isBinary ? ITransferMode.BINARY : ITransferMode.ASCII) as unknown as ITransferMode;
public static getBinaryTransferModeOrDefault(isBinary: boolean, rdw = false): ITransferMode {
return (isBinary ?
(rdw ? ITransferMode.BINARY_RDW : ITransferMode.BINARY) :
(rdw ? ITransferMode.ASCII_RDW : ITransferMode.ASCII)
) as unknown as ITransferMode;
}
}
11 changes: 4 additions & 7 deletions src/api/DataSetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as fs from "fs";

import { IO, Logger } from "@zowe/imperative";
import { CoreUtils } from "./CoreUtils";
import { IAllocateDataSetOption, IDatasetEntry, IDownloadDataSetOption, IUploadDataSetOption } from "./doc/DataSetInterface";
import { IAllocateDataSetOption, IDatasetEntry, IDatasetMemberEntry, IDownloadDataSetOption, IUploadDataSetOption } from "./doc/DataSetInterface";
import { StreamUtils } from "./StreamUtils";
import { TransferMode, ZosAccessor } from "zos-node-accessor";
import { ITransferMode, TRACK } from "./doc";
Expand All @@ -32,8 +32,7 @@ export class DataSetUtils {
const files = await connection.listDatasets(pattern);

this.log.debug("Found %d matching data sets", files.length);
const filteredFiles = files.map((file: IDatasetEntry) => CoreUtils.addLowerCaseKeysToObject(file));
return filteredFiles as IDatasetEntry[];
return files;
}

/**
Expand All @@ -43,16 +42,14 @@ export class DataSetUtils {
* @param dsn - fully-qualified dataset name without quotes
* @returns member entries
*/
public static async listMembers(connection: ZosAccessor, dsn: string): Promise<IDatasetEntry[]> {
public static async listMembers(connection: ZosAccessor, dsn: string): Promise<IDatasetMemberEntry[]> {
this.log.debug("List members of %s", dsn);

const datasetname = dsn + "(*)";
const members = await connection.listDatasets(datasetname);

this.log.debug("Found %d members", members.length);
const filteredMembers = members.map((file: IDatasetEntry) => CoreUtils.addLowerCaseKeysToObject(file));

return filteredMembers as IDatasetEntry[];
return members;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/api/UssUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export class UssUtils {
}

this.log.debug("Found %d matching files", files.length);
const filteredFiles = files.map((file: IUSSEntry) => CoreUtils.addLowerCaseKeysToObject(file));
return filteredFiles as IUSSEntry[];
return files;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/api/doc/DataSetInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import { DatasetEntry } from "zos-node-accessor/lib/interfaces/DatasetEntry";
import { IFTPProgressHandler } from "./IFTPProgressHandler";
import { ITransferMode } from "./constants";
import { DatasetMemberEntry } from "zos-node-accessor/lib/interfaces/DatasetMemberEntry";

export interface IDatasetEntry extends DatasetEntry {}
export interface IDatasetMemberEntry extends DatasetMemberEntry {}

export interface IDownloadDataSetOption {
/**
Expand All @@ -29,7 +31,7 @@ export interface IDownloadDataSetOption {
/**
* TRANSFER_TYPE_ASCII, TRANSFER_TYPE_BIANRY, TRANSFER_TYPE_ASCII_RDW, or TRANSFER_TYPE_BINARY_RDW defined in CoreUtils.
*/
transferType?: string;
transferType?: ITransferMode;

/**
* Optional encoding for download and upload of z/OS data set
Expand Down
18 changes: 8 additions & 10 deletions src/cli/download/data-set/DataSet.Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import { ZosFilesMessages, ZosFilesUtils } from "@zowe/cli";
import { FTPBaseHandler } from "../../../FTPBase.Handler";
import { IFTPHandlerParams } from "../../../IFTPHandlerParams";
import { FTPProgressHandler } from "../../../FTPProgressHandler";
import { DataSetUtils, TRANSFER_TYPE_ASCII, TRANSFER_TYPE_ASCII_RDW, TRANSFER_TYPE_BINARY, TRANSFER_TYPE_BINARY_RDW } from "../../../api";
import { CoreUtils, DataSetUtils } from "../../../api";
import { ImperativeError } from "@zowe/imperative";
import { Utilities } from "../../Utilities";

export default class DownloadDataSetHandler extends FTPBaseHandler {
public async processFTP(params: IFTPHandlerParams): Promise<void> {
const file = params.arguments.file == null ?
ZosFilesUtils.getDirsFromDataSet(params.arguments.dataSet) :
params.arguments.file;
const args = params.arguments;
const file = args.file == null ?
ZosFilesUtils.getDirsFromDataSet(args.dataSet) :
args.file;
try {
// Validate the destination file name before proceeding
if (!(Utilities.isValidFileName(file))) {
Expand All @@ -32,18 +33,15 @@ export default class DownloadDataSetHandler extends FTPBaseHandler {
if (params.response && params.response.progress) {
progress = new FTPProgressHandler(params.response.progress, true);
}
let transferType = params.arguments.binary ? TRANSFER_TYPE_BINARY : TRANSFER_TYPE_ASCII;
if (params.arguments.rdw) {
transferType = params.arguments.binary ? TRANSFER_TYPE_BINARY_RDW : TRANSFER_TYPE_ASCII_RDW;
}
const transferType = CoreUtils.getBinaryTransferModeOrDefault(args.binary, args.rdw);
const options = {
localFile: file,
response: params.response,
transferType,
progress,
encoding: params.arguments.encoding
encoding: args.encoding
};
await DataSetUtils.downloadDataSet(params.connection, params.arguments.dataSet, options);
await DataSetUtils.downloadDataSet(params.connection, args.dataSet, options);

const successMsg = params.response.console.log(ZosFilesMessages.datasetDownloadedSuccessfully.message, file);
this.log.info(successMsg);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/submit/data-set/DataSet.Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

import { IFTPHandlerParams } from "../../../IFTPHandlerParams";
import { SubmitJobHandler } from "../SubmitJobHandler";
import { DataSetUtils, TRANSFER_TYPE_ASCII } from "../../../api";
import { DataSetUtils, ITransferMode } from "../../../api";

export default class SubmitJobFromLocalFileHandler extends SubmitJobHandler {
public async processFTP(params: IFTPHandlerParams): Promise<void> {
this.log.debug("Submitting a job from data set '%s'. Downloading before submitting...", params.arguments.dataSet);
const options = {
transferType: TRANSFER_TYPE_ASCII,
transferType: ITransferMode.ASCII as unknown as ITransferMode,
};
const dsContent = (await DataSetUtils.downloadDataSet(params.connection, params.arguments.dataSet, options)).toString();
this.log.debug("Downloaded data set '%s'. Submitting...", params.arguments.dataSet);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/view/data-set/DataSet.Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

import { IFTPHandlerParams } from "../../../IFTPHandlerParams";
import { FTPBaseHandler } from "../../../FTPBase.Handler";
import { DataSetUtils, TRANSFER_TYPE_ASCII, TRANSFER_TYPE_BINARY } from "../../../api";
import { CoreUtils, DataSetUtils } from "../../../api";

export default class ViewDataSetHandler extends FTPBaseHandler {

public async processFTP(params: IFTPHandlerParams): Promise<void> {
const options = {
transferType: params.arguments.binary ? TRANSFER_TYPE_BINARY : TRANSFER_TYPE_ASCII,
transferType: CoreUtils.getBinaryTransferModeOrDefault(params.arguments.binary),
response: params.response,
encoding: params.arguments.encoding
};
Expand Down

0 comments on commit e568aca

Please sign in to comment.