Skip to Content
Octopus Energy Packages
API ReferenceStoragenuqs

nuqs Server

APIs exported from @octopus-energy/measurements/storage/nuqs/server

Use this entry point in Server Components, route handlers, or getServerSideProps. The parser configs work with both createSearchParamsCache (App Router) and createLoader (Pages Router) from nuqs/server.

import {
  createPreferencesSearchParams,
  createTimeframeSearchParams,
  groupByScope,
} from "@octopus-energy/measurements/storage/nuqs/server";

When returning a resolved Timeframe from getServerSideProps, serialize it with serializeTimeframe before passing it as a prop.

createTimeframeSearchParams

Creates a server-safe nuqs parser config for useTimeframe state. period and interval have stable parser defaults; date has no parser default. Resolve dynamic date defaults after parsing search params.

createTimeframeSearchParams

Prop

Type

Use the same stable parser defaults on the server and client when an omitted URL param should mean a custom app default.

createPreferencesSearchParams

Creates a server-safe nuqs parser config for usePreferences state.

createPreferencesSearchParams

Prop

Type

Shared parser default and option types are documented in nuqs Shared Types.

groupByScope

Reshapes a flat { "scope.field": value } object into a nested { scope: { field: value } } structure. Use this when server-side code parses scoped search params and needs to inspect each scope separately.

import { groupByScope } from "@octopus-energy/measurements/storage/nuqs/server";
groupByScope

Prop

Type

const cache = createSearchParamsCache(
  createTimeframeSearchParams({ scopes: ["electricity", "gas"] }),
);
const { electricity, gas } = groupByScope(await cache.parse(searchParams), ["electricity", "gas"]);

On the client, use createNuqsAdapter(state, setState, { scope }) for scoped read/write state. groupByScope is the server-side read-only counterpart.

Search params

ParamTypeDefaultDescription
period"day" | "week" | "month" | "year" | "custom""week"Selected timeframe period
dateYYYY-MM-DD calendar datenoneAnchor date, distinct from an ISO timestamp
interval"day" | "week" | "month""week"Custom range interval; preserved even when the current period is not custom
unit"energy" | "cost""energy"Display unit
standingChargebooleantrueShow standing charge line
taxbooleantrueInclude tax in cost values
view"chart" | "table""chart"Render mode

These defaults are package parser defaults. Custom stable parser defaults change what an omitted URL param means.


On this page