-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): rework the sdk api to a more class-based approach (#8)
* Create common building blocks to interact with the RDS API: RdsServer, RdsCatalog, and RdsDataProduct. * Add initial testing for these three classes. * Add dependencies for existing MTNA model libraries BREAKING CHANGE: No longer singletons, must instantiate the RdsServer, RdsCatalog, and RdsDataProduct via the constructor. RJ-3
- Loading branch information
1 parent
48f3697
commit 35cc217
Showing
38 changed files
with
1,007 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { ResolutionListener } from './resolution-listener'; | ||
|
||
/** | ||
* An asyncronous resource that can be resolved. | ||
*/ | ||
export abstract class AsyncResource { | ||
/** Whether this resource is resolved */ | ||
private resolved = false; | ||
/** Whether this resource is resolving */ | ||
private resolving = false; | ||
/** Array of resolution listeners */ | ||
private resolutionListeners: ResolutionListener[] = []; | ||
|
||
/** | ||
* Create a new AsyncResource | ||
* | ||
* @param resolve whether to resolve the resource now, defaults to false | ||
*/ | ||
constructor(resolve: boolean) { | ||
if (resolve) { | ||
this.resolve().catch(error => console.error('[@rds/sdk] AsyncResource: failed to resolve', error)); | ||
} | ||
} | ||
|
||
/** @returns whether this resource is resolved */ | ||
isResolved(): boolean { | ||
return this.resolved; | ||
} | ||
|
||
/** @returns whether this resource is resolving */ | ||
isResolving(): boolean { | ||
return this.resolving; | ||
} | ||
|
||
/** | ||
* Register a listener that will emit when this resource has been resolved sucessfully. | ||
* @param listener the listener for when this resource has been resolved | ||
*/ | ||
registerResolutionListener(listener: ResolutionListener) { | ||
this.resolutionListeners.push(listener); | ||
} | ||
|
||
/** | ||
* Resolve this resource. | ||
* | ||
* @returns a promise that completes once the resource is resolved | ||
*/ | ||
abstract async resolve(): Promise<void>; | ||
|
||
/** | ||
* Setter for `resolved`. | ||
* @param resolved whether this resource is resolved | ||
*/ | ||
protected setResolved(resolved: boolean) { | ||
this.resolved = resolved; | ||
// When the resource is resolved, | ||
// notify any resolution listeners | ||
if (this.resolved) { | ||
while (this.resolutionListeners.length) { | ||
this.resolutionListeners.pop()?.resolved(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Setter for `resolving`. | ||
* @param resolving whether the resource is resolving | ||
*/ | ||
protected setResolving(resolving: boolean) { | ||
this.resolving = resolving; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './async-resource'; | ||
export * from './resolution-listener'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface ResolutionListener { | ||
resolved(): void; | ||
} |
Oops, something went wrong.