Skip to content

Commit

Permalink
change FeedRange interface to abstract class (Azure#27043)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR
@azure/cosmos

### Issues associated with this PR
N/A

### Describe the problem that is addressed by this PR
`FeedRange` for changefeed is changed from interface to abstract class
for avoiding confusion among users. Users cannot create instance of
abstract class and can now only pass feed range from the result of
`container.getFeedRanges()` call.


### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_
N/A

### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
amanrao23 authored Sep 7, 2023
1 parent b99018b commit 9093cb7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
8 changes: 4 additions & 4 deletions sdk/cosmosdb/cosmos/review/cosmos.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1012,10 +1012,10 @@ export interface FeedOptions extends SharedOptions {
useIncrementalFeed?: boolean;
}

// @public (undocumented)
export interface FeedRange {
maxExclusive: string;
minInclusive: string;
// @public
export abstract class FeedRange {
readonly maxExclusive: string;
readonly minInclusive: string;
}

// @public (undocumented)
Expand Down
36 changes: 22 additions & 14 deletions sdk/cosmosdb/cosmos/src/client/ChangeFeed/FeedRange.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { ErrorResponse } from "../../request";

/**
* @hidden
* Specifies a feed range for the changefeed.
*/
export class FeedRangeInternal implements FeedRange {
export abstract class FeedRange {
/**
* Min value for the feed range.
*/
minInclusive: string;
readonly minInclusive: string;
/**
* Max value for the feed range.
*/
maxExclusive: string;
readonly maxExclusive: string;
/**
* @internal
*/
protected constructor(minInclusive: string, maxExclusive: string) {
// only way to explictly block users from creating FeedRange directly in JS
if (new.target === FeedRange) {
throw new ErrorResponse("Cannot instantiate abstract class FeedRange");
}

constructor(minInclusive: string, maxExclusive: string) {
this.minInclusive = minInclusive;
this.maxExclusive = maxExclusive;
}
}

export interface FeedRange {
/**
* Min value for the feed range.
*/
minInclusive: string;
/**
* Max value for the feed range.
*/
maxExclusive: string;
/**
* @hidden
* Specifies a feed range for the changefeed.
*/
export class FeedRangeInternal extends FeedRange {
/* eslint-disable @typescript-eslint/no-useless-constructor */
constructor(minInclusive: string, maxExclusive: string) {
super(minInclusive, maxExclusive);
}
}

0 comments on commit 9093cb7

Please sign in to comment.