All files / datasource adapter.ts

33.33% Statements 1/3
100% Branches 0/0
0% Functions 0/2
33.33% Lines 1/3

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72                                                      5x                                                                                        
/* eslint-disable @typescript-eslint/no-unused-vars */
import type {
  DatafileContent,
  EnvironmentKey,
  ExistingState,
  HistoryEntry,
  Commit,
  CommitHash,
  EntityType,
} from "@featurevisor/types";
 
import type { Scope } from "../config";
 
export interface DatafileOptions {
  environment: EnvironmentKey | false;
  tag?: string;
  scope?: Scope;
  datafilesDir?: string;
}
 
export type FeatureEnvironmentProperty = "rules" | "force" | "expose";
 
export interface FeatureSourcePaths {
  baseFilePath: string;
  environmentFilePaths: Record<string, string>;
}
 
export abstract class Adapter {
  // 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
  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>;
 
  // feature source helpers (used by lint/history attribution)
  async getFeatureSourcePaths(_featureKey: string): Promise<FeatureSourcePaths | undefined> {
    return undefined;
  }
 
  async getFeaturePropertySourcePath(
    _featureKey: string,
    _property: FeatureEnvironmentProperty,
    _environment?: string,
  ): Promise<string | undefined> {
    return undefined;
  }
}