Skip to content

QueryAdapter @vuqs/core ​

The contract every adapter satisfies.

Usage ​

ts
import type { ParsedQuery, QueryAdapter } from '@vuqs/core'
import { shallowRef } from 'vue'

const query = shallowRef<ParsedQuery>({})
const adapter: QueryAdapter = {
  query,
  navigate(next) {
    query.value = next
  },
}

Type ​

ts
interface QueryAdapter {
  debugName?: string
  query: MaybeRefOrGetter<ParsedQuery>
  navigate: QueryStateNavigate
  defaultOptions?: QueryAdapterDefaultOptions
}

Properties ​

PropertyTypeDescription
debugNamestringOptional adapter identity used by opt-in diagnostics.
queryMaybeRefOrGetter<ParsedQuery>The current parsed query, as a ref, getter, or plain value.
navigateQueryStateNavigateApplies the next query. On completion, query exposes the final state, including normalization and redirects. Returns void or Promise<void>; throws or rejects on failure or cancellation.
defaultOptionsQueryAdapterDefaultOptionsOptional adapter defaults at the bottom of the precedence chain.

Adapter object identity defines a runtime boundary. Bindings using the same adapter share one optimistic overlay, write queue, and transaction-start registry. Bindings using different adapter objects are isolated, even when their query paths overlap.

The queue removes only the versions belonging to a completed attempt. A later write to the same path remains pending, even when it has the same value. A rejected promise or a synchronous error rolls back the attempt's current versions.

QueryAdapterDefaultOptions ​

Defaults an adapter applies to every write. Extends NavigateOptions.

ts
interface QueryAdapterDefaultOptions extends NavigateOptions {
  throttleMs?: number
  clearOnDefault?: boolean
}

Properties ​

PropertyTypeDescription
history'replace' | 'push'Optional. Push a history entry or replace the current one.
scrollboolean | ScrollToOptionsOptional. Where the window scrolls after navigation, forwarded to the adapter.
throttleMsnumberOptional. Coalesce writes within this many milliseconds.
clearOnDefaultbooleanOptional. Drop a value from the URL when it equals its resolved default.

See Navigation & options for how these compose with per-instance and per-call options.

ts
interface NavigateOptions {
  history?: 'replace' | 'push'
  scroll?: boolean | ScrollToOptions
}

QueryStateNavigate ​

ts
type QueryStateNavigate = (query: ParsedQueryRaw, options: NavigateOptions) => void | Promise<void>

Bring your own adapter.

Released under the MIT License. Inspired by nuqs.