UNPKG

@zowe/zos-files-for-zowe-sdk

Version:

Zowe SDK to interact with files and data sets on z/OS

102 lines 5.42 kB
"use strict"; /* * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-v20.html * * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. * */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Rename = void 0; const imperative_1 = require("@zowe/imperative"); const path_1 = require("path"); const core_for_zowe_sdk_1 = require("@zowe/core-for-zowe-sdk"); const ZosFiles_constants_1 = require("../../constants/ZosFiles.constants"); const ZosFiles_messages_1 = require("../../constants/ZosFiles.messages"); /** * Class to handle renaming data sets */ class Rename { /** * Rename a data set * @param {AbstractSession} session - z/OSMF connection info * @param {string} beforeDataSetName - the name of the data set to rename * @param {string} fterDataSetName - the new name of the data set * @returns {Promise<IZosFilesResponse>} */ static dataSet(session, beforeDataSetName, afterDataSetName, options) { return __awaiter(this, void 0, void 0, function* () { imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(beforeDataSetName, "beforeDataSetName"); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(afterDataSetName, "afterDataSetName"); return this.rename(session, afterDataSetName.trim(), { dsn: beforeDataSetName.trim() }, options); }); } /** * Rename a data set member * @param {AbstractSession} session - z/OSMF connection info * @param {string} dataSetName - the name of the data set the member belongs to * @param {string} beforeMemberName - the current name of the member * @param {string} afterMemberName - the new name of the member * @returns {Promise<IZosFilesResponse>} */ static dataSetMember(session, dataSetName, beforeMemberName, afterMemberName, options) { return __awaiter(this, void 0, void 0, function* () { imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(dataSetName, "dataSetName"); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(beforeMemberName, "beforeMemberName"); imperative_1.ImperativeExpect.toBeDefinedAndNonBlank(afterMemberName, "afterMemberName"); return this.rename(session, `${dataSetName.trim()}(${afterMemberName.trim()})`, { dsn: dataSetName.trim(), member: beforeMemberName.trim() }, options); }); } /** * * @param {AbstractSession} session - z/OSMF connection info * @param {string} afterDataSetName - The new name of the data set in the form 'dataset(member)' * @param {IDataSet} beforeDataSet - The data set you are renaming */ static rename(session_1, afterDataSetName_1, _a, options_1) { return __awaiter(this, arguments, void 0, function* (session, afterDataSetName, { dsn: beforeDataSetName, member: beforeMemberName }, options) { const endpoint = path_1.posix.join(ZosFiles_constants_1.ZosFilesConstants.RESOURCE, ZosFiles_constants_1.ZosFilesConstants.RES_DS_FILES, encodeURIComponent(afterDataSetName)); imperative_1.Logger.getAppLogger().debug(`Endpoint: ${endpoint}`); const payload = { "request": "rename", "from-dataset": { dsn: beforeDataSetName, member: beforeMemberName } }; const reqHeaders = [ imperative_1.Headers.APPLICATION_JSON, { [imperative_1.Headers.CONTENT_LENGTH]: JSON.stringify(payload).length.toString() }, core_for_zowe_sdk_1.ZosmfHeaders.ACCEPT_ENCODING ]; if (options && options.responseTimeout != null) { reqHeaders.push({ [core_for_zowe_sdk_1.ZosmfHeaders.X_IBM_RESPONSE_TIMEOUT]: options.responseTimeout.toString() }); } try { yield core_for_zowe_sdk_1.ZosmfRestClient.putExpectString(session, endpoint, reqHeaders, payload); return { success: true, commandResponse: ZosFiles_messages_1.ZosFilesMessages.dataSetRenamedSuccessfully.message }; } catch (err) { imperative_1.Logger.getAppLogger().error(err); throw err; } }); } } exports.Rename = Rename; //# sourceMappingURL=Rename.js.map