Electric.Client.ShapeKey (Electric Client v0.10.2)

Copy Markdown View Source

Generate canonical shape keys for cache lookup.

The canonical shape key is a stable identifier for a shape definition that excludes Electric protocol parameters (like cursor, handle, offset, etc.). This allows the client to identify when different requests are for the same underlying shape, which is useful for cache busting when CDN/proxy caches serve stale responses.

Summary

Functions

Generate a canonical shape key from a URI.

Generate a canonical shape key from an endpoint URI and params map.

Functions

canonical(uri)

@spec canonical(URI.t()) :: String.t()

Generate a canonical shape key from a URI.

Extracts query parameters, filters out Electric protocol parameters, sorts the remaining parameters alphabetically, and returns a canonical URL string.

Examples

iex> uri = URI.parse("http://localhost:3000/v1/shape?table=items&cursor=123&offset=0_0")
iex> ShapeKey.canonical(uri)
"http://localhost:3000/v1/shape?table=items"

canonical(endpoint, params)

@spec canonical(URI.t(), map()) :: String.t()

Generate a canonical shape key from an endpoint URI and params map.

Examples

iex> endpoint = URI.parse("http://localhost:3000/v1/shape")
iex> params = %{"table" => "items", "where" => "id > 0", "offset" => "0_0"}
iex> ShapeKey.canonical(endpoint, params)
"http://localhost:3000/v1/shape?table=items&where=id%20%3E%200"