• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

graphty-org / graphty-element / 15958807562

29 Jun 2025 07:51PM UTC coverage: 73.631% (+0.2%) from 73.423%
15958807562

push

github

apowers313
test(test): remove .only test

270 of 375 branches covered (72.0%)

Branch coverage included in aggregate %.

2056 of 2784 relevant lines covered (73.85%)

485.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.18
/src/algorithms/Algorithm.ts
1
import {set as deepSet} from "lodash";
2✔
2

3
import {AdHocData} from "../config";
4
import {Edge} from "../Edge";
5
import {Graph} from "../Graph";
6

7
type AlgorithmClass = new (opts: object) => Algorithm;
8
const algorithmRegistry = new Map<string, AlgorithmClass>();
2✔
9
const algorithmResults: Record<string, AdHocData> = {}; // TODO: this global should live on the graph instance
2✔
10

11
// algorithmResults layout:
12
// {
13
//     node: {
14
//         id: {
15
//             namespace: {
16
//                 algorithm: {
17
//                     result: unknown
18
//                 }
19
//             }
20
//         }
21
//     },
22
//     edge: {
23
//         id: {
24
//             namespace: {
25
//                 algorithm: {
26
//                     result: unknown
27
//                 }
28
//             }
29
//         }
30
//     },
31
//     graph: {
32
//         namespace: {
33
//             algorithm: {
34
//                 result: unknown
35
//             }
36
//         }
37
//     }
38
// }
39

40
export abstract class Algorithm {
2✔
41
    static type: string;
42
    static namespace: string;
43

44
    get type() {
2✔
45
        return (this.constructor as typeof Algorithm).type;
77✔
46
    }
77✔
47

48
    get namespace() {
2✔
49
        return (this.constructor as typeof Algorithm).namespace;
77✔
50
    }
77✔
51

52
    get results(): AdHocData {
2✔
53
        return structuredClone(algorithmResults) as AdHocData;
1✔
54
    }
1✔
55

56
    abstract run(g: Graph): Promise<void>;
57

58
    #createPath(elementType: string, id?: number | string): string[] {
2✔
59
        const ret: string[] = [];
77✔
60
        ret.push(elementType);
77✔
61

62
        if (typeof id === "number") {
77!
63
            ret.push(id.toString());
×
64
        } else if (typeof id === "string") {
77✔
65
            ret.push(id);
77✔
66
        }
77✔
67

68
        ret.push(this.namespace);
77✔
69
        ret.push(this.type);
77✔
70

71
        return ret;
77✔
72
    }
77✔
73

74
    addNodeResult(nodeId: number | string, result: unknown): void {
2✔
75
        const p = this.#createPath("node", nodeId);
77✔
76
        deepSet(algorithmResults, p, result);
77✔
77
    }
77✔
78

79
    addEdgeResult(e: Edge, result: unknown): void {
2✔
80
        console.log("adding edge result", e, result);
×
81
    }
×
82

83
    addGraphResult(g: Graph, result: unknown): void {
2✔
84
        console.log("adding graph result", g, result);
×
85
    }
×
86

87
    static register<T extends AlgorithmClass>(cls: T) {
2✔
88
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
        const t: string = (cls as any).type;
7✔
90
        algorithmRegistry.set(t, cls);
7✔
91
        return cls;
7✔
92
    }
7✔
93

94
    static get(type: string, opts: object = {}): Algorithm | null {
2✔
95
        const SourceClass = algorithmRegistry.get(type);
×
96
        if (SourceClass) {
×
97
            return new SourceClass(opts);
×
98
        }
×
99

100
        return null;
×
101
    }
×
102
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc