From cf612d4221db644791c5dcfa3f90a083dcef5b00 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Thu, 10 Feb 2022 16:46:35 -0800 Subject: [PATCH 1/3] wip --- .../.eslintrc.json | 4 ++ .../package.json | 1 + .../eventhubs-checkpointstore-blob.api.md | 23 ++++++++- .../src/blobCheckpointStore.ts | 7 +-- .../src/index.ts | 1 + .../src/storageBlobInterfaces.ts | 47 +++++++++++++++++++ 6 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 sdk/eventhub/eventhubs-checkpointstore-blob/.eslintrc.json create mode 100644 sdk/eventhub/eventhubs-checkpointstore-blob/src/storageBlobInterfaces.ts diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/.eslintrc.json b/sdk/eventhub/eventhubs-checkpointstore-blob/.eslintrc.json new file mode 100644 index 000000000000..47d9fc35be4a --- /dev/null +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/.eslintrc.json @@ -0,0 +1,4 @@ +{ + "plugins": ["@azure/azure-sdk"], + "extends": ["plugin:@azure/azure-sdk/azure-sdk-base"] +} diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/package.json b/sdk/eventhub/eventhubs-checkpointstore-blob/package.json index 556a049644c8..3d1a7c66a579 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/package.json +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/package.json @@ -59,6 +59,7 @@ }, "dependencies": { "@azure/abort-controller": "^1.0.0", + "@azure/core-paging": "^1.2.0", "@azure/event-hubs": "^5.8.0-beta.1", "@azure/logger": "^1.0.0", "@azure/storage-blob": "^12.8.0", diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/review/eventhubs-checkpointstore-blob.api.md b/sdk/eventhub/eventhubs-checkpointstore-blob/review/eventhubs-checkpointstore-blob.api.md index 2d20508980e2..40ffdc170023 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/review/eventhubs-checkpointstore-blob.api.md +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/review/eventhubs-checkpointstore-blob.api.md @@ -5,21 +5,40 @@ ```ts import { AzureLogger } from '@azure/logger'; +import { BlobItem } from '@azure/storage-blob'; +import { BlobSetMetadataOptions } from '@azure/storage-blob'; +import { BlockBlobUploadOptions } from '@azure/storage-blob'; +import { BlockBlobUploadResponse } from '@azure/storage-blob'; import { Checkpoint } from '@azure/event-hubs'; import { CheckpointStore } from '@azure/event-hubs'; -import { ContainerClient } from '@azure/storage-blob'; +import { ContainerListBlobFlatSegmentResponse } from '@azure/storage-blob'; +import { ContainerListBlobsOptions } from '@azure/storage-blob'; +import { ContainerSetMetadataResponse } from '@azure/storage-blob'; +import { HttpRequestBody } from '@azure/storage-blob'; +import { Metadata } from '@azure/storage-blob'; import { OperationOptions } from '@azure/event-hubs'; +import { PagedAsyncIterableIterator } from '@azure/core-paging'; import { PartitionOwnership } from '@azure/event-hubs'; // @public export class BlobCheckpointStore implements CheckpointStore { - constructor(containerClient: ContainerClient); + constructor(containerClient: ContainerClientLike); claimOwnership(partitionOwnership: PartitionOwnership[], options?: OperationOptions): Promise; listCheckpoints(fullyQualifiedNamespace: string, eventHubName: string, consumerGroup: string, options?: OperationOptions): Promise; listOwnership(fullyQualifiedNamespace: string, eventHubName: string, consumerGroup: string, options?: OperationOptions): Promise; updateCheckpoint(checkpoint: Checkpoint, options?: OperationOptions): Promise; } +// @public +export interface ContainerClientLike { + // Warning: (ae-forgotten-export) The symbol "BlobClientLike" needs to be exported by the entry point index.d.ts + // + // (undocumented) + getBlobClient(blobName: string): BlobClientLike; + // (undocumented) + listBlobsFlat(options?: ContainerListBlobsOptions): PagedAsyncIterableIterator; +} + // @public export const logger: AzureLogger; diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/src/blobCheckpointStore.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/src/blobCheckpointStore.ts index f7e07df13850..206ecac4ac1d 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/src/blobCheckpointStore.ts +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/src/blobCheckpointStore.ts @@ -7,17 +7,18 @@ import { Checkpoint, OperationOptions, } from "@azure/event-hubs"; -import { ContainerClient, Metadata, RestError, BlobSetMetadataResponse } from "@azure/storage-blob"; +import { Metadata, RestError, BlobSetMetadataResponse } from "@azure/storage-blob"; import { logger, logErrorStackTrace } from "./log"; +import { ContainerClientLike } from "./storageBlobInterfaces"; import { throwTypeErrorIfParameterMissing } from "./util/error"; /** * An implementation of CheckpointStore that uses Azure Blob Storage to persist checkpoint data. */ export class BlobCheckpointStore implements CheckpointStore { - private _containerClient: ContainerClient; + private _containerClient: ContainerClientLike; - constructor(containerClient: ContainerClient) { + constructor(containerClient: ContainerClientLike) { this._containerClient = containerClient; } /** diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/src/index.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/src/index.ts index 87caa1697650..3d3aac22135f 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/src/index.ts +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/src/index.ts @@ -3,4 +3,5 @@ /// export { BlobCheckpointStore } from "./blobCheckpointStore"; +export { ContainerClientLike } from "./storageBlobInterfaces"; export { logger } from "./log"; diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/src/storageBlobInterfaces.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/src/storageBlobInterfaces.ts new file mode 100644 index 000000000000..4a4a1a50a8af --- /dev/null +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/src/storageBlobInterfaces.ts @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + Metadata, + BlobItem, + ContainerListBlobFlatSegmentResponse, + ContainerListBlobsOptions, + BlockBlobUploadOptions, + BlockBlobUploadResponse, + HttpRequestBody, + BlobSetMetadataOptions, + ContainerSetMetadataResponse, +} from "@azure/storage-blob"; +import { PagedAsyncIterableIterator } from "@azure/core-paging"; + +/** + * An interface compatible with Storage Blob's BlobClient class. + */ +export interface BlobClientLike { + getBlockBlobClient(): BlockBlobClientLike; +} + +/** + * An interface compatible with Storage Blob's ContainerClient class. + */ +export interface ContainerClientLike { + getBlobClient(blobName: string): BlobClientLike; + listBlobsFlat( + options?: ContainerListBlobsOptions + ): PagedAsyncIterableIterator; +} + +/** + * An interface compatible with Storage Blob's BlockBlobClient class. + */ +export interface BlockBlobClientLike { + upload( + body: HttpRequestBody, + contentLength: number, + options?: BlockBlobUploadOptions + ): Promise; + setMetadata( + metadata?: Metadata, + options?: BlobSetMetadataOptions + ): Promise; +} From 090a9f110691504dcae6b4b81ded1238fc4fecde Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 11 Feb 2022 12:17:57 -0800 Subject: [PATCH 2/3] cleanup docs --- .../eventhubs-checkpointstore-blob.api.md | 15 +++++++++++---- .../src/blobCheckpointStore.ts | 4 ++++ .../src/index.ts | 2 +- .../src/storageBlobInterfaces.ts | 18 +++++++++++++++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/review/eventhubs-checkpointstore-blob.api.md b/sdk/eventhub/eventhubs-checkpointstore-blob/review/eventhubs-checkpointstore-blob.api.md index 40ffdc170023..67e1e238991a 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/review/eventhubs-checkpointstore-blob.api.md +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/review/eventhubs-checkpointstore-blob.api.md @@ -29,13 +29,20 @@ export class BlobCheckpointStore implements CheckpointStore { updateCheckpoint(checkpoint: Checkpoint, options?: OperationOptions): Promise; } +// @public +export interface BlobClientLike { + getBlockBlobClient(): BlockBlobClientLike; +} + +// @public +export interface BlockBlobClientLike { + setMetadata(metadata?: Metadata, options?: BlobSetMetadataOptions): Promise; + upload(body: HttpRequestBody, contentLength: number, options?: BlockBlobUploadOptions): Promise; +} + // @public export interface ContainerClientLike { - // Warning: (ae-forgotten-export) The symbol "BlobClientLike" needs to be exported by the entry point index.d.ts - // - // (undocumented) getBlobClient(blobName: string): BlobClientLike; - // (undocumented) listBlobsFlat(options?: ContainerListBlobsOptions): PagedAsyncIterableIterator; } diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/src/blobCheckpointStore.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/src/blobCheckpointStore.ts index 206ecac4ac1d..e6390318d239 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/src/blobCheckpointStore.ts +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/src/blobCheckpointStore.ts @@ -18,6 +18,10 @@ import { throwTypeErrorIfParameterMissing } from "./util/error"; export class BlobCheckpointStore implements CheckpointStore { private _containerClient: ContainerClientLike; + /** + * Constructs a new instance of {@link BlobCheckpointStore} + * @param containerClient - An instance of a storage blob ContainerClient. + */ constructor(containerClient: ContainerClientLike) { this._containerClient = containerClient; } diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/src/index.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/src/index.ts index 3d3aac22135f..12018ccfcbf0 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/src/index.ts +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/src/index.ts @@ -3,5 +3,5 @@ /// export { BlobCheckpointStore } from "./blobCheckpointStore"; -export { ContainerClientLike } from "./storageBlobInterfaces"; +export { ContainerClientLike, BlobClientLike, BlockBlobClientLike } from "./storageBlobInterfaces"; export { logger } from "./log"; diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/src/storageBlobInterfaces.ts b/sdk/eventhub/eventhubs-checkpointstore-blob/src/storageBlobInterfaces.ts index 4a4a1a50a8af..5d6a5057a21a 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/src/storageBlobInterfaces.ts +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/src/storageBlobInterfaces.ts @@ -15,9 +15,12 @@ import { import { PagedAsyncIterableIterator } from "@azure/core-paging"; /** - * An interface compatible with Storage Blob's BlobClient class. + * An interface compatible with an instance of {@link BlobClient}. */ export interface BlobClientLike { + /** + * Creates a BlockBlobClient object. + */ getBlockBlobClient(): BlockBlobClientLike; } @@ -25,7 +28,14 @@ export interface BlobClientLike { * An interface compatible with Storage Blob's ContainerClient class. */ export interface ContainerClientLike { + /** + * Creates a {@link BlobClient} + */ getBlobClient(blobName: string): BlobClientLike; + /** + * Returns an async iterable iterator to list all the blobs + * under the specified account. + */ listBlobsFlat( options?: ContainerListBlobsOptions ): PagedAsyncIterableIterator; @@ -35,11 +45,17 @@ export interface ContainerClientLike { * An interface compatible with Storage Blob's BlockBlobClient class. */ export interface BlockBlobClientLike { + /** + * Creates a new block blob, or updated the content of an existing block blob. + */ upload( body: HttpRequestBody, contentLength: number, options?: BlockBlobUploadOptions ): Promise; + /** + * Sets user-defined metadata for the specified blob as one or more name-value pairs. + */ setMetadata( metadata?: Metadata, options?: BlobSetMetadataOptions From 786dc36f6b662d26e809be7bf709b04fdba28f1a Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 11 Feb 2022 14:42:27 -0800 Subject: [PATCH 3/3] changelog --- sdk/eventhub/eventhubs-checkpointstore-blob/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/CHANGELOG.md b/sdk/eventhub/eventhubs-checkpointstore-blob/CHANGELOG.md index 21f9192a4e44..b9e1a4ccfe80 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/CHANGELOG.md +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/CHANGELOG.md @@ -3,6 +3,7 @@ ## 1.1.0-beta.1 (Unreleased) ### Features Added + - With the dropping of support for Node.js versions that are no longer in LTS, the dependency on `@types/node` has been updated to version 12. Read our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details. - Updates all async methods on `BlobCheckpointStore` to accept an optional `options` parameter that can be used to pass in an @@ -13,6 +14,8 @@ ### Key Bugs Fixed +- Fixed a bug where `ContainerClient` could not passed to `BlobCheckpointStore` if the `ContainerClient` was created by another version of `@azure/storage-blob`. + ## 1.0.1 (2020-08-03) - Fixes issue [#10132](https://github.com/Azure/azure-sdk-for-js/issues/10132)