Skip to content

Commit

Permalink
feat: update BaseProvider class documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
msudgh committed Aug 18, 2024
1 parent 258e3d8 commit e3c1bb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
30 changes: 9 additions & 21 deletions src/providers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InvalidConfigError } from '../errors'
import { Storage, customOptions } from '../schemas/input'
import { sync, syncMetadata, syncTags } from '../storages/s3/buckets'
import {
ISyncCloudStorage,
IBaseProvider,
MethodReturn,
ProviderOptions,
SyncMetadataReturn,
Expand All @@ -16,10 +16,10 @@ import {
import { logger } from '../utils/logger'

/**
* Base Sync Cloud Storage class.
* @implements ISyncCloudStorage
* Base provider class for cloud frameworks.
* @implements {IBaseProvider}
*/
export abstract class BaseProvider implements ISyncCloudStorage {
export abstract class BaseProvider implements IBaseProvider {
readonly servicePath: string
readonly options: ProviderOptions
readonly client: S3Client
Expand Down Expand Up @@ -51,12 +51,9 @@ export abstract class BaseProvider implements ISyncCloudStorage {

/**
* Get S3 client.
* @returns {S3Client}
* @memberof BaseProvider
* @see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3
*
* @example
* const client = this.getS3Client()
* @returns {S3Client}
*/
getS3Client(): S3Client {
const endpoint = this.options.syncCloudStorage.offline
Expand All @@ -72,11 +69,8 @@ export abstract class BaseProvider implements ISyncCloudStorage {

/**
* Sync storages.
* @private
* @memberof BaseProvider
* @returns {Promise<{ result: SyncResult[] }>}
* @example
* const result = await this.storages()
*/
async storages(): Promise<{ result: SyncResult[] }> {
const isPluginDisable = this.disableCheck().result
Expand All @@ -102,8 +96,6 @@ export abstract class BaseProvider implements ISyncCloudStorage {
* @memberof BaseProvider
* @see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3
* @returns {Promise<PromiseSettledResult<SyncMetadataReturn>[]>}
* @example
* const result = await this.metadata()
*/
async metadata(): Promise<PromiseSettledResult<SyncMetadataReturn>[]> {
return await Promise.allSettled(
Expand All @@ -113,12 +105,9 @@ export abstract class BaseProvider implements ISyncCloudStorage {

/**
* Sync tags.
* @private
* @memberof BaseProvider
* @see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3
* @returns {Promise<TagsSyncResults>}
* @example
* const result = await this.tags()
*/
async tags(): Promise<TagsSyncResults> {
const isPluginDisable = this.disableCheck().result

Check warning on line 113 in src/providers/base.ts

View check run for this annotation

Codecov / codecov/patch

src/providers/base.ts#L112-L113

Added lines #L112 - L113 were not covered by tests
Expand All @@ -137,21 +126,20 @@ export abstract class BaseProvider implements ISyncCloudStorage {
* @private
* @returns {Promise<void>}
* @memberof BaseProvider
*
* @example
* await this.onExit()
*/
async onExit(): Promise<void> {
private async onExit(): Promise<void> {

Check warning on line 130 in src/providers/base.ts

View check run for this annotation

Codecov / codecov/patch

src/providers/base.ts#L130

Added line #L130 was not covered by tests
if (this.client) {
this.client.destroy()

Check warning on line 132 in src/providers/base.ts

View check run for this annotation

Codecov / codecov/patch

src/providers/base.ts#L132

Added line #L132 was not covered by tests
}
}

/**
* Check if the plugin is disabled.
* @private
* @memberof BaseProvider
* @returns {MethodReturn<boolean>}
*/
disableCheck(): MethodReturn<boolean> {
private disableCheck(): MethodReturn<boolean> {

Check warning on line 142 in src/providers/base.ts

View check run for this annotation

Codecov / codecov/patch

src/providers/base.ts#L142

Added line #L142 was not covered by tests
if (this.options.syncCloudStorage.disabled) {
logger.warning('SyncCloudStorage is disabled!')
return { result: true }

Check warning on line 145 in src/providers/base.ts

View check run for this annotation

Codecov / codecov/patch

src/providers/base.ts#L144-L145

Added lines #L144 - L145 were not covered by tests
Expand Down
4 changes: 1 addition & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ export const isFulfilledSyncResult = (

export type ProviderName = 'serverless' | 'cdk'

export interface ISyncCloudStorage {
export interface IBaseProvider {
storages(servicePath: string): Promise<{ result: SyncResult[] }>
metadata(): Promise<PromiseSettledResult<SyncMetadataReturn>[]>
tags(): Promise<TagsSyncResults>
onExit(): Promise<void>
disableCheck(): MethodReturn<boolean>
}

export type Provider = IServerless | Construct
Expand Down

0 comments on commit e3c1bb0

Please sign in to comment.