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

cartesi / rollups-explorer / 10317825307

09 Aug 2024 10:34AM CUT coverage: 93.674% (-0.05%) from 93.722%
10317825307

Pull #223

github

nevendyulgerov
chore(packages/ui): Revert change
Pull Request #223: #220 Upgrade mantine packages

1147 of 1362 branches covered (84.21%)

Branch coverage included in aggregate %.

18 of 18 new or added lines in 4 files covered. (100.0%)

9 existing lines in 1 file now uncovered.

12403 of 13103 relevant lines covered (94.66%)

39.54 hits per line

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

86.08
/apps/web/src/components/specification/hooks/localRepository.ts
1
"use client";
1✔
2
import { clone, hasPath, omit, pathOr, values } from "ramda";
1✔
3
import { Repository, Specification } from "../types";
1✔
4

1✔
5
export const namespace = `cartesiscan:specs` as const;
1✔
6

1✔
7
type DictKey = Required<Specification>["id"];
1✔
8
type Dict = { [k: DictKey]: Specification };
1✔
9

1✔
10
const deserialize = <T>(jsonString: string) => JSON.parse(jsonString) as T;
1✔
11
const serialize = (cfg: Dict) => JSON.stringify(cfg);
1✔
12

1✔
13
const getConfig = () => {
1✔
14
    const raw = localStorage.getItem(namespace);
39✔
15
    return raw ? deserialize<Dict>(raw) : {};
39✔
16
};
39✔
17

1✔
18
/**
1✔
19
 * Implements the Repository interface providing a persistent storage.
1✔
20
 * It uses the LocalStorage underneath.
1✔
21
 */
1✔
22
const localRepository: Repository = {
1✔
23
    async add(spec: Specification) {
1✔
24
        const cfg = getConfig();
2✔
25
        spec.id = Date.now().toString();
2✔
26
        spec.timestamp = Date.now();
2✔
27
        cfg[spec.id] = spec;
2✔
28
        localStorage.setItem(namespace, serialize(cfg));
2✔
29

2✔
30
        return clone(spec);
2✔
31
    },
2✔
32

1✔
33
    async has(id) {
1✔
34
        const cfg = getConfig();
×
35
        return hasPath([id], cfg);
×
36
    },
×
37

1✔
38
    async remove(id) {
1✔
39
        const cfg = getConfig();
1✔
40
        if (hasPath([id], cfg)) {
1!
41
            const newCfg = omit([id], cfg);
×
42
            localStorage.setItem(namespace, serialize(newCfg));
×
43
        }
×
44

1✔
45
        return true;
1✔
46
    },
1✔
47
    async get(id) {
1✔
48
        const cfg = getConfig();
×
49
        return pathOr<Specification | null>(null, [id], cfg);
×
50
    },
×
51

1✔
52
    async list() {
1✔
53
        return values(getConfig());
35✔
54
    },
35✔
55

1✔
56
    async update(spec: Specification) {
1✔
57
        if (!spec.id)
1✔
58
            throw new Error("Trying to update a specification without Id");
1!
59
        const cfg = getConfig();
1✔
60
        spec.timestamp = Date.now();
1✔
61
        cfg[spec.id] = spec;
1✔
62
        localStorage.setItem(namespace, serialize(cfg));
1✔
63

1✔
64
        return clone(spec);
1✔
65
    },
1✔
66
};
1✔
67

1✔
68
export default localRepository;
1✔
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