All files / src/apps/sources types.ts

20% Statements 1/5
0% Branches 0/4
0% Functions 0/1
25% Lines 1/4

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 73 74 75 76                                                                                                                              1x                        
import {
  BaseConceptContainer,
  EditableConceptContainerFields,
  Version
} from "../../utils";
 
interface BaseSource extends BaseConceptContainer {
  extras?: { source?: string };
}
 
export interface Source extends BaseSource {
  supported_locales: string[];
  website?: string;
  source_type: string;
  owner_url?: string;
  owner?: string;
}
interface BaseAPISource extends BaseConceptContainer {
  external_id: string;
  id: string;
  full_name: string;
  website?: string;
  custom_validation_schema: string;
}
 
export interface NewAPISource extends BaseAPISource {
  // api expects a comma separated string for this in create/ edit data
  supported_locales: string;
  owner_url: string;
  source_type?: string;
}
 
export interface APISource extends BaseAPISource {
  source_type: string;
  url: string;
  active_concepts: number;
  concepts_url: string;
  extras?: {};
  supported_locales: string[];
  owner: string;
  owner_type: string;
  owner_url: string;
}
 
export interface SourceVersion extends Version {}
 
export interface SourceState {
  sources: { items: APISource[]; responseMeta?: {} }[];
  source?: APISource;
  newSource?: APISource;
  versions: APISourceVersion[];
  showOnlyVerified: boolean;
}
export interface APISourceVersion extends SourceVersion {
  version_url: string;
  url: string;
}
 
export interface EditableSourceFields extends EditableConceptContainerFields {
  public_access?: string;
  source_type?: string;
}
 
const apiSourceToSource = (apiSource?: APISource): Source | undefined => {
  if (!apiSource) return apiSource;
 
  const { url, supported_locales, ...theRest } = apiSource;
 
  return {
    supported_locales: supported_locales || [],
    ...theRest
  };
};
 
export { apiSourceToSource };