Skip to content

Commit

Permalink
fix(sources): update typings (#3044)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel authored Oct 13, 2020
1 parent 870962c commit 90dd892
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
28 changes: 24 additions & 4 deletions packages/sources/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export as namespace cdtnSources

export function getLabelBySourceFn(src: SourceLabel): string
export function getLabelBySource(src: SourceLabel): string

export function getRouteBySourceFn(src: SourceRoute): string
export function getRouteBySource(src: SourceRoute): RouteValues

export function getSourceByRouteFn(slug: string): SourceValues | null
export function getSourceByRoute(slug: string): SourceValues | null

export const SOURCES:SOURCES

type SourceLabel = Exclude<SourceValues, "highlights" | "page_convention_collective" | "glossary" | "prequalified" | "page_fiche_ministere_travail"| "versions" >
type SourceRoute = Exclude<SourceValues, "highlights" | "prequalified" | "versions" >

type SOURCES = {
CCN: "conventions_collectives",
CCN_PAGE: "page_convention_collective",
Expand All @@ -33,5 +33,25 @@ type SOURCES = {
VERSIONS: "versions",
}

type Routes = {
[SOURCES.CCN]: "convention-collective",
[SOURCES.CCN_PAGE]: "page-convention-collective",
[SOURCES.CDT]: "code-du-travail",
[SOURCES.CONTRIBUTIONS]: "contribution",
[SOURCES.EDITORIAL_CONTENT]: "information",
[SOURCES.EXTERNALS]: "external",
[SOURCES.GLOSSARY]: "glossaire",
[SOURCES.IDCC]: "idcc",
[SOURCES.LABOUR_LAW]: "droit-du-travail",
[SOURCES.LETTERS]: "modeles-de-courriers",
[SOURCES.SHEET_MT]: "fiche-ministere-travail",
[SOURCES.SHEET_MT_PAGE]: "fiche-ministere-travail",
[SOURCES.SHEET_SP]: "fiche-service-public",
[SOURCES.THEMATIC_FILES]: "dossiers",
[SOURCES.THEMES]: "themes",
[SOURCES.TOOLS]: "outils",
}

type SourceKeys = keyof SOURCES;
type SourceValues = SOURCES[SourceKeys];
type RouteValues = Routes[SourceRoute];
6 changes: 3 additions & 3 deletions packages/sources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ const routes = /**@type {[import(".").SourceValues, string][]}*/ (Object.entries
));

// code_du_travail -> Code du travail
/** @type {cdtnSources.getLabelBySourceFn} */
/** @type {cdtnSources.getLabelBySource} */
const getLabelBySource = (src) => labelBySource[src];

// code_du_travail -> code-du-travail
/** @type {cdtnSources.getRouteBySourceFn} */
/** @type {cdtnSources.getRouteBySource} */
const getRouteBySource = (src) => routeBySource[src];

// code-du-travail -> code_du_travail
/** @type {cdtnSources.getSourceByRouteFn} */
/** @type {cdtnSources.getSourceByRoute} */
const getSourceByRoute = (slug) => {
const [source] = routes.find(([, value]) => slug === value) || [];
return source ? source : null;
Expand Down

0 comments on commit 90dd892

Please sign in to comment.