From 68a8df69f2e15caeb9ba9c5afbc40332e48aab70 Mon Sep 17 00:00:00 2001 From: Justus Fluegel Date: Sat, 18 Jul 2020 03:03:45 +0200 Subject: [PATCH] Add types for dependency-solver (#46119) Co-authored-by: Justus Fluegel --- .../dependency-solver-tests.ts | 8 +++++ types/dependency-solver/index.d.ts | 34 +++++++++++++++++++ types/dependency-solver/tsconfig.json | 23 +++++++++++++ types/dependency-solver/tslint.json | 1 + 4 files changed, 66 insertions(+) create mode 100644 types/dependency-solver/dependency-solver-tests.ts create mode 100644 types/dependency-solver/index.d.ts create mode 100644 types/dependency-solver/tsconfig.json create mode 100644 types/dependency-solver/tslint.json diff --git a/types/dependency-solver/dependency-solver-tests.ts b/types/dependency-solver/dependency-solver-tests.ts new file mode 100644 index 0000000000..64d5cc2323 --- /dev/null +++ b/types/dependency-solver/dependency-solver-tests.ts @@ -0,0 +1,8 @@ +import { addMissingKeys, getDependedBy, getDependencyLines, getEdges, getInDegree, solve } from 'dependency-solver'; + +const graph: { [key: string]: string[] } = addMissingKeys({ a: ['b', 'c'], c: ['b'] }); +const dependedBy_1: { [key: string]: number } = getDependedBy({ a: ['b', 'c'], c: ['b'] }); +const dependedBy_2: { [key: string]: number } = getEdges({ a: ['b', 'c'], c: ['b'] }); +const dependencyLines_1: Array<[string, string]> = getDependencyLines({ a: ['b', 'c'], c: ['b'] }); +const dependencyLines_2: Array<[string, string]> = getInDegree({ a: ['b', 'c'], c: ['b'] }); +const solved: string[] = solve({ a: ['b', 'c'], c: ['b'] }); diff --git a/types/dependency-solver/index.d.ts b/types/dependency-solver/index.d.ts new file mode 100644 index 0000000000..f705ee652d --- /dev/null +++ b/types/dependency-solver/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for dependency-solver 1.0 +// Project: https://github.com/haavistu/dependency-solver#readme +// Definitions by: Justus Fluegel +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Solve dependency graph + * + * @param g dependency graph + */ +export function solve(g: { [key: string]: string[] }): string[]; + +/** + * Add missing keys for dependencies of other nodes + * + * @param g dependency graph + */ +export function addMissingKeys(g: { [key: string]: string[] }): { [key: string]: string[] }; + +/** + * Get numbers of dependants for each node + * + * @param g dependency graph + */ +export function getEdges(g: { [key: string]: string[] }): { [key: string]: number }; + +/** + * Get relations between dependencies, eg. the lines in a tree diagramm + * + * @param g dependency graph + */ +export function getInDegree(g: { [key: string]: string[] }): Array<[string, string]>; + +export { getEdges as getDependedBy, getInDegree as getDependencyLines }; diff --git a/types/dependency-solver/tsconfig.json b/types/dependency-solver/tsconfig.json new file mode 100644 index 0000000000..3f6197a32d --- /dev/null +++ b/types/dependency-solver/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "dependency-solver-tests.ts" + ] +} diff --git a/types/dependency-solver/tslint.json b/types/dependency-solver/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/dependency-solver/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }