Skip to content

Commit

Permalink
Create BaseCacheService
Browse files Browse the repository at this point in the history
  • Loading branch information
LocalNewsTV committed Jan 16, 2025
1 parent 0cdb792 commit 95655a3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions app/src/utils/base-classes/BaseCacheService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @desc Generic Base Class for All Caching actions using SQLite or LocalForage ensuring consistency between all Database implementations
* @property { RepoMetadata } _ All Details contained by a Metadata Entry
* @property { RepositoryDownloadRequestSpec } _ Information details for a Download e.g. API Url, Cache Targets, bounding boxes
* @property { ProgressCallbackParams } _ Details for Callback Functionality, used for Progress bars, updates
* @property { RepositoryStatusSchema } _ Enum for Cache Statuses, e.g. READY, CACHED, ERROR, etc
* @example Implementation abstract Class Demo extends BaseCacheService<
* RepoMetadataType
* RepositoryDownloadRequestSpecType
* RepoProgressCallbackParamsType
* RepositoryStatusSchemeType>
*/
abstract class BaseCacheService<
RepoMetadata,
RepositoryDownloadRequestSpec,
ProgressCallbackParams,
RepositoryStatusSchema
> {
/** Update any details for a Repository */
protected abstract addOrUpdateRepository(repositoryId: RepoMetadata): Promise<void>;

/** Remove one Repository from the collection along with its contentes */
public abstract deleteRepository(repositoryId: string): Promise<void>;

/** Pull metadata for one Repository in the Collection */
public abstract getRepository(repositoryId: string): Promise<RepoMetadata | null>;

/** List metadata for all Repositories */
public abstract listRepositories(): Promise<RepoMetadata[]>;

/** Change the status for a given Repository */
public abstract setRepositoryStatus(repositoryId: string, status: RepositoryStatusSchema): Promise<void>;

/** Download a new Repository along with its contents */
public abstract download(
spec: RepositoryDownloadRequestSpec,
progressCallback?: (currentProgress: ProgressCallbackParams) => void
): Promise<boolean | void>;

protected constructor() {}
}

export default BaseCacheService;

0 comments on commit 95655a3

Please sign in to comment.