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

graphty-org / graphty-element / 15988747166

01 Jul 2025 03:01AM UTC coverage: 78.121% (+4.3%) from 73.786%
15988747166

push

github

apowers313
test: fix test types and mocks

319 of 434 branches covered (73.5%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

202 existing lines in 8 files now uncovered.

2284 of 2898 relevant lines covered (78.81%)

886.86 hits per line

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

88.52
/src/data/DataSource.ts
1
import {z} from "zod/v4";
2✔
2
import * as z4 from "zod/v4/core";
2✔
3

4
import {AdHocData} from "../config";
5

6
type DataSourceClass = new (opts: object) => DataSource;
7
const dataSourceRegistry = new Map<string, DataSourceClass>();
2✔
8
export interface DataSourceChunk {
9
    nodes: AdHocData[];
10
    edges: AdHocData[];
11
}
12

13
export abstract class DataSource {
2✔
14
    static readonly type: string;
15
    edgeSchema: z4.$ZodObject | null = null;
20✔
16
    nodeSchema: z4.$ZodObject | null = null;
20✔
17

18
    // abstract init(): Promise<void>;
19
    abstract sourceFetchData(): AsyncGenerator<DataSourceChunk, void, unknown>;
20

21
    async *getData(): AsyncGenerator<DataSourceChunk, void, unknown> {
2✔
22
        for await (const chunk of this.sourceFetchData()) {
19✔
23
            if (this.nodeSchema) {
18✔
24
                for (const n of chunk.nodes) {
2✔
25
                    await this.dataValidator(this.nodeSchema, n);
78✔
26
                }
77✔
27
            }
1✔
28

29
            if (this.edgeSchema) {
18!
30
                for (const e of chunk.edges) {
×
31
                    await this.dataValidator(this.edgeSchema, e);
×
UNCOV
32
                }
×
UNCOV
33
            }
✔
34

35
            yield chunk;
17✔
36
        }
16✔
37
    }
19✔
38

39
    async dataValidator(schema: z4.$ZodObject, obj: object): Promise<void> {
2✔
40
        const res = await z4.safeParseAsync(schema, obj);
78✔
41
        if (!res.success) {
78✔
42
            const errMsg = z.prettifyError(res.error);
1✔
43
            throw new TypeError(`Error while validating data in '${this.type}' data source:\n${errMsg}`);
1✔
44
        }
1✔
45
    }
78✔
46

47
    get type(): string {
2✔
48
        return (this.constructor as typeof DataSource).type;
2✔
49
    }
2✔
50

51
    static register<T extends DataSourceClass>(cls: T): T {
2✔
52
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
        const t: string = (cls as any).type;
8✔
54
        dataSourceRegistry.set(t, cls);
8✔
55
        return cls;
8✔
56
    }
8✔
57

58
    static get(type: string, opts: object = {}): DataSource | null {
2✔
59
        const SourceClass = dataSourceRegistry.get(type);
16✔
60
        if (SourceClass) {
16✔
61
            return new SourceClass(opts);
16✔
62
        }
16!
63

UNCOV
64
        return null;
×
65
    }
16✔
66
}
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