@azure/storage-file-share 12.9.0-alpha.20220105.6 → 12.9.0-alpha.20220210.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import { SpanStatusCode } from "@azure/core-tracing";
6
6
  import { Share, Directory, File } from "./generated/src/operations";
7
7
  import { newPipeline, Pipeline } from "./Pipeline";
8
8
  import { DEFAULT_MAX_DOWNLOAD_RETRY_REQUESTS, DEFAULT_HIGH_LEVEL_CONCURRENCY, FILE_MAX_SIZE_BYTES, FILE_RANGE_MAX_SIZE_BYTES, URLConstants, } from "./utils/constants";
9
- import { appendToURLPath, setURLParameter, truncatedISO8061Date, extractConnectionStringParts, getShareNameAndPathFromUrl, appendToURLQuery, httpAuthorizationToString, } from "./utils/utils.common";
9
+ import { appendToURLPath, setURLParameter, truncatedISO8061Date, extractConnectionStringParts, getShareNameAndPathFromUrl, appendToURLQuery, httpAuthorizationToString, setURLPath, setURLQueries, } from "./utils/utils.common";
10
10
  import { Credential } from "./credentials/Credential";
11
11
  import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential";
12
12
  import { AnonymousCredential } from "./credentials/AnonymousCredential";
@@ -1647,6 +1647,68 @@ export class ShareDirectoryClient extends StorageClient {
1647
1647
  span.end();
1648
1648
  }
1649
1649
  }
1650
+ /**
1651
+ * Renames a directory.
1652
+ * This API only supports renaming a directory in the same share.
1653
+ *
1654
+ * @param destinationPath - Specifies the destination path to rename to. The path will be encoded to put into a URL to specify the destination.
1655
+ * @param options - Options for the renaming operation.
1656
+ * @returns Response data for the file renaming operation.
1657
+ *
1658
+ * Example usage:
1659
+ *
1660
+ * ```js
1661
+ *
1662
+ * // Rename the directory
1663
+ * await diretoryClient.rename(destinationPath);
1664
+ * console.log("Renamed directory successfully!");
1665
+ * ```
1666
+ */
1667
+ async rename(destinationPath, options = {}) {
1668
+ const { span, updatedOptions } = createSpan("ShareDirectoryClient-rename", options);
1669
+ const split = destinationPath.split("?");
1670
+ let destinationUrl;
1671
+ if (split.length === 2) {
1672
+ const pathOnly = encodeURIComponent(split[0]);
1673
+ const renameDestination = `/${this.shareName}/${pathOnly}`;
1674
+ destinationUrl = setURLPath(this.url, renameDestination);
1675
+ destinationUrl = setURLQueries(destinationUrl, split[1]);
1676
+ }
1677
+ else if (split.length === 1) {
1678
+ const pathOnly = encodeURIComponent(destinationPath);
1679
+ const renameDestination = `/${this.shareName}/${pathOnly}`;
1680
+ destinationUrl = setURLPath(this.url, renameDestination);
1681
+ }
1682
+ else {
1683
+ throw new RangeError("Destination path should not contain more than one query string");
1684
+ }
1685
+ const destDirectory = new ShareDirectoryClient(destinationUrl, this.pipeline);
1686
+ try {
1687
+ const response = await destDirectory.context.rename(this.url, Object.assign(Object.assign({}, updatedOptions), { sourceLeaseAccessConditions: updatedOptions.sourceLeaseAccessConditions
1688
+ ? {
1689
+ sourceLeaseId: updatedOptions.sourceLeaseAccessConditions.leaseId,
1690
+ }
1691
+ : undefined, destinationLeaseAccessConditions: updatedOptions.destinationLeaseAccessConditions
1692
+ ? {
1693
+ destinationLeaseId: updatedOptions.destinationLeaseAccessConditions.leaseId,
1694
+ }
1695
+ : undefined }));
1696
+ return {
1697
+ destinationDirectoryClient: destDirectory,
1698
+ directoryRenameResponse: response,
1699
+ };
1700
+ }
1701
+ catch (e) {
1702
+ span.setStatus({
1703
+ code: SpanStatusCode.ERROR,
1704
+ message: e.message,
1705
+ });
1706
+ throw e;
1707
+ }
1708
+ finally {
1709
+ span.end();
1710
+ }
1711
+ }
1650
1712
  }
1651
1713
  /**
1652
1714
  * A ShareFileClient represents a URL to an Azure Storage file.
@@ -2993,6 +3055,68 @@ export class ShareFileClient extends StorageClient {
2993
3055
  const sas = generateFileSASQueryParameters(Object.assign({ shareName: this.shareName, filePath: this.path }, options), this.credential).toString();
2994
3056
  return appendToURLQuery(this.url, sas);
2995
3057
  }
3058
+ /**
3059
+ * Renames a file.
3060
+ * This API only supports renaming a file in the same share.
3061
+ *
3062
+ * @param destinationPath - Specifies the destination path to rename to. The path will be encoded to put into a URL to specify the destination.
3063
+ * @param options - Options for the renaming operation.
3064
+ * @returns Response data for the file renaming operation.
3065
+ *
3066
+ * Example usage:
3067
+ *
3068
+ * ```js
3069
+ *
3070
+ * // Rename the file
3071
+ * await fileClient.rename(destinationPath);
3072
+ * console.log("Renamed file successfully!");
3073
+ * ```
3074
+ */
3075
+ async rename(destinationPath, options = {}) {
3076
+ const { span, updatedOptions } = createSpan("ShareFileClient-rename", options);
3077
+ const split = destinationPath.split("?");
3078
+ let destinationUrl;
3079
+ if (split.length === 2) {
3080
+ const pathOnly = encodeURIComponent(split[0]);
3081
+ const renameDestination = `/${this.shareName}/${pathOnly}`;
3082
+ destinationUrl = setURLPath(this.url, renameDestination);
3083
+ destinationUrl = setURLQueries(destinationUrl, split[1]);
3084
+ }
3085
+ else if (split.length === 1) {
3086
+ const pathOnly = encodeURIComponent(destinationPath);
3087
+ const renameDestination = `/${this.shareName}/${pathOnly}`;
3088
+ destinationUrl = setURLPath(this.url, renameDestination);
3089
+ }
3090
+ else {
3091
+ throw new RangeError("Destination path should not contain more than one query string");
3092
+ }
3093
+ const destFile = new ShareFileClient(destinationUrl, this.pipeline);
3094
+ try {
3095
+ const response = await destFile.context.rename(this.url, Object.assign(Object.assign({}, updatedOptions), { sourceLeaseAccessConditions: updatedOptions.sourceLeaseAccessConditions
3096
+ ? {
3097
+ sourceLeaseId: updatedOptions.sourceLeaseAccessConditions.leaseId,
3098
+ }
3099
+ : undefined, destinationLeaseAccessConditions: updatedOptions.destinationLeaseAccessConditions
3100
+ ? {
3101
+ destinationLeaseId: updatedOptions.destinationLeaseAccessConditions.leaseId,
3102
+ }
3103
+ : undefined }));
3104
+ return {
3105
+ destinationFileClient: destFile,
3106
+ fileRenameResponse: response,
3107
+ };
3108
+ }
3109
+ catch (e) {
3110
+ span.setStatus({
3111
+ code: SpanStatusCode.ERROR,
3112
+ message: e.message,
3113
+ });
3114
+ throw e;
3115
+ }
3116
+ finally {
3117
+ span.end();
3118
+ }
3119
+ }
2996
3120
  }
2997
3121
  /**
2998
3122
  * A client that manages leases for a {@link ShareFileClient} or {@link ShareClient}.