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
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"
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"