Implementation:Apache Druid LocalStorage Keys
| Knowledge Sources | |
|---|---|
| Domains | Web_Console, State_Persistence |
| Last Updated | 2026-02-10 10:00 GMT |
Overview
Defines a typed registry of localStorage keys and provides safe accessor functions for persisting web console state in the browser.
Description
The LocalStorage Keys module exports a `LocalStorageKeys` constant object mapping named identifiers (e.g., `QUERY_KEY`, `WORKBENCH_QUERIES`, `EXPLORE_STATE`) to their corresponding localStorage string keys. It also provides type-safe getter, setter, and removal functions that handle JSON serialization via `json-bigint-native`, gracefully degrade when localStorage is unavailable, and support an optional namespace prefix for key isolation.
Usage
Used throughout the web console to persist user preferences, query state, workbench configurations, table column selections, refresh rates, and explore view state across browser sessions.
Code Reference
Source Location
- Repository: Apache Druid
- File: web-console/src/utils/local-storage-keys.tsx
- Lines: 1-121
Signature
export const LocalStorageKeys: {
CAPABILITIES_OVERRIDE: 'capabilities-override';
INGESTION_SPEC: 'ingestion-spec';
QUERY_KEY: 'druid-console-query';
QUERY_CONTEXT: 'query-context';
WORKBENCH_QUERIES: 'workbench-queries';
EXPLORE_STATE: 'explore-state';
WEB_CONSOLE_CONFIGS: 'web-console-configs';
// ... and many more
};
export type LocalStorageKeys = (typeof LocalStorageKeys)[keyof typeof LocalStorageKeys];
export function setLocalStorageNamespace(namespace: string): void;
export function localStorageSet(key: LocalStorageKeys, value: string): void;
export function localStorageSetJson(key: LocalStorageKeys, value: any): void;
export function localStorageGet(key: LocalStorageKeys): string | undefined;
export function localStorageGetJson(key: LocalStorageKeys): any;
export function localStorageRemove(key: LocalStorageKeys): void;
Import
import { LocalStorageKeys, localStorageGet, localStorageSetJson } from './utils/local-storage-keys';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| key | LocalStorageKeys |
Yes | A typed localStorage key identifier from the LocalStorageKeys registry |
| value | any | Yes | The value to store; plain string for localStorageSet, any serializable value for localStorageSetJson |
| namespace | string |
Yes | An optional prefix namespace to isolate localStorage keys |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | undefined | The raw stored string value, or undefined if not found (localStorageGet) |
| (return) | any |
The JSON-parsed value, or undefined if not found or parse fails (localStorageGetJson) |
Usage Examples
Store and retrieve a JSON value
import { LocalStorageKeys, localStorageSetJson, localStorageGetJson } from './utils/local-storage-keys';
localStorageSetJson(LocalStorageKeys.QUERY_CONTEXT, { sqlOuterLimit: 1000 });
const ctx = localStorageGetJson(LocalStorageKeys.QUERY_CONTEXT);
// ctx = { sqlOuterLimit: 1000 }
Use namespace isolation
import { setLocalStorageNamespace, localStorageSet, localStorageGet } from './utils/local-storage-keys';
setLocalStorageNamespace('my-instance');
localStorageSet(LocalStorageKeys.QUERY_KEY, 'SELECT 1');
// Stored under key 'my-instance:druid-console-query'