All files / src/datasource adapter.ts

100% Statements 1/1
100% Branches 0/0
100% Functions 0/0
100% Lines 1/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                            5x                                                                    
import type {
  DatafileContent,
  EnvironmentKey,
  ExistingState,
  HistoryEntry,
  Commit,
  CommitHash,
  EntityType,
} from "@featurevisor/types";
 
export interface DatafileOptions {
  environment: EnvironmentKey | false;
  target?: string;
  datafilesDir?: string;
}
 
export interface DatafileFile {
  path: string;
  size: number;
  gzipSize: number;
}
 
export abstract class Adapter {
  abstract listSets(): Promise<string[]>;
 
  // entities
  abstract listEntities(entityType: EntityType): Promise<string[]>;
  abstract entityExists(entityType: EntityType, entityKey: string): Promise<boolean>;
  abstract readEntity<T>(entityType: EntityType, entityKey: string): Promise<T>;
  abstract writeEntity<T>(entityType: EntityType, entityKey: string, entity: T): Promise<T>;
  abstract deleteEntity(entityType: EntityType, entityKey: string): Promise<void>;
 
  // state
  abstract readState(environment: EnvironmentKey | false): Promise<ExistingState>;
  abstract writeState(
    environment: EnvironmentKey | false,
    existingState: ExistingState,
  ): Promise<void>;
 
  // datafile
  listDatafiles?(): Promise<DatafileFile[]>;
  abstract readDatafile(options: DatafileOptions): Promise<DatafileContent>;
  abstract writeDatafile(datafileContent: DatafileContent, options: DatafileOptions): Promise<void>;
 
  // revision
  abstract readRevision(): Promise<string>;
  abstract writeRevision(revision: string): Promise<void>;
 
  // history
  abstract listHistoryEntries(entityType?: EntityType, entityKey?: string): Promise<HistoryEntry[]>;
  abstract readCommit(
    commit: CommitHash,
    entityType?: EntityType,
    entityKey?: string,
  ): Promise<Commit>;
}