diff --git a/sdk/storage/storage-blob/samples/typescript/advanced.ts b/sdk/storage/storage-blob/samples/typescript/advanced.ts index 9fa45ea7f453..e6fb7a5e5a0a 100644 --- a/sdk/storage/storage-blob/samples/typescript/advanced.ts +++ b/sdk/storage/storage-blob/samples/typescript/advanced.ts @@ -37,7 +37,7 @@ async function main() { // Create a container const containerName = `newcontainer${new Date().getTime()}`; const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); // Create a blob const blobName = "newblob" + new Date().getTime(); @@ -46,7 +46,7 @@ async function main() { // Parallel uploading with uploadFileToBlockBlob in Node.js runtime // uploadFileToBlockBlob is only available in Node.js - await uploadFileToBlockBlob(Aborter.none, localFilePath, blockBlobURL, { + await uploadFileToBlockBlob(localFilePath, blockBlobURL, { blockSize: 4 * 1024 * 1024, // 4MB block size parallelism: 20, // 20 concurrency progress: ev => console.log(ev) @@ -56,12 +56,12 @@ async function main() { // Parallel uploading a Readable stream with uploadStreamToBlockBlob in Node.js runtime // uploadStreamToBlockBlob is only available in Node.js await uploadStreamToBlockBlob( - Aborter.timeout(30 * 60 * 60 * 1000), // Abort uploading with timeout in 30mins fs.createReadStream(localFilePath), blockBlobURL, 4 * 1024 * 1024, 20, { + abortSignal: Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins progress: ev => console.log(ev) } ); @@ -71,7 +71,7 @@ async function main() { // Uncomment following code in browsers because uploadBrowserDataToBlockBlob is only available in browsers /* const browserFile = document.getElementById("fileinput").files[0]; - await uploadBrowserDataToBlockBlob(Aborter.none, browserFile, blockBlobURL, { + await uploadBrowserDataToBlockBlob(browserFile, blockBlobURL, { blockSize: 4 * 1024 * 1024, // 4MB block size parallelism: 20, // 20 concurrency progress: ev => console.log(ev) @@ -83,12 +83,12 @@ async function main() { const fileSize = fs.statSync(localFilePath).size; const buffer = Buffer.alloc(fileSize); await downloadBlobToBuffer( - Aborter.timeout(30 * 60 * 60 * 1000), buffer, blockBlobURL, 0, undefined, { + abortSignal: Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins blockSize: 4 * 1024 * 1024, // 4MB block size parallelism: 20, // 20 concurrency progress: ev => console.log(ev) @@ -97,7 +97,7 @@ async function main() { console.log("downloadBlobToBuffer success"); // Delete container - await containerURL.delete(Aborter.none); + await containerURL.delete(); console.log("deleted container"); } diff --git a/sdk/storage/storage-blob/samples/typescript/basic.ts b/sdk/storage/storage-blob/samples/typescript/basic.ts index 4ca2bb6ed06d..847c637cfc62 100644 --- a/sdk/storage/storage-blob/samples/typescript/basic.ts +++ b/sdk/storage/storage-blob/samples/typescript/basic.ts @@ -56,7 +56,7 @@ async function main() { const containerName = `newcontainer${new Date().getTime()}`; const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - const createContainerResponse = await containerURL.create(Aborter.none); + const createContainerResponse = await containerURL.create(); console.log( `Create container ${containerName} successfully`, createContainerResponse.requestId @@ -68,7 +68,6 @@ async function main() { const blobURL = BlobURL.fromContainerURL(containerURL, blobName); const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); const uploadBlobResponse = await blockBlobURL.upload( - Aborter.none, content, content.length ); @@ -94,17 +93,14 @@ async function main() { // Get blob content from position 0 to the end // In Node.js, get downloaded data by accessing downloadBlockBlobResponse.readableStreamBody // In browsers, get downloaded data by accessing downloadBlockBlobResponse.blobBody - const downloadBlockBlobResponse: Models.BlobDownloadResponse = await blobURL.download( - Aborter.none, - 0 - ); + const downloadBlockBlobResponse: Models.BlobDownloadResponse = await blobURL.download(0); console.log( "Downloaded blob content", await streamToString(downloadBlockBlobResponse.readableStreamBody!) ); // Delete container - await containerURL.delete(Aborter.none); + await containerURL.delete(); console.log("deleted container"); } diff --git a/sdk/storage/storage-blob/src/Aborter.ts b/sdk/storage/storage-blob/src/Aborter.ts index 4e3c1c46bf0d..711c5a7da871 100644 --- a/sdk/storage/storage-blob/src/Aborter.ts +++ b/sdk/storage/storage-blob/src/Aborter.ts @@ -14,7 +14,7 @@ import { AbortSignalLike, isNode } from "@azure/ms-rest-js"; * * @example * // Abort without timeout - * await blockBlobURL.upload(Aborter.none, buf, buf.length); + * await blockBlobURL.upload(buf, buf.length); * * @example * // Abort container create in 1000ms diff --git a/sdk/storage/storage-blob/src/AppendBlobURL.ts b/sdk/storage/storage-blob/src/AppendBlobURL.ts index ebf663786be3..dd19d5bbb8dd 100644 --- a/sdk/storage/storage-blob/src/AppendBlobURL.ts +++ b/sdk/storage/storage-blob/src/AppendBlobURL.ts @@ -15,12 +15,14 @@ import { URLConstants } from "./utils/constants"; import { appendToURLPath, setURLParameter } from "./utils/utils.common"; export interface IAppendBlobCreateOptions { + abortSignal?: Aborter; accessConditions?: IBlobAccessConditions; blobHTTPHeaders?: Models.BlobHTTPHeaders; metadata?: IMetadata; } export interface IAppendBlobAppendBlockOptions { + abortSignal?: Aborter; accessConditions?: IAppendBlobAccessConditions; progress?: (progress: TransferProgressEvent) => void; transactionalContentMD5?: Uint8Array; @@ -133,16 +135,14 @@ export class AppendBlobURL extends BlobURL { * Creates a 0-length append blob. Call AppendBlock to append data to an append blob. * @see https://docs.microsoft.com/rest/api/storageservices/put-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IAppendBlobCreateOptions} [options] * @returns {Promise} * @memberof AppendBlobURL */ public async create( - aborter: Aborter, options: IAppendBlobCreateOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.appendBlobContext.create(0, { abortSignal: aborter, @@ -158,8 +158,6 @@ export class AppendBlobURL extends BlobURL { * Commits a new block of data to the end of the existing append blob. * @see https://docs.microsoft.com/rest/api/storageservices/append-block * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {HttpRequestBody} body * @param {number} contentLength * @param {IAppendBlobAppendBlockOptions} [options] @@ -167,11 +165,11 @@ export class AppendBlobURL extends BlobURL { * @memberof AppendBlobURL */ public async appendBlock( - aborter: Aborter, body: HttpRequestBody, contentLength: number, options: IAppendBlobAppendBlockOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.appendBlobContext.appendBlock(body, contentLength, { abortSignal: aborter, diff --git a/sdk/storage/storage-blob/src/BlobDownloadResponse.ts b/sdk/storage/storage-blob/src/BlobDownloadResponse.ts index 94f83926ce98..35b314b9b3b7 100644 --- a/sdk/storage/storage-blob/src/BlobDownloadResponse.ts +++ b/sdk/storage/storage-blob/src/BlobDownloadResponse.ts @@ -1,6 +1,5 @@ import { HttpResponse, isNode } from "@azure/ms-rest-js"; -import { Aborter } from "./Aborter"; import * as Models from "./generated/lib/models"; import { IMetadata } from "./models"; import { IRetriableReadableStreamOptions } from "./utils/RetriableReadableStream"; @@ -436,7 +435,6 @@ export class BlobDownloadResponse implements Models.BlobDownloadResponse { /** * Creates an instance of BlobDownloadResponse. * - * @param {Aborter} aborter * @param {Models.BlobDownloadResponse} originalResponse * @param {ReadableStreamGetter} getter * @param {number} offset @@ -445,7 +443,6 @@ export class BlobDownloadResponse implements Models.BlobDownloadResponse { * @memberof BlobDownloadResponse */ public constructor( - aborter: Aborter, originalResponse: Models.BlobDownloadResponse, getter: ReadableStreamGetter, offset: number, @@ -454,7 +451,6 @@ export class BlobDownloadResponse implements Models.BlobDownloadResponse { ) { this.originalResponse = originalResponse; this.blobDownloadStream = new RetriableReadableStream( - aborter, this.originalResponse.readableStreamBody!, getter, offset, diff --git a/sdk/storage/storage-blob/src/BlobURL.ts b/sdk/storage/storage-blob/src/BlobURL.ts index 9f87c1ad324c..5a0ff72579dd 100644 --- a/sdk/storage/storage-blob/src/BlobURL.ts +++ b/sdk/storage/storage-blob/src/BlobURL.ts @@ -16,6 +16,7 @@ import { import { appendToURLPath, setURLParameter } from "./utils/utils.common"; export interface IBlobDownloadOptions { + abortSignal?: Aborter; snapshot?: string; rangeGetContentMD5?: boolean; blobAccessConditions?: IBlobAccessConditions; @@ -40,58 +41,71 @@ export interface IBlobDownloadOptions { } export interface IBlobGetPropertiesOptions { + abortSignal?: Aborter; blobAccessConditions?: IBlobAccessConditions; } export interface IBlobDeleteOptions { + abortSignal?: Aborter; blobAccessConditions?: IBlobAccessConditions; deleteSnapshots?: Models.DeleteSnapshotsOptionType; } export interface IBlobSetHTTPHeadersOptions { + abortSignal?: Aborter; blobAccessConditions?: IBlobAccessConditions; } export interface IBlobSetMetadataOptions { + abortSignal?: Aborter; blobAccessConditions?: IBlobAccessConditions; } export interface IBlobAcquireLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IBlobReleaseLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IBlobRenewLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IBlobChangeLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IBlobBreakLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IBlobCreateSnapshotOptions { + abortSignal?: Aborter; metadata?: IMetadata; blobAccessConditions?: IBlobAccessConditions; } export interface IBlobStartCopyFromURLOptions { + abortSignal?: Aborter; metadata?: IMetadata; blobAccessConditions?: IBlobAccessConditions; sourceModifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IBlobAbortCopyFromURLOptions { + abortSignal?: Aborter; leaseAccessConditions?: Models.LeaseAccessConditions; } export interface IBlobSetTierOptions { + abortSignal?: Aborter; leaseAccessConditions?: Models.LeaseAccessConditions; } @@ -192,8 +206,6 @@ export class BlobURL extends StorageURL { * * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} offset From which position of the blob to download, >= 0 * @param {number} [count] How much data to be downloaded, > 0. Will download to the end when undefined * @param {IBlobDownloadOptions} [options] @@ -201,11 +213,11 @@ export class BlobURL extends StorageURL { * @memberof BlobURL */ public async download( - aborter: Aborter, offset: number, count?: number, options: IBlobDownloadOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.blobAccessConditions = options.blobAccessConditions || {}; options.blobAccessConditions.modifiedAccessConditions = options.blobAccessConditions.modifiedAccessConditions || {}; @@ -253,7 +265,6 @@ export class BlobURL extends StorageURL { } return new BlobDownloadResponse( - aborter, res, async (start: number): Promise => { const updatedOptions: Models.BlobDownloadOptionalParams = { @@ -292,6 +303,7 @@ export class BlobURL extends StorageURL { offset, res.contentLength!, { + abortSignal: aborter, maxRetryRequests: options.maxRetryRequests, progress: options.progress } @@ -303,16 +315,14 @@ export class BlobURL extends StorageURL { * for the blob. It does not return the content of the blob. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IBlobGetPropertiesOptions} [options] * @returns {Promise} * @memberof BlobURL */ public async getProperties( - aborter: Aborter, options: IBlobGetPropertiesOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.blobAccessConditions = options.blobAccessConditions || {}; return this.blobContext.getProperties({ abortSignal: aborter, @@ -329,16 +339,14 @@ export class BlobURL extends StorageURL { * Blob operation. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IBlobDeleteOptions} [options] * @returns {Promise} * @memberof BlobURL */ public async delete( - aborter: Aborter, options: IBlobDeleteOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.blobAccessConditions = options.blobAccessConditions || {}; return this.blobContext.deleteMethod({ abortSignal: aborter, @@ -355,16 +363,14 @@ export class BlobURL extends StorageURL { * or later. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/undelete-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @returns {Promise} * @memberof BlobURL */ public async undelete( - aborter: Aborter + aborter?: Aborter ): Promise { return this.blobContext.undelete({ - abortSignal: aborter + abortSignal: aborter || Aborter.none }); } @@ -375,8 +381,6 @@ export class BlobURL extends StorageURL { * these blob HTTP headers without a value will be cleared. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Models.BlobHTTPHeaders} [blobHTTPHeaders] If no value provided, or no value provided for * the specificed blob HTTP headers, these blob HTTP * headers without a value will be cleared. @@ -385,10 +389,10 @@ export class BlobURL extends StorageURL { * @memberof BlobURL */ public async setHTTPHeaders( - aborter: Aborter, blobHTTPHeaders?: Models.BlobHTTPHeaders, options: IBlobSetHTTPHeadersOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.blobAccessConditions = options.blobAccessConditions || {}; return this.blobContext.setHTTPHeaders({ abortSignal: aborter, @@ -406,8 +410,6 @@ export class BlobURL extends StorageURL { * metadata will be removed. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-metadata * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IMetadata} [metadata] Replace existing metadata with this value. * If no value provided the existing metadata will be removed. * @param {IBlobSetMetadataOptions} [options] @@ -415,10 +417,10 @@ export class BlobURL extends StorageURL { * @memberof BlobURL */ public async setMetadata( - aborter: Aborter, metadata?: IMetadata, options: IBlobSetMetadataOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.blobAccessConditions = options.blobAccessConditions || {}; return this.blobContext.setMetadata({ abortSignal: aborter, @@ -435,8 +437,6 @@ export class BlobURL extends StorageURL { * In versions prior to 2012-02-12, the lock duration is 60 seconds. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} proposedLeaseId Can be specified in any valid GUID string format * @param {number} duration The lock duration can be 15 to 60 seconds, or can be infinite * @param {IBlobAcquireLeaseOptions} [options] @@ -444,11 +444,11 @@ export class BlobURL extends StorageURL { * @memberof BlobURL */ public async acquireLease( - aborter: Aborter, proposedLeaseId: string, duration: number, options: IBlobAcquireLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.blobContext.acquireLease({ abortSignal: aborter, duration, @@ -462,18 +462,16 @@ export class BlobURL extends StorageURL { * acquire a lease against the blob. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} leaseId * @param {IBlobReleaseLeaseOptions} [options] * @returns {Promise} * @memberof BlobURL */ public async releaseLease( - aborter: Aborter, leaseId: string, options: IBlobReleaseLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.blobContext.releaseLease(leaseId, { abortSignal: aborter, modifiedAccessConditions: options.modifiedAccessConditions @@ -484,18 +482,16 @@ export class BlobURL extends StorageURL { * To renew an existing lease. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} leaseId * @param {IBlobRenewLeaseOptions} [options] * @returns {Promise} * @memberof BlobURL */ public async renewLease( - aborter: Aborter, leaseId: string, options: IBlobRenewLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.blobContext.renewLease(leaseId, { abortSignal: aborter, modifiedAccessConditions: options.modifiedAccessConditions @@ -506,8 +502,6 @@ export class BlobURL extends StorageURL { * To change the ID of an existing lease. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} leaseId * @param {string} proposedLeaseId * @param {IBlobChangeLeaseOptions} [options] @@ -515,11 +509,11 @@ export class BlobURL extends StorageURL { * @memberof BlobURL */ public async changeLease( - aborter: Aborter, leaseId: string, proposedLeaseId: string, options: IBlobChangeLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.blobContext.changeLease(leaseId, proposedLeaseId, { abortSignal: aborter, modifiedAccessConditions: options.modifiedAccessConditions @@ -531,18 +525,16 @@ export class BlobURL extends StorageURL { * until the current lease period has expired. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} [breakPeriod] * @param {IBlobBreakLeaseOptions} [options] * @returns {Promise} * @memberof BlobURL */ public async breakLease( - aborter: Aborter, breakPeriod?: number, options: IBlobBreakLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.blobContext.breakLease({ abortSignal: aborter, breakPeriod, @@ -554,16 +546,14 @@ export class BlobURL extends StorageURL { * Creates a read-only snapshot of a blob. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/snapshot-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IBlobCreateSnapshotOptions} [options] * @returns {Promise} * @memberof BlobURL */ public async createSnapshot( - aborter: Aborter, options: IBlobCreateSnapshotOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.blobAccessConditions = options.blobAccessConditions || {}; return this.blobContext.createSnapshot({ abortSignal: aborter, @@ -584,18 +574,16 @@ export class BlobURL extends StorageURL { * operation to copy from another storage account. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/copy-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} copySource * @param {IBlobStartCopyFromURLOptions} [options] * @returns {Promise} * @memberof BlobURL */ public async startCopyFromURL( - aborter: Aborter, copySource: string, options: IBlobStartCopyFromURLOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.blobAccessConditions = options.blobAccessConditions || {}; options.sourceModifiedAccessConditions = options.sourceModifiedAccessConditions || {}; @@ -622,18 +610,16 @@ export class BlobURL extends StorageURL { * length and full metadata. Version 2012-02-12 and newer. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/abort-copy-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} copyId * @param {IBlobAbortCopyFromURLOptions} [options] * @returns {Promise} * @memberof BlobURL */ public async abortCopyFromURL( - aborter: Aborter, copyId: string, options: IBlobAbortCopyFromURLOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.blobContext.abortCopyFromURL(copyId, { abortSignal: aborter, leaseAccessConditions: options.leaseAccessConditions @@ -648,18 +634,16 @@ export class BlobURL extends StorageURL { * storage type. This operation does not update the blob's ETag. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Models.AccessTier} tier * @param {IBlobSetTierOptions} [options] * @returns {Promise} * @memberof BlobURL */ public async setTier( - aborter: Aborter, tier: Models.AccessTier, options: IBlobSetTierOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return await this.blobContext.setTier(tier, { abortSignal: aborter, leaseAccessConditions: options.leaseAccessConditions diff --git a/sdk/storage/storage-blob/src/BlockBlobURL.ts b/sdk/storage/storage-blob/src/BlockBlobURL.ts index 0a89318d765a..4a1aa8cf20ec 100644 --- a/sdk/storage/storage-blob/src/BlockBlobURL.ts +++ b/sdk/storage/storage-blob/src/BlockBlobURL.ts @@ -12,6 +12,7 @@ import { URLConstants } from "./utils/constants"; import { appendToURLPath, setURLParameter } from "./utils/utils.common"; export interface IBlockBlobUploadOptions { + abortSignal?: Aborter; accessConditions?: IBlobAccessConditions; blobHTTPHeaders?: Models.BlobHTTPHeaders; metadata?: IMetadata; @@ -19,24 +20,28 @@ export interface IBlockBlobUploadOptions { } export interface IBlockBlobStageBlockOptions { + abortSignal?: Aborter; leaseAccessConditions?: Models.LeaseAccessConditions; progress?: (progress: TransferProgressEvent) => void; transactionalContentMD5?: Uint8Array; } export interface IBlockBlobStageBlockFromURLOptions { + abortSignal?: Aborter; range?: IRange; leaseAccessConditions?: Models.LeaseAccessConditions; sourceContentMD5?: Uint8Array; } export interface IBlockBlobCommitBlockListOptions { + abortSignal?: Aborter; accessConditions?: IBlobAccessConditions; blobHTTPHeaders?: Models.BlobHTTPHeaders; metadata?: IMetadata; } export interface IBlockBlobGetBlockListOptions { + abortSignal?: Aborter; leaseAccessConditions?: Models.LeaseAccessConditions; } @@ -156,8 +161,6 @@ export class BlockBlobURL extends BlobURL { * * @see https://docs.microsoft.com/rest/api/storageservices/put-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {HttpRequestBody} body * @param {number} contentLength * @param {IBlockBlobUploadOptions} [options] @@ -165,11 +168,11 @@ export class BlockBlobURL extends BlobURL { * @memberof BlockBlobURL */ public async upload( - aborter: Aborter, body: HttpRequestBody, contentLength: number, options: IBlockBlobUploadOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.blockBlobContext.upload(body, contentLength, { abortSignal: aborter, @@ -187,8 +190,6 @@ export class BlockBlobURL extends BlobURL { * committed by a call to commitBlockList. * @see https://docs.microsoft.com/rest/api/storageservices/put-block * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} blockId A 64-byte value that is base64-encoded * @param {HttpRequestBody} body * @param {number} contentLength @@ -197,12 +198,12 @@ export class BlockBlobURL extends BlobURL { * @memberof BlockBlobURL */ public async stageBlock( - aborter: Aborter, blockId: string, body: HttpRequestBody, contentLength: number, options: IBlockBlobStageBlockOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.blockBlobContext.stageBlock(blockId, contentLength, body, { abortSignal: aborter, leaseAccessConditions: options.leaseAccessConditions, @@ -217,8 +218,6 @@ export class BlockBlobURL extends BlobURL { * This API is available starting in version 2018-03-28. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} blockId A 64-byte value that is base64-encoded * @param {string} sourceURL Specifies the URL of the blob. The value * may be a URL of up to 2 KB in length that specifies a blob. @@ -236,13 +235,13 @@ export class BlockBlobURL extends BlobURL { * @memberof BlockBlobURL */ public async stageBlockFromURL( - aborter: Aborter, blockId: string, sourceURL: string, offset: number, count?: number, options: IBlockBlobStageBlockFromURLOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.blockBlobContext.stageBlockFromURL(blockId, 0, sourceURL, { abortSignal: aborter, leaseAccessConditions: options.leaseAccessConditions, @@ -260,18 +259,16 @@ export class BlockBlobURL extends BlobURL { * blocks together. Any blocks not specified in the block list and permanently deleted. * @see https://docs.microsoft.com/rest/api/storageservices/put-block-list * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string[]} blocks Array of 64-byte value that is base64-encoded * @param {IBlockBlobCommitBlockListOptions} [options] * @returns {Promise} * @memberof BlockBlobURL */ public async commitBlockList( - aborter: Aborter, blocks: string[], options: IBlockBlobCommitBlockListOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.blockBlobContext.commitBlockList( { latest: blocks }, @@ -291,18 +288,16 @@ export class BlockBlobURL extends BlobURL { * using the specified block list filter. * @see https://docs.microsoft.com/rest/api/storageservices/get-block-list * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Models.BlockListType} listType * @param {IBlockBlobGetBlockListOptions} [options] * @returns {Promise} * @memberof BlockBlobURL */ public async getBlockList( - aborter: Aborter, listType: Models.BlockListType, options: IBlockBlobGetBlockListOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; const res = await this.blockBlobContext.getBlockList(listType, { abortSignal: aborter, leaseAccessConditions: options.leaseAccessConditions diff --git a/sdk/storage/storage-blob/src/ContainerURL.ts b/sdk/storage/storage-blob/src/ContainerURL.ts index f1d47c8a94af..0d39001e5e4b 100644 --- a/sdk/storage/storage-blob/src/ContainerURL.ts +++ b/sdk/storage/storage-blob/src/ContainerURL.ts @@ -10,23 +10,28 @@ import { ETagNone } from "./utils/constants"; import { appendToURLPath, truncatedISO8061Date } from "./utils/utils.common"; export interface IContainerCreateOptions { + abortSignal?: Aborter; metadata?: IMetadata; access?: Models.PublicAccessType; } export interface IContainerGetPropertiesOptions { + abortSignal?: Aborter; leaseAccessConditions?: Models.LeaseAccessConditions; } export interface IContainerDeleteMethodOptions { + abortSignal?: Aborter; containerAccessConditions?: IContainerAccessConditions; } export interface IContainerSetMetadataOptions { + abortSignal?: Aborter; containerAccessConditions?: IContainerAccessConditions; } export interface IContainerGetAccessPolicyOptions { + abortSignal?: Aborter; leaseAccessConditions?: Models.LeaseAccessConditions; } @@ -78,26 +83,32 @@ export declare type ContainerGetAccessPolicyResponse = { }; export interface IContainerSetAccessPolicyOptions { + abortSignal?: Aborter; containerAccessConditions?: IContainerAccessConditions; } export interface IContainerAcquireLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IContainerReleaseLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IContainerRenewLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IContainerBreakLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } export interface IContainerChangeLeaseOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } @@ -189,21 +200,20 @@ export class ContainerURL extends StorageURL { * the same name already exists, the operation fails. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-container * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IContainerCreateOptions} [options] * @returns {Promise} * @memberof ContainerURL */ public async create( - aborter: Aborter, options: IContainerCreateOptions = {} ): Promise { + if (!options.abortSignal) { + options.abortSignal = Aborter.none; + } // Spread operator in destructuring assignments, // this will filter out unwanted properties from the response object into result object return this.containerContext.create({ - ...options, - abortSignal: aborter + ...options }); } @@ -212,20 +222,19 @@ export class ContainerURL extends StorageURL { * container. The data returned does not include the container's list of blobs. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IContainersGetPropertiesOptions} [options] * @returns {Promise} * @memberof ContainerURL */ public async getProperties( - aborter: Aborter, options: IContainerGetPropertiesOptions = {} ): Promise { if (!options.leaseAccessConditions) { options.leaseAccessConditions = {}; } + const aborter = options.abortSignal || Aborter.none; + return this.containerContext.getProperties({ abortSignal: aborter, ...options.leaseAccessConditions @@ -237,16 +246,15 @@ export class ContainerURL extends StorageURL { * contained within it are later deleted during garbage collection. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-container * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Models.ContainersDeleteMethodOptionalParams} [options] * @returns {Promise} * @memberof ContainerURL */ public async delete( - aborter: Aborter, options: IContainerDeleteMethodOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; + if (!options.containerAccessConditions) { options.containerAccessConditions = {}; } @@ -290,8 +298,6 @@ export class ContainerURL extends StorageURL { * * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-container-metadata * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IMetadata} [metadata] Replace existing metadata with this value. * If no value provided the existing metadata will be removed. * @param {IContainerSetMetadataOptions} [options] @@ -299,10 +305,11 @@ export class ContainerURL extends StorageURL { * @memberof ContainerURL */ public async setMetadata( - aborter: Aborter, metadata?: IMetadata, options: IContainerSetMetadataOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; + if (!options.containerAccessConditions) { options.containerAccessConditions = {}; } @@ -350,19 +357,17 @@ export class ContainerURL extends StorageURL { * * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-acl * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IContainerGetAccessPolicyOptions} [options] * @returns {Promise} * @memberof ContainerURL */ public async getAccessPolicy( - aborter: Aborter, options: IContainerGetAccessPolicyOptions = {} ): Promise { if (!options.leaseAccessConditions) { options.leaseAccessConditions = {}; } + const aborter = options.abortSignal || Aborter.none; const response = await this.containerContext.getAccessPolicy({ abortSignal: aborter, @@ -404,8 +409,6 @@ export class ContainerURL extends StorageURL { * removed. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-container-acl * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {PublicAccessType} [access] * @param {ISignedIdentifier[]} [containerAcl] * @param {IContainerSetAccessPolicyOptions} [options] @@ -413,11 +416,11 @@ export class ContainerURL extends StorageURL { * @memberof ContainerURL */ public async setAccessPolicy( - aborter: Aborter, access?: Models.PublicAccessType, containerAcl?: ISignedIdentifier[], options: IContainerSetAccessPolicyOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.containerAccessConditions = options.containerAccessConditions || {}; const acl: Models.SignedIdentifier[] = []; for (const identifier of containerAcl || []) { @@ -447,8 +450,6 @@ export class ContainerURL extends StorageURL { * The lock duration can be 15 to 60 seconds, or can be infinite. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} proposedLeaseId Can be specified in any valid GUID string format * @param {number} duration Must be between 15 to 60 seconds, or infinite (-1) * @param {IContainerAcquireLeaseOptions} [options] @@ -456,11 +457,11 @@ export class ContainerURL extends StorageURL { * @memberof ContainerURL */ public async acquireLease( - aborter: Aborter, proposedLeaseId: string, duration: number, options: IContainerAcquireLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.containerContext.acquireLease({ abortSignal: aborter, duration, @@ -474,18 +475,16 @@ export class ContainerURL extends StorageURL { * immediately acquire a lease against the container. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} leaseId * @param {IContainerReleaseLeaseOptions} [options] * @returns {Promise} * @memberof ContainerURL */ public async releaseLease( - aborter: Aborter, leaseId: string, options: IContainerReleaseLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.containerContext.releaseLease(leaseId, { abortSignal: aborter, modifiedAccessConditions: options.modifiedAccessConditions @@ -496,18 +495,16 @@ export class ContainerURL extends StorageURL { * To renew an existing lease. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} leaseId * @param {IContainerRenewLeaseOptions} [options] * @returns {Promise} * @memberof ContainerURL */ public async renewLease( - aborter: Aborter, leaseId: string, options: IContainerRenewLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.containerContext.renewLease(leaseId, { abortSignal: aborter, modifiedAccessConditions: options.modifiedAccessConditions @@ -519,18 +516,16 @@ export class ContainerURL extends StorageURL { * until the current lease period has expired. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} period break period * @param {IContainerBreakLeaseOptions} [options] * @returns {Promise} * @memberof ContainerURL */ public async breakLease( - aborter: Aborter, period: number, options: IContainerBreakLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.containerContext.breakLease({ abortSignal: aborter, breakPeriod: period, @@ -542,8 +537,6 @@ export class ContainerURL extends StorageURL { * To change the ID of an existing lease. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} leaseId * @param {string} proposedLeaseId * @param {IContainerChangeLeaseOptions} [options] @@ -551,11 +544,11 @@ export class ContainerURL extends StorageURL { * @memberof ContainerURL */ public async changeLease( - aborter: Aborter, leaseId: string, proposedLeaseId: string, options: IContainerChangeLeaseOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.containerContext.changeLease(leaseId, proposedLeaseId, { abortSignal: aborter, modifiedAccessConditions: options.modifiedAccessConditions diff --git a/sdk/storage/storage-blob/src/PageBlobURL.ts b/sdk/storage/storage-blob/src/PageBlobURL.ts index 13e975eaafd4..6300802fd06b 100644 --- a/sdk/storage/storage-blob/src/PageBlobURL.ts +++ b/sdk/storage/storage-blob/src/PageBlobURL.ts @@ -16,6 +16,7 @@ import { URLConstants } from "./utils/constants"; import { appendToURLPath, setURLParameter } from "./utils/utils.common"; export interface IPageBlobCreateOptions { + abortSignal?: Aborter; accessConditions?: IBlobAccessConditions; blobSequenceNumber?: number; blobHTTPHeaders?: Models.BlobHTTPHeaders; @@ -23,33 +24,40 @@ export interface IPageBlobCreateOptions { } export interface IPageBlobUploadPagesOptions { + abortSignal?: Aborter; accessConditions?: IPageBlobAccessConditions; progress?: (progress: TransferProgressEvent) => void; transactionalContentMD5?: Uint8Array; } export interface IPageBlobClearPagesOptions { + abortSignal?: Aborter; accessConditions?: IPageBlobAccessConditions; } export interface IPageBlobGetPageRangesOptions { + abortSignal?: Aborter; accessConditions?: IBlobAccessConditions; } export interface IPageBlobGetPageRangesDiffOptions { + abortSignal?: Aborter; accessConditions?: IBlobAccessConditions; range?: string; } export interface IPageBlobResizeOptions { + abortSignal?: Aborter; accessConditions?: IBlobAccessConditions; } export interface IPageBlobUpdateSequenceNumberOptions { + abortSignal?: Aborter; accessConditions?: IBlobAccessConditions; } export interface IPageBlobStartCopyIncrementalOptions { + abortSignal?: Aborter; modifiedAccessConditions?: Models.ModifiedAccessConditions; } @@ -161,18 +169,16 @@ export class PageBlobURL extends BlobURL { * data to a page blob. * @see https://docs.microsoft.com/rest/api/storageservices/put-blob * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} size * @param {IPageBlobCreateOptions} [options] * @returns {Promise} * @memberof PageBlobURL */ public async create( - aborter: Aborter, size: number, options: IPageBlobCreateOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.pageBlobContext.create(0, size, { abortSignal: aborter, @@ -189,8 +195,6 @@ export class PageBlobURL extends BlobURL { * Writes 1 or more pages to the page blob. The start and end offsets must be a multiple of 512. * @see https://docs.microsoft.com/rest/api/storageservices/put-page * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {HttpRequestBody} body * @param {number} offset Offset of destination page blob * @param {number} count Content length of body, also how many bytes to be uploaded @@ -199,12 +203,12 @@ export class PageBlobURL extends BlobURL { * @memberof PageBlobURL */ public async uploadPages( - aborter: Aborter, body: HttpRequestBody, offset: number, count: number, options: IPageBlobUploadPagesOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.pageBlobContext.uploadPages(body, count, { abortSignal: aborter, @@ -223,8 +227,6 @@ export class PageBlobURL extends BlobURL { * Frees the specified pages from the page blob. * @see https://docs.microsoft.com/rest/api/storageservices/put-page * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} offset * @param {number} count * @param {IPageBlobClearPagesOptions} [options] @@ -232,11 +234,11 @@ export class PageBlobURL extends BlobURL { * @memberof PageBlobURL */ public async clearPages( - aborter: Aborter, offset: number, count: number, options: IPageBlobClearPagesOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.pageBlobContext.clearPages(0, { abortSignal: aborter, @@ -253,8 +255,6 @@ export class PageBlobURL extends BlobURL { * Returns the list of valid page ranges for a page blob or snapshot of a page blob. * @see https://docs.microsoft.com/rest/api/storageservices/get-page-ranges * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} offset * @param {number} count * @param {IPageBlobGetPageRangesOptions} [options] @@ -262,11 +262,11 @@ export class PageBlobURL extends BlobURL { * @memberof PageBlobURL */ public async getPageRanges( - aborter: Aborter, offset: number, count: number, options: IPageBlobGetPageRangesOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.pageBlobContext.getPageRanges({ abortSignal: aborter, @@ -281,8 +281,6 @@ export class PageBlobURL extends BlobURL { * Gets the collection of page ranges that differ between a specified snapshot and this page blob. * @see https://docs.microsoft.com/rest/api/storageservices/get-page-ranges * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} offset * @param {number} count * @param {string} prevSnapshot @@ -291,12 +289,12 @@ export class PageBlobURL extends BlobURL { * @memberof PageBlobURL */ public async getPageRangesDiff( - aborter: Aborter, offset: number, count: number, prevSnapshot: string, options: IPageBlobGetPageRangesDiffOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.pageBlobContext.getPageRangesDiff({ abortSignal: aborter, @@ -312,18 +310,16 @@ export class PageBlobURL extends BlobURL { * Resizes the page blob to the specified size (which must be a multiple of 512). * @see https://docs.microsoft.com/rest/api/storageservices/set-blob-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} size * @param {IPageBlobResizeOptions} [options] * @returns {Promise} * @memberof PageBlobURL */ public async resize( - aborter: Aborter, size: number, options: IPageBlobResizeOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.pageBlobContext.resize(size, { abortSignal: aborter, @@ -337,8 +333,6 @@ export class PageBlobURL extends BlobURL { * Sets a page blob's sequence number. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Models.SequenceNumberActionType} sequenceNumberAction * @param {number} [sequenceNumber] Required if sequenceNumberAction is max or update * @param {IPageBlobUpdateSequenceNumberOptions} [options] @@ -346,11 +340,11 @@ export class PageBlobURL extends BlobURL { * @memberof PageBlobURL */ public async updateSequenceNumber( - aborter: Aborter, sequenceNumberAction: Models.SequenceNumberActionType, sequenceNumber?: number, options: IPageBlobUpdateSequenceNumberOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; options.accessConditions = options.accessConditions || {}; return this.pageBlobContext.updateSequenceNumber(sequenceNumberAction, { abortSignal: aborter, @@ -369,8 +363,6 @@ export class PageBlobURL extends BlobURL { * @see https://docs.microsoft.com/rest/api/storageservices/incremental-copy-blob * @see https://docs.microsoft.com/en-us/azure/virtual-machines/windows/incremental-snapshots * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} copySource Specifies the name of the source page blob snapshot. For example, * https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot= * @param {IPageBlobStartCopyIncrementalOptions} [options] @@ -378,10 +370,10 @@ export class PageBlobURL extends BlobURL { * @memberof PageBlobURL */ public async startCopyIncremental( - aborter: Aborter, copySource: string, options: IPageBlobStartCopyIncrementalOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.pageBlobContext.copyIncremental(copySource, { abortSignal: aborter, modifiedAccessConditions: options.modifiedAccessConditions diff --git a/sdk/storage/storage-blob/src/ServiceURL.ts b/sdk/storage/storage-blob/src/ServiceURL.ts index a1d32daf1c1f..11ef39f314b7 100644 --- a/sdk/storage/storage-blob/src/ServiceURL.ts +++ b/sdk/storage/storage-blob/src/ServiceURL.ts @@ -85,10 +85,10 @@ export class ServiceURL extends StorageURL { * @memberof ServiceURL */ public async getProperties( - aborter: Aborter + aborter?: Aborter ): Promise { return this.serviceContext.getProperties({ - abortSignal: aborter + abortSignal: aborter || Aborter.none }); } @@ -97,18 +97,18 @@ export class ServiceURL extends StorageURL { * for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules and soft delete settings. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-service-properties} * + * @param {Models.StorageServiceProperties} properties * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), * goto documents of Aborter for more examples about request cancellation - * @param {Models.StorageServiceProperties} properties * @returns {Promise} * @memberof ServiceURL */ public async setProperties( - aborter: Aborter, - properties: Models.StorageServiceProperties + properties: Models.StorageServiceProperties, + aborter?: Aborter ): Promise { return this.serviceContext.setProperties(properties, { - abortSignal: aborter + abortSignal: aborter || Aborter.none }); } @@ -124,10 +124,10 @@ export class ServiceURL extends StorageURL { * @memberof ServiceURL */ public async getStatistics( - aborter: Aborter + aborter?: Aborter ): Promise { return this.serviceContext.getStatistics({ - abortSignal: aborter + abortSignal: aborter || Aborter.none }); } @@ -144,10 +144,10 @@ export class ServiceURL extends StorageURL { * @memberof ServiceURL */ public async getAccountInfo( - aborter: Aborter + aborter?: Aborter ): Promise { return this.serviceContext.getAccountInfo({ - abortSignal: aborter + abortSignal: aborter || Aborter.none }); } diff --git a/sdk/storage/storage-blob/src/highlevel.browser.ts b/sdk/storage/storage-blob/src/highlevel.browser.ts index 3a3796e0b006..f5a0dc52a91e 100644 --- a/sdk/storage/storage-blob/src/highlevel.browser.ts +++ b/sdk/storage/storage-blob/src/highlevel.browser.ts @@ -1,6 +1,5 @@ import { generateUuid } from "@azure/ms-rest-js"; -import { Aborter } from "./Aborter"; import { BlockBlobURL } from "./BlockBlobURL"; import { BlobUploadCommonResponse, @@ -25,22 +24,18 @@ import { generateBlockID } from "./utils/utils.common"; * to commit the block list. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Blob | ArrayBuffer | ArrayBufferView} browserData Blob, File, ArrayBuffer or ArrayBufferView * @param {BlockBlobURL} blockBlobURL * @param {IUploadToBlockBlobOptions} [options] * @returns {Promise} */ export async function uploadBrowserDataToBlockBlob( - aborter: Aborter, browserData: Blob | ArrayBuffer | ArrayBufferView, blockBlobURL: BlockBlobURL, - options?: IUploadToBlockBlobOptions + options: IUploadToBlockBlobOptions = {} ): Promise { const browserBlob = new Blob([browserData]); return UploadSeekableBlobToBlockBlob( - aborter, (offset: number, size: number): Blob => { return browserBlob.slice(offset, offset + size); }, @@ -60,8 +55,6 @@ export async function uploadBrowserDataToBlockBlob( * Otherwise, this method will call stageBlock to upload blocks, and finally call commitBlockList * to commit the block list. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {(offset: number, size: number) => Blob} blobFactory * @param {number} size * @param {BlockBlobURL} blockBlobURL @@ -69,7 +62,6 @@ export async function uploadBrowserDataToBlockBlob( * @returns {Promise} */ async function UploadSeekableBlobToBlockBlob( - aborter: Aborter, blobFactory: (offset: number, size: number) => Blob, size: number, blockBlobURL: BlockBlobURL, @@ -118,7 +110,7 @@ async function UploadSeekableBlobToBlockBlob( } if (size <= options.maxSingleShotSize) { - return blockBlobURL.upload(aborter, blobFactory(0, size), size, options); + return blockBlobURL.upload(blobFactory(0, size), size, options); } const numBlocks: number = Math.floor((size - 1) / options.blockSize) + 1; @@ -143,11 +135,11 @@ async function UploadSeekableBlobToBlockBlob( const contentLength = end - start; blockList.push(blockID); await blockBlobURL.stageBlock( - aborter, blockID, blobFactory(start, contentLength), contentLength, { + abortSignal: options.abortSignal, leaseAccessConditions: options.blobAccessConditions! .leaseAccessConditions } @@ -165,5 +157,5 @@ async function UploadSeekableBlobToBlockBlob( } await batch.do(); - return blockBlobURL.commitBlockList(aborter, blockList, options); + return blockBlobURL.commitBlockList(blockList, options); } diff --git a/sdk/storage/storage-blob/src/highlevel.common.ts b/sdk/storage/storage-blob/src/highlevel.common.ts index 6f7468928043..22a2bd35e3a1 100644 --- a/sdk/storage/storage-blob/src/highlevel.common.ts +++ b/sdk/storage/storage-blob/src/highlevel.common.ts @@ -1,5 +1,6 @@ import { HttpResponse, TransferProgressEvent } from "@azure/ms-rest-js"; +import { Aborter } from "./Aborter"; import * as Models from "./generated/lib/models"; import { IBlobAccessConditions } from "./models"; @@ -10,6 +11,16 @@ import { IBlobAccessConditions } from "./models"; * @interface IUploadToBlockBlobOptions */ export interface IUploadToBlockBlobOptions { + /** + * Aborter instance to cancel request. It can be created with Aborter.none + * or Aborter.timeout(). Go to documents of {@link Aborter} for more examples + * about request cancellation. + * + * @type {Aborter} + * @memberof IUploadToBlockBlobOptions + */ + abortSignal?: Aborter; + /** * Destination block blob size in bytes. * @@ -91,6 +102,16 @@ export type BlobUploadCommonResponse = Models.BlockBlobUploadHeaders & { * @interface IDownloadFromBlobOptions */ export interface IDownloadFromBlobOptions { + /** + * Aborter instance to cancel request. It can be created with Aborter.none + * or Aborter.timeout(). Go to documents of {@link Aborter} for more examples + * about request cancellation. + * + * @type {Aborter} + * @memberof IUploadToBlockBlobOptions + */ + abortSignal?: Aborter; + /** * blockSize is the data every request trying to download. * Must be >= 0, if set to 0 or undefined, blockSize will automatically calculated according diff --git a/sdk/storage/storage-blob/src/highlevel.node.ts b/sdk/storage/storage-blob/src/highlevel.node.ts index 3062e0ef7048..2ba6f65176a2 100644 --- a/sdk/storage/storage-blob/src/highlevel.node.ts +++ b/sdk/storage/storage-blob/src/highlevel.node.ts @@ -33,22 +33,18 @@ import { streamToBuffer } from "./utils/utils.node"; * to commit the block list. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} filePath Full path of local file * @param {BlockBlobURL} blockBlobURL BlockBlobURL * @param {IUploadToBlockBlobOptions} [options] IUploadToBlockBlobOptions * @returns {(Promise)} ICommonResponse */ export async function uploadFileToBlockBlob( - aborter: Aborter, filePath: string, blockBlobURL: BlockBlobURL, - options?: IUploadToBlockBlobOptions + options: IUploadToBlockBlobOptions = {} ): Promise { const size = fs.statSync(filePath).size; return uploadResetableStreamToBlockBlob( - aborter, (offset, count) => fs.createReadStream(filePath, { autoClose: true, @@ -73,8 +69,6 @@ export async function uploadFileToBlockBlob( * to commit the block list. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {(offset: number) => NodeJS.ReadableStream} streamFactory Returns a Node.js Readable stream starting * from the offset defined * @param {number} size Size of the block blob @@ -83,7 +77,6 @@ export async function uploadFileToBlockBlob( * @returns {(Promise)} ICommonResponse */ async function uploadResetableStreamToBlockBlob( - aborter: Aborter, streamFactory: (offset: number, count?: number) => NodeJS.ReadableStream, size: number, blockBlobURL: BlockBlobURL, @@ -132,7 +125,7 @@ async function uploadResetableStreamToBlockBlob( } if (size <= options.maxSingleShotSize) { - return blockBlobURL.upload(aborter, () => streamFactory(0), size, options); + return blockBlobURL.upload(() => streamFactory(0), size, options); } const numBlocks: number = Math.floor((size - 1) / options.blockSize) + 1; @@ -157,11 +150,11 @@ async function uploadResetableStreamToBlockBlob( const contentLength = end - start; blockList.push(blockID); await blockBlobURL.stageBlock( - aborter, blockID, () => streamFactory(start, contentLength), contentLength, { + abortSignal: options.abortSignal, leaseAccessConditions: options.blobAccessConditions! .leaseAccessConditions } @@ -176,7 +169,7 @@ async function uploadResetableStreamToBlockBlob( } await batch.do(); - return blockBlobURL.commitBlockList(aborter, blockList, options); + return blockBlobURL.commitBlockList(blockList, options); } /** @@ -186,8 +179,6 @@ async function uploadResetableStreamToBlockBlob( * Offset and count are optional, pass 0 for both to download the entire blob. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Buffer} buffer Buffer to be fill, must have length larger than count * @param {BlobURL} blobURL A BlobURL object * @param {number} offset From which position of the block blob to download @@ -196,7 +187,6 @@ async function uploadResetableStreamToBlockBlob( * @returns {Promise} */ export async function downloadBlobToBuffer( - aborter: Aborter, buffer: Buffer, blobURL: BlobURL, offset: number, @@ -227,7 +217,7 @@ export async function downloadBlobToBuffer( // Customer doesn't specify length, get it if (!count) { - const response = await blobURL.getProperties(aborter, options); + const response = await blobURL.getProperties(options); count = response.contentLength! - offset; if (count < 0) { throw new RangeError( @@ -249,10 +239,10 @@ export async function downloadBlobToBuffer( const chunkEnd = off + options.blockSize! < count! ? off + options.blockSize! : count!; const response = await blobURL.download( - aborter, off, chunkEnd - off + 1, { + abortSignal: options.abortSignal, blobAccessConditions: options.blobAccessConditions, maxRetryRequests: options.maxRetryRequestsPerBlock } @@ -278,6 +268,16 @@ export async function downloadBlobToBuffer( * @interface IUploadStreamToBlockBlobOptions */ export interface IUploadStreamToBlockBlobOptions { + /** + * Aborter instance to cancel request. It can be created with Aborter.none + * or Aborter.timeout(). Go to documents of {@link Aborter} for more examples + * about request cancellation. + * + * @type {Aborter} + * @memberof IUploadToBlockBlobOptions + */ + abortSignal?: Aborter; + /** * Blob HTTP Headers. * @@ -320,8 +320,6 @@ export interface IUploadStreamToBlockBlobOptions { * parameter, which will avoid Buffer.concat() operations. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Readable} stream Node.js Readable stream * @param {BlockBlobURL} blockBlobURL A BlockBlobURL instance * @param {number} bufferSize Size of every buffer allocated, also the block size in the uploaded block blob @@ -331,7 +329,6 @@ export interface IUploadStreamToBlockBlobOptions { * @returns {Promise} */ export async function uploadStreamToBlockBlob( - aborter: Aborter, stream: Readable, blockBlobURL: BlockBlobURL, bufferSize: number, @@ -359,7 +356,8 @@ export async function uploadStreamToBlockBlob( blockList.push(blockID); blockNum++; - await blockBlobURL.stageBlock(aborter, blockID, buffer, buffer.length, { + await blockBlobURL.stageBlock(blockID, buffer, buffer.length, { + abortSignal: options.abortSignal, leaseAccessConditions: options.accessConditions!.leaseAccessConditions }); @@ -377,5 +375,5 @@ export async function uploadStreamToBlockBlob( ); await scheduler.do(); - return blockBlobURL.commitBlockList(aborter, blockList, options); + return blockBlobURL.commitBlockList(blockList, options); } diff --git a/sdk/storage/storage-blob/src/utils/RetriableReadableStream.ts b/sdk/storage/storage-blob/src/utils/RetriableReadableStream.ts index 69f70ded63a6..d5c634b47257 100644 --- a/sdk/storage/storage-blob/src/utils/RetriableReadableStream.ts +++ b/sdk/storage/storage-blob/src/utils/RetriableReadableStream.ts @@ -8,6 +8,16 @@ export type ReadableStreamGetter = ( ) => Promise; export interface IRetriableReadableStreamOptions { + /** + * Aborter instance to cancel request. It can be created with Aborter.none + * or Aborter.timeout(). Go to documents of {@link Aborter} for more examples + * about request cancellation. + * + * @type {Aborter} + * @memberof IUploadToBlockBlobOptions + */ + abortSignal?: Aborter; + /** * Max retry count (>=0), undefined or invalid value means no retry * @@ -61,8 +71,6 @@ export class RetriableReadableStream extends Readable { /** * Creates an instance of RetriableReadableStream. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {NodeJS.ReadableStream} source The current ReadableStream returned from getter * @param {ReadableStreamGetter} getter A method calling downloading request returning * a new ReadableStream from specified offset @@ -72,7 +80,6 @@ export class RetriableReadableStream extends Readable { * @memberof RetriableReadableStream */ public constructor( - aborter: Aborter, source: NodeJS.ReadableStream, getter: ReadableStreamGetter, offset: number, @@ -80,7 +87,7 @@ export class RetriableReadableStream extends Readable { options: IRetriableReadableStreamOptions = {} ) { super(); - this.aborter = aborter; + this.aborter = options.abortSignal || Aborter.none; this.getter = getter; this.source = source; this.start = offset; @@ -93,7 +100,7 @@ export class RetriableReadableStream extends Readable { this.progress = options.progress; this.options = options; - aborter.addEventListener("abort", () => { + this.aborter.addEventListener("abort", () => { this.source.pause(); this.emit( "error", diff --git a/sdk/storage/storage-blob/test/aborter.test.ts b/sdk/storage/storage-blob/test/aborter.test.ts index f749b8ac02d9..f346b19ace29 100644 --- a/sdk/storage/storage-blob/test/aborter.test.ts +++ b/sdk/storage/storage-blob/test/aborter.test.ts @@ -23,12 +23,12 @@ describe("Aborter", () => { }); it("Should not abort after calling abort()", async () => { - await containerURL.create(Aborter.none); + await containerURL.create({abortSignal: Aborter.none}); }); it("Should abort when calling abort() before request finishes", async () => { const aborter = Aborter.none; - const response = containerURL.create(aborter); + const response = containerURL.create({abortSignal: aborter}); aborter.abort(); try { await response; @@ -38,13 +38,13 @@ describe("Aborter", () => { it("Should not abort when calling abort() after request finishes", async () => { const aborter = Aborter.none; - await containerURL.create(aborter); + await containerURL.create({abortSignal: aborter}); aborter.abort(); }); it("Should abort after aborter timeout", async () => { try { - await containerURL.create(Aborter.timeout(1)); + await containerURL.create({abortSignal: Aborter.timeout(1)}); assert.fail(); } catch (err) {} }); @@ -52,7 +52,7 @@ describe("Aborter", () => { it("Should abort after father aborter calls abort()", async () => { try { const aborter = Aborter.none; - const response = containerURL.create(aborter.withTimeout(10 * 60 * 1000)); + const response = containerURL.create({abortSignal: aborter.withTimeout(10 * 60 * 1000)}); aborter.abort(); await response; assert.fail(); @@ -62,7 +62,7 @@ describe("Aborter", () => { it("Should abort after father aborter timeout", async () => { try { const aborter = Aborter.timeout(1); - const response = containerURL.create(aborter.withTimeout(10 * 60 * 1000)); + const response = containerURL.create({abortSignal: aborter.withTimeout(10 * 60 * 1000)}); await response; assert.fail(); } catch (err) {} diff --git a/sdk/storage/storage-blob/test/appendbloburl.test.ts b/sdk/storage/storage-blob/test/appendbloburl.test.ts index 462351eb6989..19ccc3dfcb43 100644 --- a/sdk/storage/storage-blob/test/appendbloburl.test.ts +++ b/sdk/storage/storage-blob/test/appendbloburl.test.ts @@ -1,6 +1,5 @@ import * as assert from "assert"; -import { Aborter } from "../src/Aborter"; import { AppendBlobURL } from "../src/AppendBlobURL"; import { ContainerURL } from "../src/ContainerURL"; import { bodyToString, getBSU, getUniqueName } from "./utils"; @@ -17,18 +16,18 @@ describe("AppendBlobURL", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); blobName = getUniqueName("blob"); appendBlobURL = AppendBlobURL.fromContainerURL(containerURL, blobName); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("create with default parameters", async () => { - await appendBlobURL.create(Aborter.none); - await appendBlobURL.download(Aborter.none, 0); + await appendBlobURL.create(); + await appendBlobURL.download(0); }); it("create with parameters configured", async () => { @@ -45,8 +44,8 @@ describe("AppendBlobURL", () => { key2: "valb" } }; - await appendBlobURL.create(Aborter.none, options); - const properties = await appendBlobURL.getProperties(Aborter.none); + await appendBlobURL.create(options); + const properties = await appendBlobURL.getProperties(); assert.equal( properties.cacheControl, options.blobHTTPHeaders.blobCacheControl @@ -72,12 +71,12 @@ describe("AppendBlobURL", () => { }); it("appendBlock", async () => { - await appendBlobURL.create(Aborter.none); + await appendBlobURL.create(); const content = "Hello World!"; - await appendBlobURL.appendBlock(Aborter.none, content, content.length); + await appendBlobURL.appendBlock(content, content.length); - const downloadResponse = await appendBlobURL.download(Aborter.none, 0); + const downloadResponse = await appendBlobURL.download(0); assert.equal(await bodyToString(downloadResponse, content.length), content); assert.equal(downloadResponse.contentLength!, content.length); }); diff --git a/sdk/storage/storage-blob/test/bloburl.test.ts b/sdk/storage/storage-blob/test/bloburl.test.ts index fdf4e93c39a8..4612f4f58971 100644 --- a/sdk/storage/storage-blob/test/bloburl.test.ts +++ b/sdk/storage/storage-blob/test/bloburl.test.ts @@ -21,24 +21,24 @@ describe("BlobURL", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); blobName = getUniqueName("blob"); blobURL = BlobURL.fromContainerURL(containerURL, blobName); blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); - await blockBlobURL.upload(Aborter.none, content, content.length); + await blockBlobURL.upload(content, content.length); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("download with with default parameters", async () => { - const result = await blobURL.download(Aborter.none, 0); + const result = await blobURL.download(0); assert.deepStrictEqual(await bodyToString(result, content.length), content); }); it("download all parameters set", async () => { - const result = await blobURL.download(Aborter.none, 0, 1, { + const result = await blobURL.download(0, 1, { rangeGetContentMD5: true }); assert.deepStrictEqual(await bodyToString(result, 1), content[0]); @@ -49,8 +49,8 @@ describe("BlobURL", () => { a: "a", b: "b" }; - await blobURL.setMetadata(Aborter.none, metadata); - const result = await blobURL.getProperties(Aborter.none); + await blobURL.setMetadata(metadata); + const result = await blobURL.getProperties(); assert.deepStrictEqual(result.metadata, metadata); }); @@ -59,18 +59,18 @@ describe("BlobURL", () => { a: "a", b: "b" }; - await blobURL.setMetadata(Aborter.none, metadata); - const result = await blobURL.getProperties(Aborter.none); + await blobURL.setMetadata(metadata); + const result = await blobURL.getProperties(); assert.deepStrictEqual(result.metadata, metadata); - await blobURL.setMetadata(Aborter.none); - const result2 = await blobURL.getProperties(Aborter.none); + await blobURL.setMetadata(); + const result2 = await blobURL.getProperties(); assert.deepStrictEqual(result2.metadata, {}); }); it("setHTTPHeaders with default parameters", async () => { - await blobURL.setHTTPHeaders(Aborter.none, {}); - const result = await blobURL.getProperties(Aborter.none); + await blobURL.setHTTPHeaders({}); + const result = await blobURL.getProperties(); assert.deepStrictEqual(result.blobType, "BlockBlob"); assert.ok(result.lastModified); @@ -94,8 +94,8 @@ describe("BlobURL", () => { : new Uint8Array([1, 2, 3, 4]), blobContentType: "blobContentType" }; - await blobURL.setHTTPHeaders(Aborter.none, headers); - const result = await blobURL.getProperties(Aborter.none); + await blobURL.setHTTPHeaders(headers); + const result = await blobURL.getProperties(); assert.ok(result.date); assert.deepStrictEqual(result.blobType, "BlockBlob"); assert.ok(result.lastModified); @@ -114,110 +114,110 @@ describe("BlobURL", () => { it("acquireLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = 30; - await blobURL.acquireLease(Aborter.none, guid, duration); + await blobURL.acquireLease(guid, duration); - const result = await blobURL.getProperties(Aborter.none); + const result = await blobURL.getProperties(); assert.equal(result.leaseDuration, "fixed"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); - await blobURL.releaseLease(Aborter.none, guid); + await blobURL.releaseLease(guid); }); it("releaseLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = -1; - await blobURL.acquireLease(Aborter.none, guid, duration); + await blobURL.acquireLease(guid, duration); - const result = await blobURL.getProperties(Aborter.none); + const result = await blobURL.getProperties(); assert.equal(result.leaseDuration, "infinite"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); - await blobURL.releaseLease(Aborter.none, guid); + await blobURL.releaseLease(guid); }); it("renewLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = 15; - await blobURL.acquireLease(Aborter.none, guid, duration); + await blobURL.acquireLease(guid, duration); - const result = await blobURL.getProperties(Aborter.none); + const result = await blobURL.getProperties(); assert.equal(result.leaseDuration, "fixed"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); await sleep(16 * 1000); - const result2 = await blobURL.getProperties(Aborter.none); + const result2 = await blobURL.getProperties(); assert.ok(!result2.leaseDuration); assert.equal(result2.leaseState, "expired"); assert.equal(result2.leaseStatus, "unlocked"); - await blobURL.renewLease(Aborter.none, guid); - const result3 = await blobURL.getProperties(Aborter.none); + await blobURL.renewLease(guid); + const result3 = await blobURL.getProperties(); assert.equal(result3.leaseDuration, "fixed"); assert.equal(result3.leaseState, "leased"); assert.equal(result3.leaseStatus, "locked"); - await blobURL.releaseLease(Aborter.none, guid); + await blobURL.releaseLease(guid); }); it("changeLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = 15; - await blobURL.acquireLease(Aborter.none, guid, duration); + await blobURL.acquireLease(guid, duration); - const result = await blobURL.getProperties(Aborter.none); + const result = await blobURL.getProperties(); assert.equal(result.leaseDuration, "fixed"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); const newGuid = "3c7e72ebb4304526bc53d8ecef03798f"; - await blobURL.changeLease(Aborter.none, guid, newGuid); + await blobURL.changeLease(guid, newGuid); - await blobURL.getProperties(Aborter.none); - await blobURL.releaseLease(Aborter.none, newGuid); + await blobURL.getProperties(); + await blobURL.releaseLease(newGuid); }); it("breakLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = 15; - await blobURL.acquireLease(Aborter.none, guid, duration); + await blobURL.acquireLease(guid, duration); - const result = await blobURL.getProperties(Aborter.none); + const result = await blobURL.getProperties(); assert.equal(result.leaseDuration, "fixed"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); - await blobURL.breakLease(Aborter.none, 3); + await blobURL.breakLease(3); - const result2 = await blobURL.getProperties(Aborter.none); + const result2 = await blobURL.getProperties(); assert.ok(!result2.leaseDuration); assert.equal(result2.leaseState, "breaking"); assert.equal(result2.leaseStatus, "locked"); await sleep(3 * 1000); - const result3 = await blobURL.getProperties(Aborter.none); + const result3 = await blobURL.getProperties(); assert.ok(!result3.leaseDuration); assert.equal(result3.leaseState, "broken"); assert.equal(result3.leaseStatus, "unlocked"); }); it("delete", async () => { - await blobURL.delete(Aborter.none); + await blobURL.delete(); }); // The following code illustrates deleting a snapshot after creating one it("delete snapshot", async () => { - const result = await blobURL.createSnapshot(Aborter.none); + const result = await blobURL.createSnapshot(); assert.ok(result.snapshot); const blobSnapshotURL = blobURL.withSnapshot(result.snapshot!); - await blobSnapshotURL.getProperties(Aborter.none); + await blobSnapshotURL.getProperties(); - await blobSnapshotURL.delete(Aborter.none); - await blobURL.delete(Aborter.none); + await blobSnapshotURL.delete(); + await blobURL.delete(); const result2 = await containerURL.listBlobFlatSegment( Aborter.none, @@ -232,11 +232,11 @@ describe("BlobURL", () => { }); it("createSnapshot", async () => { - const result = await blobURL.createSnapshot(Aborter.none); + const result = await blobURL.createSnapshot(); assert.ok(result.snapshot); const blobSnapshotURL = blobURL.withSnapshot(result.snapshot!); - await blobSnapshotURL.getProperties(Aborter.none); + await blobSnapshotURL.getProperties(); const result3 = await containerURL.listBlobFlatSegment( Aborter.none, @@ -268,9 +268,9 @@ describe("BlobURL", () => { }); it("undelete", async () => { - const properties = await serviceURL.getProperties(Aborter.none); + const properties = await serviceURL.getProperties(); if (!properties.deleteRetentionPolicy!.enabled) { - await serviceURL.setProperties(Aborter.none, { + await serviceURL.setProperties({ deleteRetentionPolicy: { days: 7, enabled: true @@ -279,7 +279,7 @@ describe("BlobURL", () => { await sleep(15 * 1000); } - await blobURL.delete(Aborter.none); + await blobURL.delete(); const result = await containerURL.listBlobFlatSegment( Aborter.none, @@ -290,7 +290,7 @@ describe("BlobURL", () => { ); assert.ok(result.segment.blobItems![0].deleted); - await blobURL.undelete(Aborter.none); + await blobURL.undelete(); const result2 = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -306,11 +306,11 @@ describe("BlobURL", () => { containerURL, getUniqueName("copiedblob") ); - const result = await newBlobURL.startCopyFromURL(Aborter.none, blobURL.url); + const result = await newBlobURL.startCopyFromURL(blobURL.url); assert.ok(result.copyId); - const properties1 = await blobURL.getProperties(Aborter.none); - const properties2 = await newBlobURL.getProperties(Aborter.none); + const properties1 = await blobURL.getProperties(); + const properties2 = await newBlobURL.getProperties(); assert.deepStrictEqual(properties1.contentMD5, properties2.contentMD5); assert.deepStrictEqual(properties2.copyId, result.copyId); assert.deepStrictEqual(properties2.copySource, blobURL.url); @@ -321,12 +321,12 @@ describe("BlobURL", () => { containerURL, getUniqueName("copiedblob") ); - const result = await newBlobURL.startCopyFromURL(Aborter.none, blobURL.url); + const result = await newBlobURL.startCopyFromURL(blobURL.url); assert.ok(result.copyId); sleep(1 * 1000); try { - await newBlobURL.abortCopyFromURL(Aborter.none, result.copyId!); + await newBlobURL.abortCopyFromURL(result.copyId!); assert.fail( "AbortCopyFromURL should be failed and throw exception for an completed copy operation." ); @@ -336,18 +336,18 @@ describe("BlobURL", () => { }); it("setTier set default to cool", async () => { - await blockBlobURL.setTier(Aborter.none, "Cool"); - const properties = await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.setTier("Cool"); + const properties = await blockBlobURL.getProperties(); assert.equal(properties.accessTier!.toLowerCase(), "cool"); }); it("setTier set archive to hot", async () => { - await blockBlobURL.setTier(Aborter.none, "Archive"); - let properties = await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.setTier("Archive"); + let properties = await blockBlobURL.getProperties(); assert.equal(properties.accessTier!.toLowerCase(), "archive"); - await blockBlobURL.setTier(Aborter.none, "Hot"); - properties = await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.setTier("Hot"); + properties = await blockBlobURL.getProperties(); if (properties.archiveStatus) { assert.equal( properties.archiveStatus.toLowerCase(), diff --git a/sdk/storage/storage-blob/test/blockbloburl.test.ts b/sdk/storage/storage-blob/test/blockbloburl.test.ts index 7310d2f33949..a976d1ec0035 100644 --- a/sdk/storage/storage-blob/test/blockbloburl.test.ts +++ b/sdk/storage/storage-blob/test/blockbloburl.test.ts @@ -1,6 +1,5 @@ import * as assert from "assert"; -import { Aborter } from "../src/Aborter"; import { BlobURL } from "../src/BlobURL"; import { BlockBlobURL } from "../src/BlockBlobURL"; import { ContainerURL } from "../src/ContainerURL"; @@ -19,20 +18,20 @@ describe("BlockBlobURL", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); blobName = getUniqueName("blob"); blobURL = BlobURL.fromContainerURL(containerURL, blobName); blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("upload with string body and default parameters", async () => { const body: string = getUniqueName("randomstring"); - await blockBlobURL.upload(Aborter.none, body, body.length); - const result = await blobURL.download(Aborter.none, 0); + await blockBlobURL.upload(body, body.length); + const result = await blobURL.download(0); assert.deepStrictEqual(await bodyToString(result, body.length), body); }); @@ -49,11 +48,11 @@ describe("BlockBlobURL", () => { keyb: "valb" } }; - await blockBlobURL.upload(Aborter.none, body, body.length, { + await blockBlobURL.upload(body, body.length, { blobHTTPHeaders: options, metadata: options.metadata }); - const result = await blobURL.download(Aborter.none, 0); + const result = await blobURL.download(0); assert.deepStrictEqual(await bodyToString(result, body.length), body); assert.deepStrictEqual(result.cacheControl, options.blobCacheControl); assert.deepStrictEqual( @@ -69,19 +68,16 @@ describe("BlockBlobURL", () => { it("stageBlock", async () => { const body = "HelloWorld"; await blockBlobURL.stageBlock( - Aborter.none, base64encode("1"), body, body.length ); await blockBlobURL.stageBlock( - Aborter.none, base64encode("2"), body, body.length ); const listResponse = await blockBlobURL.getBlockList( - Aborter.none, "uncommitted" ); assert.equal(listResponse.uncommittedBlocks!.length, 2); @@ -93,12 +89,12 @@ describe("BlockBlobURL", () => { it("stageBlockFromURL copy source blob as single block", async () => { const body = "HelloWorld"; - await blockBlobURL.upload(Aborter.none, body, body.length); + await blockBlobURL.upload(body, body.length); // When testing is in Node.js environment with shared key, setAccessPolicy will work // But in browsers testing with SAS tokens, below will throw an exception, ignore it try { - await containerURL.setAccessPolicy(Aborter.none, "container"); + await containerURL.setAccessPolicy("container"); // tslint:disable-next-line:no-empty } catch (err) {} @@ -107,14 +103,12 @@ describe("BlockBlobURL", () => { getUniqueName("newblockblob") ); await newBlockBlobURL.stageBlockFromURL( - Aborter.none, base64encode("1"), blockBlobURL.url, 0 ); const listResponse = await newBlockBlobURL.getBlockList( - Aborter.none, "uncommitted" ); assert.equal(listResponse.uncommittedBlocks!.length, 1); @@ -124,12 +118,12 @@ describe("BlockBlobURL", () => { it("stageBlockFromURL copy source blob as separate blocks", async () => { const body = "HelloWorld"; - await blockBlobURL.upload(Aborter.none, body, body.length); + await blockBlobURL.upload(body, body.length); // When testing is in Node.js environment with shared key, setAccessPolicy will work // But in browsers testing with SAS tokens, below will throw an exception, ignore it try { - await containerURL.setAccessPolicy(Aborter.none, "container"); + await containerURL.setAccessPolicy("container"); // tslint:disable-next-line:no-empty } catch (err) {} @@ -138,21 +132,18 @@ describe("BlockBlobURL", () => { getUniqueName("newblockblob") ); await newBlockBlobURL.stageBlockFromURL( - Aborter.none, base64encode("1"), blockBlobURL.url, 0, 4 ); await newBlockBlobURL.stageBlockFromURL( - Aborter.none, base64encode("2"), blockBlobURL.url, 4, 4 ); await newBlockBlobURL.stageBlockFromURL( - Aborter.none, base64encode("3"), blockBlobURL.url, 8, @@ -160,7 +151,6 @@ describe("BlockBlobURL", () => { ); const listResponse = await newBlockBlobURL.getBlockList( - Aborter.none, "uncommitted" ); assert.equal(listResponse.uncommittedBlocks!.length, 3); @@ -171,36 +161,33 @@ describe("BlockBlobURL", () => { assert.equal(listResponse.uncommittedBlocks![2].name, base64encode("3")); assert.equal(listResponse.uncommittedBlocks![2].size, 2); - await newBlockBlobURL.commitBlockList(Aborter.none, [ + await newBlockBlobURL.commitBlockList([ base64encode("1"), base64encode("2"), base64encode("3") ]); - const downloadResponse = await newBlockBlobURL.download(Aborter.none, 0); + const downloadResponse = await newBlockBlobURL.download(0); assert.equal(await bodyToString(downloadResponse, 10), body); }); it("commitBlockList", async () => { const body = "HelloWorld"; await blockBlobURL.stageBlock( - Aborter.none, base64encode("1"), body, body.length ); await blockBlobURL.stageBlock( - Aborter.none, base64encode("2"), body, body.length ); - await blockBlobURL.commitBlockList(Aborter.none, [ + await blockBlobURL.commitBlockList([ base64encode("1"), base64encode("2") ]); const listResponse = await blockBlobURL.getBlockList( - Aborter.none, "committed" ); assert.equal(listResponse.committedBlocks!.length, 2); @@ -213,13 +200,11 @@ describe("BlockBlobURL", () => { it("commitBlockList with all parameters set", async () => { const body = "HelloWorld"; await blockBlobURL.stageBlock( - Aborter.none, base64encode("1"), body, body.length ); await blockBlobURL.stageBlock( - Aborter.none, base64encode("2"), body, body.length @@ -237,7 +222,6 @@ describe("BlockBlobURL", () => { } }; await blockBlobURL.commitBlockList( - Aborter.none, [base64encode("1"), base64encode("2")], { blobHTTPHeaders: options, @@ -246,7 +230,6 @@ describe("BlockBlobURL", () => { ); const listResponse = await blockBlobURL.getBlockList( - Aborter.none, "committed" ); assert.equal(listResponse.committedBlocks!.length, 2); @@ -255,7 +238,7 @@ describe("BlockBlobURL", () => { assert.equal(listResponse.committedBlocks![1].name, base64encode("2")); assert.equal(listResponse.committedBlocks![1].size, body.length); - const result = await blobURL.download(Aborter.none, 0); + const result = await blobURL.download(0); assert.deepStrictEqual( await bodyToString(result, body.repeat(2).length), body.repeat(2) @@ -274,19 +257,17 @@ describe("BlockBlobURL", () => { it("getBlockList", async () => { const body = "HelloWorld"; await blockBlobURL.stageBlock( - Aborter.none, base64encode("1"), body, body.length ); await blockBlobURL.stageBlock( - Aborter.none, base64encode("2"), body, body.length ); - await blockBlobURL.commitBlockList(Aborter.none, [base64encode("2")]); - const listResponse = await blockBlobURL.getBlockList(Aborter.none, "all"); + await blockBlobURL.commitBlockList([base64encode("2")]); + const listResponse = await blockBlobURL.getBlockList("all"); assert.equal(listResponse.committedBlocks!.length, 1); assert.equal(listResponse.uncommittedBlocks!.length, 0); assert.equal(listResponse.committedBlocks![0].name, base64encode("2")); diff --git a/sdk/storage/storage-blob/test/browser/highlevel.browser.test.ts b/sdk/storage/storage-blob/test/browser/highlevel.browser.test.ts index 0a57e8f17219..0750666f80ed 100644 --- a/sdk/storage/storage-blob/test/browser/highlevel.browser.test.ts +++ b/sdk/storage/storage-blob/test/browser/highlevel.browser.test.ts @@ -32,14 +32,14 @@ describe("Highelvel", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); blobName = getUniqueName("blob"); blobURL = BlobURL.fromContainerURL(containerURL, blobName); blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); before(async () => { @@ -53,7 +53,9 @@ describe("Highelvel", () => { const aborter = Aborter.timeout(1); try { - await uploadBrowserDataToBlockBlob(aborter, tempFile1, blockBlobURL); + await uploadBrowserDataToBlockBlob(tempFile1, blockBlobURL, { + abortSignal: aborter + }); assert.fail(); } catch (err) { assert.ok((err.code as string).toLowerCase().includes("abort")); @@ -64,7 +66,8 @@ describe("Highelvel", () => { const aborter = Aborter.timeout(1); try { - await uploadBrowserDataToBlockBlob(aborter, tempFile2, blockBlobURL, { + await uploadBrowserDataToBlockBlob(tempFile2, blockBlobURL, { + abortSignal: aborter, blockSize: 4 * 1024 * 1024, parallelism: 2 }); @@ -79,7 +82,8 @@ describe("Highelvel", () => { const aborter = Aborter.none; try { - await uploadBrowserDataToBlockBlob(aborter, tempFile1, blockBlobURL, { + await uploadBrowserDataToBlockBlob(tempFile1, blockBlobURL, { + abortSignal: aborter, blockSize: 4 * 1024 * 1024, parallelism: 2, progress: ev => { @@ -97,7 +101,8 @@ describe("Highelvel", () => { const aborter = Aborter.none; try { - await uploadBrowserDataToBlockBlob(aborter, tempFile2, blockBlobURL, { + await uploadBrowserDataToBlockBlob(tempFile2, blockBlobURL, { + abortSignal: aborter, blockSize: 4 * 1024 * 1024, parallelism: 2, progress: ev => { @@ -111,12 +116,12 @@ describe("Highelvel", () => { }); it("uploadBrowserDataToBlockBlob should success when blob < BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES", async () => { - await uploadBrowserDataToBlockBlob(Aborter.none, tempFile2, blockBlobURL, { + await uploadBrowserDataToBlockBlob(tempFile2, blockBlobURL, { blockSize: 4 * 1024 * 1024, parallelism: 2 }); - const downloadResponse = await blockBlobURL.download(Aborter.none, 0); + const downloadResponse = await blockBlobURL.download(0); const downloadedString = await bodyToString(downloadResponse); const uploadedString = await blobToString(tempFile2); @@ -124,12 +129,12 @@ describe("Highelvel", () => { }); it("uploadBrowserDataToBlockBlob should success when blob < BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES and configured maxSingleShotSize", async () => { - await uploadBrowserDataToBlockBlob(Aborter.none, tempFile2, blockBlobURL, { + await uploadBrowserDataToBlockBlob(tempFile2, blockBlobURL, { blockSize: 512 * 1024, maxSingleShotSize: 0 }); - const downloadResponse = await blockBlobURL.download(Aborter.none, 0); + const downloadResponse = await blockBlobURL.download(0); const downloadedString = await bodyToString(downloadResponse); const uploadedString = await blobToString(tempFile2); @@ -145,12 +150,12 @@ describe("Highelvel", () => { return; } - await uploadBrowserDataToBlockBlob(Aborter.none, tempFile1, blockBlobURL, { + await uploadBrowserDataToBlockBlob(tempFile1, blockBlobURL, { blockSize: 4 * 1024 * 1024, parallelism: 2 }); - const downloadResponse = await blockBlobURL.download(Aborter.none, 0); + const downloadResponse = await blockBlobURL.download(0); const buf1 = await blobToArrayBuffer(await downloadResponse.blobBody!); const buf2 = await blobToArrayBuffer(tempFile1); diff --git a/sdk/storage/storage-blob/test/containerurl.test.ts b/sdk/storage/storage-blob/test/containerurl.test.ts index 24dd7860129c..b1c939c311a7 100644 --- a/sdk/storage/storage-blob/test/containerurl.test.ts +++ b/sdk/storage/storage-blob/test/containerurl.test.ts @@ -16,11 +16,11 @@ describe("ContainerURL", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("setMetadata", async () => { @@ -29,14 +29,14 @@ describe("ContainerURL", () => { keya: "vala", keyb: "valb" }; - await containerURL.setMetadata(Aborter.none, metadata); + await containerURL.setMetadata(metadata); - const result = await containerURL.getProperties(Aborter.none); + const result = await containerURL.getProperties(); assert.deepEqual(result.metadata, metadata); }); it("getProperties", async () => { - const result = await containerURL.getProperties(Aborter.none); + const result = await containerURL.getProperties(); assert.ok(result.eTag!.length > 0); assert.ok(result.lastModified); assert.ok(!result.leaseDuration); @@ -60,8 +60,8 @@ describe("ContainerURL", () => { ); const metadata = { key: "value" }; const access = "container"; - await cURL.create(Aborter.none, { metadata, access }); - const result = await cURL.getProperties(Aborter.none); + await cURL.create({ metadata, access }); + const result = await cURL.getProperties(); assert.deepEqual(result.blobPublicAccess, access); assert.deepEqual(result.metadata, metadata); }); @@ -74,91 +74,91 @@ describe("ContainerURL", () => { it("acquireLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = 30; - await containerURL.acquireLease(Aborter.none, guid, duration); + await containerURL.acquireLease(guid, duration); - const result = await containerURL.getProperties(Aborter.none); + const result = await containerURL.getProperties(); assert.equal(result.leaseDuration, "fixed"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); - await containerURL.releaseLease(Aborter.none, guid); + await containerURL.releaseLease(guid); }); it("releaseLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = -1; - await containerURL.acquireLease(Aborter.none, guid, duration); + await containerURL.acquireLease(guid, duration); - const result = await containerURL.getProperties(Aborter.none); + const result = await containerURL.getProperties(); assert.equal(result.leaseDuration, "infinite"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); - await containerURL.releaseLease(Aborter.none, guid); + await containerURL.releaseLease(guid); }); it("renewLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = 15; - await containerURL.acquireLease(Aborter.none, guid, duration); + await containerURL.acquireLease(guid, duration); - const result = await containerURL.getProperties(Aborter.none); + const result = await containerURL.getProperties(); assert.equal(result.leaseDuration, "fixed"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); await sleep(16 * 1000); - const result2 = await containerURL.getProperties(Aborter.none); + const result2 = await containerURL.getProperties(); assert.ok(!result2.leaseDuration); assert.equal(result2.leaseState, "expired"); assert.equal(result2.leaseStatus, "unlocked"); - await containerURL.renewLease(Aborter.none, guid); - const result3 = await containerURL.getProperties(Aborter.none); + await containerURL.renewLease(guid); + const result3 = await containerURL.getProperties(); assert.equal(result3.leaseDuration, "fixed"); assert.equal(result3.leaseState, "leased"); assert.equal(result3.leaseStatus, "locked"); - await containerURL.releaseLease(Aborter.none, guid); + await containerURL.releaseLease(guid); }); it("changeLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = 15; - await containerURL.acquireLease(Aborter.none, guid, duration); + await containerURL.acquireLease(guid, duration); - const result = await containerURL.getProperties(Aborter.none); + const result = await containerURL.getProperties(); assert.equal(result.leaseDuration, "fixed"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); const newGuid = "3c7e72ebb4304526bc53d8ecef03798f"; - await containerURL.changeLease(Aborter.none, guid, newGuid); + await containerURL.changeLease(guid, newGuid); - await containerURL.getProperties(Aborter.none); - await containerURL.releaseLease(Aborter.none, newGuid); + await containerURL.getProperties(); + await containerURL.releaseLease(newGuid); }); it("breakLease", async () => { const guid = "ca761232ed4211cebacd00aa0057b223"; const duration = 15; - await containerURL.acquireLease(Aborter.none, guid, duration); + await containerURL.acquireLease(guid, duration); - const result = await containerURL.getProperties(Aborter.none); + const result = await containerURL.getProperties(); assert.equal(result.leaseDuration, "fixed"); assert.equal(result.leaseState, "leased"); assert.equal(result.leaseStatus, "locked"); - await containerURL.breakLease(Aborter.none, 3); + await containerURL.breakLease(3); - const result2 = await containerURL.getProperties(Aborter.none); + const result2 = await containerURL.getProperties(); assert.ok(!result2.leaseDuration); assert.equal(result2.leaseState, "breaking"); assert.equal(result2.leaseStatus, "locked"); await sleep(3 * 1000); - const result3 = await containerURL.getProperties(Aborter.none); + const result3 = await containerURL.getProperties(); assert.ok(!result3.leaseDuration); assert.equal(result3.leaseState, "broken"); assert.equal(result3.leaseStatus, "unlocked"); @@ -172,7 +172,7 @@ describe("ContainerURL", () => { getUniqueName(`blockblob/${i}`) ); const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); - await blockBlobURL.upload(Aborter.none, "", 0); + await blockBlobURL.upload("", 0); blobURLs.push(blobURL); } @@ -184,7 +184,7 @@ describe("ContainerURL", () => { assert.ok(blobURLs[0].url.indexOf(result.segment.blobItems![0].name)); for (const blob of blobURLs) { - await blob.delete(Aborter.none); + await blob.delete(); } }); @@ -201,7 +201,7 @@ describe("ContainerURL", () => { getUniqueName(`${prefix}/${i}`) ); const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); - await blockBlobURL.upload(Aborter.none, "", 0, { + await blockBlobURL.upload("", 0, { metadata }); blobURLs.push(blobURL); @@ -251,7 +251,7 @@ describe("ContainerURL", () => { assert.deepStrictEqual(result2.segment.blobItems![0].metadata, metadata); for (const blob of blobURLs) { - await blob.delete(Aborter.none); + await blob.delete(); } }); @@ -263,7 +263,7 @@ describe("ContainerURL", () => { getUniqueName(`blockblob${i}/${i}`) ); const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); - await blockBlobURL.upload(Aborter.none, "", 0); + await blockBlobURL.upload("", 0); blobURLs.push(blobURL); } @@ -287,7 +287,7 @@ describe("ContainerURL", () => { } for (const blob of blobURLs) { - await blob.delete(Aborter.none); + await blob.delete(); } }); @@ -305,7 +305,7 @@ describe("ContainerURL", () => { getUniqueName(`${prefix}${i}${delimiter}${i}`) ); const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); - await blockBlobURL.upload(Aborter.none, "", 0, { + await blockBlobURL.upload("", 0, { metadata }); blobURLs.push(blobURL); @@ -362,7 +362,7 @@ describe("ContainerURL", () => { assert.ok(blobURLs[0].url.indexOf(result3.segment.blobItems![0].name)); for (const blob of blobURLs) { - await blob.delete(Aborter.none); + await blob.delete(); } }); }); diff --git a/sdk/storage/storage-blob/test/node/blockbloburl.test.ts b/sdk/storage/storage-blob/test/node/blockbloburl.test.ts index caa0198821e0..6ddd3556d9cc 100644 --- a/sdk/storage/storage-blob/test/node/blockbloburl.test.ts +++ b/sdk/storage/storage-blob/test/node/blockbloburl.test.ts @@ -1,6 +1,5 @@ import * as assert from "assert"; -import { Aborter } from "../../src/Aborter"; import { BlobURL } from "../../src/BlobURL"; import { BlockBlobURL } from "../../src/BlockBlobURL"; import { ContainerURL } from "../../src/ContainerURL"; @@ -17,22 +16,22 @@ describe("BlockBlobURL Node.js only", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); blobName = getUniqueName("blob"); blobURL = BlobURL.fromContainerURL(containerURL, blobName); blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("upload with Readable stream body and default parameters", async () => { const body: string = getUniqueName("randomstring"); const bodyBuffer = Buffer.from(body); - await blockBlobURL.upload(Aborter.none, bodyBuffer, body.length); - const result = await blobURL.download(Aborter.none, 0); + await blockBlobURL.upload(bodyBuffer, body.length); + const result = await blobURL.download(0); const downloadedBody = await new Promise((resolve, reject) => { const buffer: string[] = []; @@ -50,8 +49,8 @@ describe("BlockBlobURL Node.js only", () => { it("upload with Chinese string body and default parameters", async () => { const body: string = getUniqueName("randomstring你好"); - await blockBlobURL.upload(Aborter.none, body, Buffer.byteLength(body)); - const result = await blobURL.download(Aborter.none, 0); + await blockBlobURL.upload(body, Buffer.byteLength(body)); + const result = await blobURL.download(0); assert.deepStrictEqual( await bodyToString(result, Buffer.byteLength(body)), body diff --git a/sdk/storage/storage-blob/test/node/containerurl.test.ts b/sdk/storage/storage-blob/test/node/containerurl.test.ts index 7317edee4eda..4e673157a664 100644 --- a/sdk/storage/storage-blob/test/node/containerurl.test.ts +++ b/sdk/storage/storage-blob/test/node/containerurl.test.ts @@ -1,6 +1,5 @@ import * as assert from "assert"; -import { Aborter } from "../../src/Aborter"; import { ContainerURL } from "../../src/ContainerURL"; import { getBSU, getUniqueName } from "../utils"; import { PublicAccessType } from "../../src/generated/lib/models/index"; @@ -13,15 +12,15 @@ describe("ContainerURL", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("getAccessPolicy", async () => { - const result = await containerURL.getAccessPolicy(Aborter.none); + const result = await containerURL.getAccessPolicy(); assert.ok(result.eTag!.length > 0); assert.ok(result.lastModified); assert.ok(result.requestId); @@ -42,8 +41,8 @@ describe("ContainerURL", () => { } ]; - await containerURL.setAccessPolicy(Aborter.none, access, containerAcl); - const result = await containerURL.getAccessPolicy(Aborter.none); + await containerURL.setAccessPolicy(access, containerAcl); + const result = await containerURL.getAccessPolicy(); assert.deepEqual(result.signedIdentifiers, containerAcl); assert.deepEqual(result.blobPublicAccess, access); }); diff --git a/sdk/storage/storage-blob/test/node/highlevel.node.test.ts b/sdk/storage/storage-blob/test/node/highlevel.node.test.ts index 94f82d12ab98..d1b42432bff7 100644 --- a/sdk/storage/storage-blob/test/node/highlevel.node.test.ts +++ b/sdk/storage/storage-blob/test/node/highlevel.node.test.ts @@ -35,14 +35,14 @@ describe("Highlevel", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); blobName = getUniqueName("blob"); blobURL = BlobURL.fromContainerURL(containerURL, blobName); blockBlobURL = BlockBlobURL.fromBlobURL(blobURL); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); before(async () => { @@ -69,12 +69,12 @@ describe("Highlevel", () => { }); it("uploadFileToBlockBlob should success when blob >= BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES", async () => { - await uploadFileToBlockBlob(Aborter.none, tempFileLarge, blockBlobURL, { + await uploadFileToBlockBlob(tempFileLarge, blockBlobURL, { blockSize: 4 * 1024 * 1024, parallelism: 20 }); - const downloadResponse = await blockBlobURL.download(Aborter.none, 0); + const downloadResponse = await blockBlobURL.download(0); const downloadedFile = path.join( tempFolderPath, getUniqueName("downloadfile.") @@ -92,12 +92,12 @@ describe("Highlevel", () => { }); it("uploadFileToBlockBlob should success when blob < BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES", async () => { - await uploadFileToBlockBlob(Aborter.none, tempFileSmall, blockBlobURL, { + await uploadFileToBlockBlob(tempFileSmall, blockBlobURL, { blockSize: 4 * 1024 * 1024, parallelism: 20 }); - const downloadResponse = await blockBlobURL.download(Aborter.none, 0); + const downloadResponse = await blockBlobURL.download(0); const downloadedFile = path.join( tempFolderPath, getUniqueName("downloadfile.") @@ -115,11 +115,11 @@ describe("Highlevel", () => { }); it("uploadFileToBlockBlob should success when blob < BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES and configured maxSingleShotSize", async () => { - await uploadFileToBlockBlob(Aborter.none, tempFileSmall, blockBlobURL, { + await uploadFileToBlockBlob(tempFileSmall, blockBlobURL, { maxSingleShotSize: 0 }); - const downloadResponse = await blockBlobURL.download(Aborter.none, 0); + const downloadResponse = await blockBlobURL.download(0); const downloadedFile = path.join( tempFolderPath, getUniqueName("downloadfile.") @@ -140,7 +140,8 @@ describe("Highlevel", () => { const aborter = Aborter.timeout(1); try { - await uploadFileToBlockBlob(aborter, tempFileLarge, blockBlobURL, { + await uploadFileToBlockBlob(tempFileLarge, blockBlobURL, { + abortSignal: aborter, blockSize: 4 * 1024 * 1024, parallelism: 20 }); @@ -154,7 +155,8 @@ describe("Highlevel", () => { const aborter = Aborter.timeout(1); try { - await uploadFileToBlockBlob(aborter, tempFileSmall, blockBlobURL, { + await uploadFileToBlockBlob(tempFileSmall, blockBlobURL, { + abortSignal: aborter, blockSize: 4 * 1024 * 1024, parallelism: 20 }); @@ -169,7 +171,8 @@ describe("Highlevel", () => { const aborter = Aborter.none; try { - await uploadFileToBlockBlob(aborter, tempFileLarge, blockBlobURL, { + await uploadFileToBlockBlob(tempFileLarge, blockBlobURL, { + abortSignal: aborter, blockSize: 4 * 1024 * 1024, parallelism: 20, progress: ev => { @@ -187,7 +190,8 @@ describe("Highlevel", () => { const aborter = Aborter.none; try { - await uploadFileToBlockBlob(aborter, tempFileSmall, blockBlobURL, { + await uploadFileToBlockBlob(tempFileSmall, blockBlobURL, { + abortSignal: aborter, blockSize: 4 * 1024 * 1024, parallelism: 20, progress: ev => { @@ -203,14 +207,13 @@ describe("Highlevel", () => { it("uploadStreamToBlockBlob should success", async () => { const rs = fs.createReadStream(tempFileLarge); await uploadStreamToBlockBlob( - Aborter.none, rs, blockBlobURL, 4 * 1024 * 1024, 20 ); - const downloadResponse = await blockBlobURL.download(Aborter.none, 0); + const downloadResponse = await blockBlobURL.download(0); const downloadFilePath = path.join( tempFolderPath, @@ -234,14 +237,13 @@ describe("Highlevel", () => { bufferStream.end(buf); await uploadStreamToBlockBlob( - Aborter.none, bufferStream, blockBlobURL, 4 * 1024 * 1024, 20 ); - const downloadResponse = await blockBlobURL.download(Aborter.none, 0); + const downloadResponse = await blockBlobURL.download(0); const downloadFilePath = path.join( tempFolderPath, @@ -264,11 +266,13 @@ describe("Highlevel", () => { try { await uploadStreamToBlockBlob( - aborter, rs, blockBlobURL, 4 * 1024 * 1024, - 20 + 20, + { + abortSignal: aborter + } ); assert.fail(); } catch (err) { @@ -281,7 +285,6 @@ describe("Highlevel", () => { let eventTriggered = false; await uploadStreamToBlockBlob( - Aborter.none, rs, blockBlobURL, 4 * 1024 * 1024, @@ -299,7 +302,6 @@ describe("Highlevel", () => { it("downloadBlobToBuffer should success", async () => { const rs = fs.createReadStream(tempFileLarge); await uploadStreamToBlockBlob( - Aborter.none, rs, blockBlobURL, 4 * 1024 * 1024, @@ -307,7 +309,7 @@ describe("Highlevel", () => { ); const buf = Buffer.alloc(tempFileLargeLength); - await downloadBlobToBuffer(Aborter.none, buf, blockBlobURL, 0, undefined, { + await downloadBlobToBuffer(buf, blockBlobURL, 0, undefined, { blockSize: 4 * 1024 * 1024, maxRetryRequestsPerBlock: 5, parallelism: 20 @@ -320,7 +322,6 @@ describe("Highlevel", () => { it("downloadBlobToBuffer should abort", async () => { const rs = fs.createReadStream(tempFileLarge); await uploadStreamToBlockBlob( - Aborter.none, rs, blockBlobURL, 4 * 1024 * 1024, @@ -330,12 +331,12 @@ describe("Highlevel", () => { try { const buf = Buffer.alloc(tempFileLargeLength); await downloadBlobToBuffer( - Aborter.timeout(1), buf, blockBlobURL, 0, undefined, { + abortSignal: Aborter.timeout(1), blockSize: 4 * 1024 * 1024, maxRetryRequestsPerBlock: 5, parallelism: 20 @@ -350,7 +351,6 @@ describe("Highlevel", () => { it("downloadBlobToBuffer should update progress event", async () => { const rs = fs.createReadStream(tempFileSmall); await uploadStreamToBlockBlob( - Aborter.none, rs, blockBlobURL, 4 * 1024 * 1024, @@ -361,7 +361,8 @@ describe("Highlevel", () => { const buf = Buffer.alloc(tempFileSmallLength); const aborter = Aborter.none; try { - await downloadBlobToBuffer(aborter, buf, blockBlobURL, 0, undefined, { + await downloadBlobToBuffer(buf, blockBlobURL, 0, undefined, { + abortSignal: aborter, blockSize: 1 * 1024, maxRetryRequestsPerBlock: 5, parallelism: 1, @@ -376,7 +377,6 @@ describe("Highlevel", () => { it("bloburl.download should success when internal stream unexcepted ends at the stream end", async () => { const uploadResponse = await uploadFileToBlockBlob( - Aborter.none, tempFileSmall, blockBlobURL, { @@ -387,7 +387,6 @@ describe("Highlevel", () => { let retirableReadableStreamOptions: IRetriableReadableStreamOptions; const downloadResponse = await blockBlobURL.download( - Aborter.none, 0, undefined, { @@ -426,7 +425,6 @@ describe("Highlevel", () => { it("bloburl.download should download full data successfully when internal stream unexcepted ends", async () => { const uploadResponse = await uploadFileToBlockBlob( - Aborter.none, tempFileSmall, blockBlobURL, { @@ -438,7 +436,6 @@ describe("Highlevel", () => { let retirableReadableStreamOptions: IRetriableReadableStreamOptions; let injectedErrors = 0; const downloadResponse = await blockBlobURL.download( - Aborter.none, 0, undefined, { @@ -477,7 +474,6 @@ describe("Highlevel", () => { it("bloburl.download should download partial data when internal stream unexcepted ends", async () => { const uploadResponse = await uploadFileToBlockBlob( - Aborter.none, tempFileSmall, blockBlobURL, { @@ -491,7 +487,6 @@ describe("Highlevel", () => { let retirableReadableStreamOptions: IRetriableReadableStreamOptions; let injectedErrors = 0; const downloadResponse = await blockBlobURL.download( - Aborter.none, 0, partialSize, { @@ -534,7 +529,6 @@ describe("Highlevel", () => { it("bloburl.download should download data failed when exceeding max stream retry requests", async () => { const uploadResponse = await uploadFileToBlockBlob( - Aborter.none, tempFileSmall, blockBlobURL, { @@ -554,7 +548,6 @@ describe("Highlevel", () => { try { const downloadResponse = await blockBlobURL.download( - Aborter.none, 0, undefined, { @@ -587,7 +580,6 @@ describe("Highlevel", () => { it("bloburl.download should abort after retrys", async () => { const uploadResponse = await uploadFileToBlockBlob( - Aborter.none, tempFileSmall, blockBlobURL, { @@ -608,10 +600,10 @@ describe("Highlevel", () => { try { const aborter = Aborter.none; const downloadResponse = await blockBlobURL.download( - aborter, 0, undefined, { + abortSignal: aborter, blobAccessConditions: { modifiedAccessConditions: { ifMatch: uploadResponse.eTag diff --git a/sdk/storage/storage-blob/test/node/pagebloburl.test.ts b/sdk/storage/storage-blob/test/node/pagebloburl.test.ts index 4e7861bd89b1..1022b056db2d 100644 --- a/sdk/storage/storage-blob/test/node/pagebloburl.test.ts +++ b/sdk/storage/storage-blob/test/node/pagebloburl.test.ts @@ -17,25 +17,25 @@ describe("PageBlobURL", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); blobName = getUniqueName("blob"); blobURL = BlobURL.fromContainerURL(containerURL, blobName); pageBlobURL = PageBlobURL.fromBlobURL(blobURL); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("startCopyIncremental", async () => { - await pageBlobURL.create(Aborter.none, 1024, { + await pageBlobURL.create(1024, { metadata: { sourcemeta: "val" } }); - await pageBlobURL.uploadPages(Aborter.none, "b".repeat(1024), 0, 1024); + await pageBlobURL.uploadPages("b".repeat(1024), 0, 1024); - let snapshotResult = await pageBlobURL.createSnapshot(Aborter.none); + let snapshotResult = await pageBlobURL.createSnapshot(); assert.ok(snapshotResult.snapshot); const destPageBlobURL = PageBlobURL.fromContainerURL( @@ -43,10 +43,9 @@ describe("PageBlobURL", () => { getUniqueName("page") ); - await containerURL.setAccessPolicy(Aborter.none, "container"); + await containerURL.setAccessPolicy("container"); let copySource = pageBlobURL.withSnapshot(snapshotResult.snapshot!).url; let copyResponse = await destPageBlobURL.startCopyIncremental( - Aborter.none, copySource ); @@ -62,7 +61,7 @@ describe("PageBlobURL", () => { throw new Error("Copy unexcepted aborted."); case "pending": await sleep(3000); - copyResponse = await destPageBlobURL.getProperties(Aborter.none); + copyResponse = await destPageBlobURL.getProperties(); await waitForCopy(++retries); return; case "failed": @@ -84,12 +83,11 @@ describe("PageBlobURL", () => { assert.equal(listBlobResponse.segment.blobItems.length, 4); - await pageBlobURL.uploadPages(Aborter.none, "c".repeat(1024), 0, 1024); - snapshotResult = await pageBlobURL.createSnapshot(Aborter.none); + await pageBlobURL.uploadPages("c".repeat(1024), 0, 1024); + snapshotResult = await pageBlobURL.createSnapshot(); assert.ok(snapshotResult.snapshot); copySource = pageBlobURL.withSnapshot(snapshotResult.snapshot!).url; copyResponse = await destPageBlobURL.startCopyIncremental( - Aborter.none, copySource ); @@ -105,9 +103,7 @@ describe("PageBlobURL", () => { assert.equal(listBlobResponse.segment.blobItems.length, 6); - const pageBlobProperties = await destPageBlobURL.getProperties( - Aborter.none - ); + const pageBlobProperties = await destPageBlobURL.getProperties(); assert.equal(pageBlobProperties.metadata!.sourcemeta, "val"); }); }); diff --git a/sdk/storage/storage-blob/test/node/sas.test.ts b/sdk/storage/storage-blob/test/node/sas.test.ts index 2687871d4a64..4b57f9ecc295 100644 --- a/sdk/storage/storage-blob/test/node/sas.test.ts +++ b/sdk/storage/storage-blob/test/node/sas.test.ts @@ -53,7 +53,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { StorageURL.newPipeline(new AnonymousCredential()) ); - await serviceURLWithSAS.getAccountInfo(Aborter.none); + await serviceURLWithSAS.getAccountInfo(); }); it("generateAccountSASQueryParameters should not work with invalid permission", async () => { @@ -82,7 +82,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { let error; try { - await serviceURLWithSAS.getProperties(Aborter.none); + await serviceURLWithSAS.getProperties(); } catch (err) { error = err; } @@ -116,7 +116,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { let error; try { - await serviceURLWithSAS.getProperties(Aborter.none); + await serviceURLWithSAS.getProperties(); } catch (err) { error = err; } @@ -153,7 +153,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { let error; try { - await serviceURLWithSAS.getProperties(Aborter.none); + await serviceURLWithSAS.getProperties(); } catch (err) { error = err; } @@ -174,7 +174,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { const containerName = getUniqueName("container"); const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); const containerSAS = generateBlobSASQueryParameters( { @@ -196,7 +196,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { ); await containerURLwithSAS.listBlobFlatSegment(Aborter.none); - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("generateBlobSASQueryParameters should work for blob", async () => { @@ -212,11 +212,11 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { const containerName = getUniqueName("container"); const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); const blobName = getUniqueName("blob"); const blobURL = PageBlobURL.fromContainerURL(containerURL, blobName); - await blobURL.create(Aborter.none, 1024, { + await blobURL.create(1024, { blobHTTPHeaders: { blobContentType: "content-type-original" } @@ -247,14 +247,14 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { StorageURL.newPipeline(new AnonymousCredential()) ); - const properties = await blobURLwithSAS.getProperties(Aborter.none); + const properties = await blobURLwithSAS.getProperties(); assert.equal(properties.cacheControl, "cache-control-override"); assert.equal(properties.contentDisposition, "content-disposition-override"); assert.equal(properties.contentEncoding, "content-encoding-override"); assert.equal(properties.contentLanguage, "content-language-override"); assert.equal(properties.contentType, "content-type-override"); - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("generateBlobSASQueryParameters should work for blob with special namings", async () => { @@ -270,13 +270,13 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { const containerName = getUniqueName("container-with-dash"); const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); const blobName = getUniqueName( "////Upper/blob/empty /another 汉字 ру́сский язы́к ру́сский язы́к عربي/عربى にっぽんご/にほんご . special ~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,/'" ); const blobURL = PageBlobURL.fromContainerURL(containerURL, blobName); - await blobURL.create(Aborter.none, 1024, { + await blobURL.create(1024, { blobHTTPHeaders: { blobContentType: "content-type-original" } @@ -308,14 +308,14 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { StorageURL.newPipeline(new AnonymousCredential()) ); - const properties = await blobURLwithSAS.getProperties(Aborter.none); + const properties = await blobURLwithSAS.getProperties(); assert.equal(properties.cacheControl, "cache-control-override"); assert.equal(properties.contentDisposition, "content-disposition-override"); assert.equal(properties.contentEncoding, "content-encoding-override"); assert.equal(properties.contentLanguage, "content-language-override"); assert.equal(properties.contentType, "content-type-override"); - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("generateBlobSASQueryParameters should work for blob with access policy", async () => { @@ -331,14 +331,14 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { const containerName = getUniqueName("container"); const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); const blobName = getUniqueName("blob"); const blobURL = PageBlobURL.fromContainerURL(containerURL, blobName); - await blobURL.create(Aborter.none, 1024); + await blobURL.create(1024); const id = "unique-id"; - await containerURL.setAccessPolicy(Aborter.none, undefined, [ + await containerURL.setAccessPolicy(undefined, [ { accessPolicy: { expiry: tmr, @@ -363,7 +363,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { StorageURL.newPipeline(new AnonymousCredential()) ); - await blobURLwithSAS.getProperties(Aborter.none); - await containerURL.delete(Aborter.none); + await blobURLwithSAS.getProperties(); + await containerURL.delete(); }); }); diff --git a/sdk/storage/storage-blob/test/pagebloburl.test.ts b/sdk/storage/storage-blob/test/pagebloburl.test.ts index 3cef7acd3d3f..e407d474dd3c 100644 --- a/sdk/storage/storage-blob/test/pagebloburl.test.ts +++ b/sdk/storage/storage-blob/test/pagebloburl.test.ts @@ -1,7 +1,6 @@ import * as assert from "assert"; import { bodyToString, getBSU, getUniqueName } from "./utils"; -import { Aborter } from "../src/Aborter"; import { BlobURL } from "../src/BlobURL"; import { ContainerURL } from "../src/ContainerURL"; import { PageBlobURL } from "../src/PageBlobURL"; @@ -19,20 +18,20 @@ describe("PageBlobURL", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); blobName = getUniqueName("blob"); blobURL = BlobURL.fromContainerURL(containerURL, blobName); pageBlobURL = PageBlobURL.fromBlobURL(blobURL); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("create with default parameters", async () => { - await pageBlobURL.create(Aborter.none, 512); + await pageBlobURL.create(512); - const result = await blobURL.download(Aborter.none, 0); + const result = await blobURL.download(0); assert.deepStrictEqual( await bodyToString(result, 512), "\u0000".repeat(512) @@ -53,15 +52,15 @@ describe("PageBlobURL", () => { key2: "valb" } }; - await pageBlobURL.create(Aborter.none, 512, options); + await pageBlobURL.create(512, options); - const result = await blobURL.download(Aborter.none, 0); + const result = await blobURL.download(0); assert.deepStrictEqual( await bodyToString(result, 512), "\u0000".repeat(512) ); - const properties = await blobURL.getProperties(Aborter.none); + const properties = await blobURL.getProperties(); assert.equal( properties.cacheControl, options.blobHTTPHeaders.blobCacheControl @@ -87,35 +86,35 @@ describe("PageBlobURL", () => { }); it("uploadPages", async () => { - await pageBlobURL.create(Aborter.none, 1024); + await pageBlobURL.create(1024); - const result = await blobURL.download(Aborter.none, 0); + const result = await blobURL.download(0); assert.equal(await bodyToString(result, 1024), "\u0000".repeat(1024)); - await pageBlobURL.uploadPages(Aborter.none, "a".repeat(512), 0, 512); - await pageBlobURL.uploadPages(Aborter.none, "b".repeat(512), 512, 512); + await pageBlobURL.uploadPages("a".repeat(512), 0, 512); + await pageBlobURL.uploadPages("b".repeat(512), 512, 512); - const page1 = await pageBlobURL.download(Aborter.none, 0, 512); - const page2 = await pageBlobURL.download(Aborter.none, 512, 512); + const page1 = await pageBlobURL.download(0, 512); + const page2 = await pageBlobURL.download(512, 512); assert.equal(await bodyToString(page1, 512), "a".repeat(512)); assert.equal(await bodyToString(page2, 512), "b".repeat(512)); }); it("clearPages", async () => { - await pageBlobURL.create(Aborter.none, 1024); - let result = await blobURL.download(Aborter.none, 0); + await pageBlobURL.create(1024); + let result = await blobURL.download(0); assert.deepStrictEqual( await bodyToString(result, 1024), "\u0000".repeat(1024) ); - await pageBlobURL.uploadPages(Aborter.none, "a".repeat(1024), 0, 1024); - result = await pageBlobURL.download(Aborter.none, 0, 1024); + await pageBlobURL.uploadPages("a".repeat(1024), 0, 1024); + result = await pageBlobURL.download(0, 1024); assert.deepStrictEqual(await bodyToString(result, 1024), "a".repeat(1024)); - await pageBlobURL.clearPages(Aborter.none, 0, 512); - result = await pageBlobURL.download(Aborter.none, 0, 512); + await pageBlobURL.clearPages(0, 512); + result = await pageBlobURL.download(0, 512); assert.deepStrictEqual( await bodyToString(result, 512), "\u0000".repeat(512) @@ -123,43 +122,42 @@ describe("PageBlobURL", () => { }); it("getPageRanges", async () => { - await pageBlobURL.create(Aborter.none, 1024); + await pageBlobURL.create(1024); - const result = await blobURL.download(Aborter.none, 0); + const result = await blobURL.download(0); assert.deepStrictEqual( await bodyToString(result, 1024), "\u0000".repeat(1024) ); - await pageBlobURL.uploadPages(Aborter.none, "a".repeat(512), 0, 512); - await pageBlobURL.uploadPages(Aborter.none, "b".repeat(512), 512, 512); + await pageBlobURL.uploadPages("a".repeat(512), 0, 512); + await pageBlobURL.uploadPages("b".repeat(512), 512, 512); - const page1 = await pageBlobURL.getPageRanges(Aborter.none, 0, 512); - const page2 = await pageBlobURL.getPageRanges(Aborter.none, 512, 512); + const page1 = await pageBlobURL.getPageRanges(0, 512); + const page2 = await pageBlobURL.getPageRanges(512, 512); assert.equal(page1.pageRange![0].end, 511); assert.equal(page2.pageRange![0].end, 1023); }); it("getPageRangesDiff", async () => { - await pageBlobURL.create(Aborter.none, 1024); + await pageBlobURL.create(1024); - const result = await blobURL.download(Aborter.none, 0); + const result = await blobURL.download(0); assert.deepStrictEqual( await bodyToString(result, 1024), "\u0000".repeat(1024) ); - await pageBlobURL.uploadPages(Aborter.none, "b".repeat(1024), 0, 1024); + await pageBlobURL.uploadPages("b".repeat(1024), 0, 1024); - const snapshotResult = await pageBlobURL.createSnapshot(Aborter.none); + const snapshotResult = await pageBlobURL.createSnapshot(); assert.ok(snapshotResult.snapshot); - await pageBlobURL.uploadPages(Aborter.none, "a".repeat(512), 0, 512); - await pageBlobURL.clearPages(Aborter.none, 512, 512); + await pageBlobURL.uploadPages("a".repeat(512), 0, 512); + await pageBlobURL.clearPages(512, 512); const rangesDiff = await pageBlobURL.getPageRangesDiff( - Aborter.none, 0, 1024, snapshotResult.snapshot! @@ -171,19 +169,19 @@ describe("PageBlobURL", () => { }); it("updateSequenceNumber", async () => { - await pageBlobURL.create(Aborter.none, 1024); - let propertiesResponse = await pageBlobURL.getProperties(Aborter.none); + await pageBlobURL.create(1024); + let propertiesResponse = await pageBlobURL.getProperties(); - await pageBlobURL.updateSequenceNumber(Aborter.none, "increment"); - propertiesResponse = await pageBlobURL.getProperties(Aborter.none); + await pageBlobURL.updateSequenceNumber("increment"); + propertiesResponse = await pageBlobURL.getProperties(); assert.equal(propertiesResponse.blobSequenceNumber!, 1); - await pageBlobURL.updateSequenceNumber(Aborter.none, "update", 10); - propertiesResponse = await pageBlobURL.getProperties(Aborter.none); + await pageBlobURL.updateSequenceNumber("update", 10); + propertiesResponse = await pageBlobURL.getProperties(); assert.equal(propertiesResponse.blobSequenceNumber!, 10); - await pageBlobURL.updateSequenceNumber(Aborter.none, "max", 100); - propertiesResponse = await pageBlobURL.getProperties(Aborter.none); + await pageBlobURL.updateSequenceNumber("max", 100); + propertiesResponse = await pageBlobURL.getProperties(); assert.equal(propertiesResponse.blobSequenceNumber!, 100); }); }); diff --git a/sdk/storage/storage-blob/test/retrypolicy.test.ts b/sdk/storage/storage-blob/test/retrypolicy.test.ts index 260304f43fcc..49dfaaf1ff4c 100644 --- a/sdk/storage/storage-blob/test/retrypolicy.test.ts +++ b/sdk/storage/storage-blob/test/retrypolicy.test.ts @@ -2,7 +2,6 @@ import { URLBuilder } from "@azure/ms-rest-js"; import * as assert from "assert"; import { RestError, StorageURL } from "../src"; -import { Aborter } from "../src/Aborter"; import { ContainerURL } from "../src/ContainerURL"; import { Pipeline } from "../src/Pipeline"; import { getBSU, getUniqueName } from "./utils"; @@ -18,11 +17,11 @@ describe("RetryPolicy", () => { beforeEach(async () => { containerName = getUniqueName("container"); containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); - await containerURL.create(Aborter.none); + await containerURL.create(); }); afterEach(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("Retry Policy should work when first request fails with 500", async () => { @@ -47,9 +46,9 @@ describe("RetryPolicy", () => { keya: "vala", keyb: "valb" }; - await injectContainerURL.setMetadata(Aborter.none, metadata); + await injectContainerURL.setMetadata(metadata); - const result = await containerURL.getProperties(Aborter.none); + const result = await containerURL.getProperties(); assert.deepEqual(result.metadata, metadata); }); @@ -76,7 +75,7 @@ describe("RetryPolicy", () => { keya: "vala", keyb: "valb" }; - await injectContainerURL.setMetadata(Aborter.none, metadata); + await injectContainerURL.setMetadata(metadata); } catch (err) { hasError = true; } @@ -117,7 +116,7 @@ describe("RetryPolicy", () => { let finalRequestURL = ""; try { - const response = await injectContainerURL.getProperties(Aborter.none); + const response = await injectContainerURL.getProperties(); finalRequestURL = response._response.request.url; } catch (err) { finalRequestURL = err.request ? err.request.url : ""; diff --git a/sdk/storage/storage-blob/test/serviceurl.test.ts b/sdk/storage/storage-blob/test/serviceurl.test.ts index cc0d6623dcf9..0c33c5035d9f 100644 --- a/sdk/storage/storage-blob/test/serviceurl.test.ts +++ b/sdk/storage/storage-blob/test/serviceurl.test.ts @@ -41,8 +41,8 @@ describe("ServiceURL", () => { serviceURL, containerName2 ); - await containerURL1.create(Aborter.none, { metadata: { key: "val" } }); - await containerURL2.create(Aborter.none, { metadata: { key: "val" } }); + await containerURL1.create({ metadata: { key: "val" } }); + await containerURL2.create({ metadata: { key: "val" } }); const result1 = await serviceURL.listContainersSegment( Aborter.none, @@ -98,13 +98,13 @@ describe("ServiceURL", () => { ); assert.deepEqual(result2.containerItems![0].metadata!.key, "val"); - await containerURL1.delete(Aborter.none); - await containerURL2.delete(Aborter.none); + await containerURL1.delete(); + await containerURL2.delete(); }); it("GetProperties", async () => { const serviceURL = getBSU(); - const result = await serviceURL.getProperties(Aborter.none); + const result = await serviceURL.getProperties(); assert.ok(typeof result.requestId); assert.ok(result.requestId!.length > 0); @@ -123,7 +123,7 @@ describe("ServiceURL", () => { it("SetProperties", async () => { const serviceURL = getBSU(); - const serviceProperties = await serviceURL.getProperties(Aborter.none); + const serviceProperties = await serviceURL.getProperties(); serviceProperties.logging = { deleteProperty: true, @@ -176,10 +176,10 @@ describe("ServiceURL", () => { }; } - await serviceURL.setProperties(Aborter.none, serviceProperties); + await serviceURL.setProperties(serviceProperties); await wait(5 * 1000); - const result = await serviceURL.getProperties(Aborter.none); + const result = await serviceURL.getProperties(); assert.ok(typeof result.requestId); assert.ok(result.requestId!.length > 0); assert.ok(typeof result.version); @@ -208,7 +208,7 @@ describe("ServiceURL", () => { it("getAccountInfo", async () => { const serviceURL = getBSU(); - const accountInfo = await serviceURL.getAccountInfo(Aborter.none); + const accountInfo = await serviceURL.getAccountInfo(); assert.ok(accountInfo.accountKind); assert.ok(accountInfo.skuName); }); diff --git a/sdk/storage/storage-blob/test/specialnaming.test.ts b/sdk/storage/storage-blob/test/specialnaming.test.ts index f44444a9a557..cf0ab4bed474 100644 --- a/sdk/storage/storage-blob/test/specialnaming.test.ts +++ b/sdk/storage/storage-blob/test/specialnaming.test.ts @@ -13,18 +13,18 @@ describe("Special Naming Tests", () => { const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName); before(async () => { - await containerURL.create(Aborter.none); + await containerURL.create(); }); after(async () => { - await containerURL.delete(Aborter.none); + await containerURL.delete(); }); it("Should work with special container and blob names with spaces", async () => { const blobName: string = getUniqueName("blob empty"); const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName); - await blockBlobURL.upload(Aborter.none, "A", 1); + await blockBlobURL.upload("A", 1); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -42,7 +42,7 @@ describe("Special Naming Tests", () => { containerURL.pipeline ); - await blockBlobURL.upload(Aborter.none, "A", 1); + await blockBlobURL.upload("A", 1); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -57,8 +57,8 @@ describe("Special Naming Tests", () => { const blobName: string = getUniqueName("////blob/empty /another"); const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -76,8 +76,8 @@ describe("Special Naming Tests", () => { containerURL.pipeline ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -92,8 +92,8 @@ describe("Special Naming Tests", () => { const blobName: string = getUniqueName("////Upper/blob/empty /another"); const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -111,8 +111,8 @@ describe("Special Naming Tests", () => { containerURL.pipeline ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -129,8 +129,8 @@ describe("Special Naming Tests", () => { ); const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -150,8 +150,8 @@ describe("Special Naming Tests", () => { containerURL.pipeline ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -168,8 +168,8 @@ describe("Special Naming Tests", () => { ); const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -196,8 +196,8 @@ describe("Special Naming Tests", () => { containerURL.pipeline ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -217,8 +217,8 @@ describe("Special Naming Tests", () => { blobNameEncoded ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -233,8 +233,8 @@ describe("Special Naming Tests", () => { const blobName: string = getUniqueName("ру́сский язы́к"); const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -252,8 +252,8 @@ describe("Special Naming Tests", () => { containerURL.pipeline ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -272,8 +272,8 @@ describe("Special Naming Tests", () => { blobNameEncoded ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -288,8 +288,8 @@ describe("Special Naming Tests", () => { const blobName: string = getUniqueName("عربي/عربى"); const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -307,8 +307,8 @@ describe("Special Naming Tests", () => { containerURL.pipeline ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -327,8 +327,8 @@ describe("Special Naming Tests", () => { blobNameEncoded ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -343,8 +343,8 @@ describe("Special Naming Tests", () => { const blobName: string = getUniqueName("にっぽんご/にほんご"); const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, @@ -362,8 +362,8 @@ describe("Special Naming Tests", () => { containerURL.pipeline ); - await blockBlobURL.upload(Aborter.none, "A", 1); - await blockBlobURL.getProperties(Aborter.none); + await blockBlobURL.upload("A", 1); + await blockBlobURL.getProperties(); const response = await containerURL.listBlobFlatSegment( Aborter.none, undefined, diff --git a/sdk/storage/storage-blob/tsconfig.json b/sdk/storage/storage-blob/tsconfig.json index 61885eb2e18c..39e8f25bd11e 100644 --- a/sdk/storage/storage-blob/tsconfig.json +++ b/sdk/storage/storage-blob/tsconfig.json @@ -20,6 +20,6 @@ "esModuleInterop": true }, "compileOnSave": true, - "exclude": ["node_modules", "./samples/*"], + "exclude": ["node_modules", "./samples/**"], "include": ["./src/**/*.ts", "./test/**/*.ts"] } \ No newline at end of file