MCPcopy Index your code
hub / github.com/bytebase/bytebase / safeRead

Function safeRead

frontend/src/react/stores/sqlEditor/editor.ts:32–47  ·  view source on GitHub ↗
(
  key: string,
  parse: (raw: unknown) => T | undefined,
  fallback: T
)

Source from the content-addressed store, hash-verified

30const DEFAULT_RESULT_ROWS_LIMIT = 1000;
31
32const safeRead = <T>(
33 key: string,
34 parse: (raw: unknown) => T | undefined,
35 fallback: T
36): T => {
37 if (typeof window === "undefined") return fallback;
38 try {
39 const raw = window.localStorage.getItem(key);
40 if (raw === null) return fallback;
41 const parsed = JSON.parse(raw);
42 const valid = parse(parsed);
43 return valid === undefined ? fallback : valid;
44 } catch {
45 return fallback;
46 }
47};
48
49const safeWrite = (key: string, value: unknown) => {
50 if (typeof window === "undefined") return;

Callers 3

readProjectFunction · 0.70
readResultRowsLimitFunction · 0.70
readRedisOptionFunction · 0.70

Calls 1

parseFunction · 0.85

Tested by

no test coverage detected