Skip to content

Commit

Permalink
feat: refactor types.ts for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
msudgh committed Aug 18, 2024
1 parent e3c1bb0 commit caaf03e
Showing 1 changed file with 24 additions and 35 deletions.
59 changes: 24 additions & 35 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import Serverless from 'serverless'

import { CustomOptions, Storage } from './schemas/input'

export type IServerlessProvider = ReturnType<
typeof Serverless.prototype.getProvider
>
export type AWSProvider = ReturnType<typeof Serverless.prototype.getProvider>

// Instance definition of AWS Serverless with the the custom options.
export type IServerless = {
service: {
custom: CustomOptions
Expand All @@ -17,18 +16,18 @@ export type IServerless = {
}
}
}
getProvider(name: string): IServerlessProvider
getProvider(name: string): AWSProvider
}

export interface ExtendedServerlessProvider extends IServerlessProvider {
cachedCredentials?: {
accessKeyId?: string
secretAccessKey?: string
sessionToken?: string
region?: string
}
export interface IBaseProvider {
storages(servicePath: string): Promise<{ result: SyncResult[] }>
metadata(): Promise<PromiseSettledResult<SyncMetadataReturn>[]>
tags(): Promise<TagsSyncResults>
}

export type Provider = IServerless | Construct
export type CdkOptions = CustomOptions['syncCloudStorage']
export type ProviderOptions = CustomOptions
export type LocalFile = {
fileName: string
localPath: string
Expand Down Expand Up @@ -60,10 +59,6 @@ export type StoragesSyncResult = {
metadata?: Record<string, string>
}

export type DeepPartial<T> = {
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]
}

export interface MethodReturn<T = undefined> {
storage?: Storage
result?: T
Expand Down Expand Up @@ -94,26 +89,20 @@ interface SyncRejectedResult {

export type SyncResult = SyncFulfilledResult | SyncRejectedResult

export const isFulfilledSyncResult = (
result: SyncResult
): result is SyncFulfilledResult => result.status === 'fulfilled'

export type ProviderName = 'serverless' | 'cdk'

export interface IBaseProvider {
storages(servicePath: string): Promise<{ result: SyncResult[] }>
metadata(): Promise<PromiseSettledResult<SyncMetadataReturn>[]>
tags(): Promise<TagsSyncResults>
// Testing utilities and types
export interface ExtendedServerlessProvider extends AWSProvider {
cachedCredentials?: {
accessKeyId?: string
secretAccessKey?: string
sessionToken?: string
region?: string
}
}

export type Provider = IServerless | Construct

export type ServerlessOptions = CustomOptions
export type CdkOptions = CustomOptions['syncCloudStorage']
export type ProviderOptions = CustomOptions
export interface LogActivity {
name: string
status: 'fulfilled' | 'rejected'
reason?: string
result?: unknown
export type DeepPartial<T> = {
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]
}

export const isFulfilledSyncResult = (
result: SyncResult
): result is SyncFulfilledResult => result.status === 'fulfilled'

0 comments on commit caaf03e

Please sign in to comment.