scottohara / tvmanager

PWA for tracking recorded, watched & upcoming TV shows
MIT License
3 stars 0 forks source link

Revisit persisted/serialised interfaces #90

Open scottohara opened 4 years ago

scottohara commented 4 years ago

As part of the migration from WebSQL to IndexedDb, we opted for minimal changes to the storage formats to reduce the impact on other parts of the code base (outside of the storage layer).

At some point we should revisit this and update where it makes sense to do so, for example:

  1. Change the ModelType aliases from proper case to lower case
  2. Create a base PersistedModel interface that other models extend
  3. Remove PersistedProgram.ProgramID, PersistedSeries.SeriesID and PersistedEpisode.EpisodeID primary keys in favour of the common PersistedModel.id field
  4. Remove PersistedProgram.ProgramName, PersistedSeries.SeriesName and PersistedEpisode.EpisodeName fields in favour of the common PersistedModel.name field
  5. etc.

Strawman

export type ModelType = "program" | "series" | "episode";

// Interfaces for persisting to local storage (IndexedDb)

interface PersistedModel {
  id: string;
  name: string;
}

type PersistedProgram = PersistedModel;

interface PersistedSeries extends PersistedModel {
  programId: string;
  nowShowing: number;
}

interface PersistedEpisode extends PersistedModel {
  seriesId: string;
  status: EpisodeStatus;
  statusDate: string;
  unverified: boolean;
  unscheduled: boolean;
  sequence: number;
}

interface PersistedSetting {
  name: string;
  value: string;
}

interface PersistedSync {
  type: ModelType;
  id: string;
  action: SyncAction;
}

// Interfaces for import/exporting to remote storage (CouchDb)

export type SerializedModel = SerializedProgram | SerializedSeries | SerializedEpisode;

interface SerializedProgram extends PersistedProgram {
  type: "program";
}

interface SerializedSeries extends PersistedSeries {
  type: "series";
}

interface SerializedEpisode extends PersistedEpisode {
  type: "episode";
}

// Interfaces for list results

interface EpisodeCounts {
  episodeCount: number;
  watchedCount: number;
  recordedCount: number;
  expectedCount: number;
}

interface ProgramEpisodeCounts extends EpisodeCounts {
  seriesCount: number;
}

interface ProgramListItem extends PersistedProgram, ProgramEpisodeCounts {}

interface SeriesListItem extends PersistedSeries, EpisodeCounts {
  programName: string;
  missedCount?: number;
  statusWarningCount?: number;
}

interface SeriesStatusListItem extends PersistedSeries {
  programName: string;
  episodeCount: number;
  statusCount: number;
}

interface EpisodeListItem extends PersistedEpisode {
  seriesName: string;
  programId: string;
  programName: string;
}