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

cartesi / rollups-explorer / 10138892735

29 Jul 2024 05:56AM UTC coverage: 92.455% (-0.9%) from 93.346%
10138892735

Pull #213

github

brunomenezes
feat: Integrate decoding spec + input-details-view. Improve error handling for Content component.
Pull Request #213: Feature/165 add decode specification v1

897 of 1067 branches covered (84.07%)

Branch coverage included in aggregate %.

1137 of 1303 new or added lines in 21 files covered. (87.26%)

2 existing lines in 1 file now uncovered.

10168 of 10901 relevant lines covered (93.28%)

48.08 hits per line

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

54.93
/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);
1✔
15
    return raw ? deserialize<Dict>(raw) : {};
1!
16
};
1✔
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✔
NEW
24
        const cfg = getConfig();
×
NEW
25
        spec.id = Date.now().toString();
×
NEW
26
        spec.timestamp = Date.now();
×
NEW
27
        cfg[spec.id] = spec;
×
NEW
28
        localStorage.setItem(namespace, serialize(cfg));
×
NEW
29

×
NEW
30
        return clone(spec);
×
NEW
31
    },
×
32

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

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

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

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

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

×
NEW
64
        return clone(spec);
×
NEW
65
    },
×
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

© 2026 Coveralls, Inc