Liking cljdoc? Tell your friends :D

supabase.core.client

Client configuration for interacting with Supabase.

Creates and manages immutable client maps containing connection options, service URLs, and configuration for your Supabase project. The client is a plain Clojure map validated with Malli schemas.

Usage

(require '[supabase.core.client :as client])

;; Create a client with defaults
(client/make-client "https://abc.supabase.co" "my-api-key")

;; Create a client with options
(client/make-client "https://abc.supabase.co" "my-api-key"
  :db {:schema "another"}
  :auth {:flow-type "pkce"}
  :global {:headers {"custom-header" "custom-value"}})

;; Update the access token for authenticated requests
(client/update-access-token client "new-token")

Client Map Structure

{:base-url       "https://abc.supabase.co"
 :api-key        "my-api-key"
 :access-token   "my-api-key"
 :auth-url       "https://abc.supabase.co/auth/v1"
 :database-url   "https://abc.supabase.co/rest/v1"
 :storage-url    "https://abc.supabase.co/storage/v1"
 :functions-url  "https://abc.supabase.co/functions/v1"
 :realtime-url   "https://abc.supabase.co/realtime/v1"
 :db             {:schema "public"}
 :client-info    {"supabase-clj" "0.7.0"}
 :global         {:headers {}}
 :auth           {:auto-refresh-token true, :flow-type "implicit", ...}
 :storage        {:use-new-hostname false}}

The :client-info map is rendered into the structured x-client-info header on every request (see format-client-info). Service modules register themselves via with-client-info.

See https://supabase.com/docs/reference/javascript/initializing

Client configuration for interacting with Supabase.

Creates and manages immutable client maps containing connection options,
service URLs, and configuration for your Supabase project. The client is
a plain Clojure map validated with Malli schemas.

## Usage

    (require '[supabase.core.client :as client])

    ;; Create a client with defaults
    (client/make-client "https://abc.supabase.co" "my-api-key")

    ;; Create a client with options
    (client/make-client "https://abc.supabase.co" "my-api-key"
      :db {:schema "another"}
      :auth {:flow-type "pkce"}
      :global {:headers {"custom-header" "custom-value"}})

    ;; Update the access token for authenticated requests
    (client/update-access-token client "new-token")

## Client Map Structure

    {:base-url       "https://abc.supabase.co"
     :api-key        "my-api-key"
     :access-token   "my-api-key"
     :auth-url       "https://abc.supabase.co/auth/v1"
     :database-url   "https://abc.supabase.co/rest/v1"
     :storage-url    "https://abc.supabase.co/storage/v1"
     :functions-url  "https://abc.supabase.co/functions/v1"
     :realtime-url   "https://abc.supabase.co/realtime/v1"
     :db             {:schema "public"}
     :client-info    {"supabase-clj" "0.7.0"}
     :global         {:headers {}}
     :auth           {:auto-refresh-token true, :flow-type "implicit", ...}
     :storage        {:use-new-hostname false}}

The `:client-info` map is rendered into the structured `x-client-info`
header on every request (see [[format-client-info]]). Service modules
register themselves via [[with-client-info]].

See https://supabase.com/docs/reference/javascript/initializing
raw docstring

Authclj/s

Schema for auth configuration options.

Schema for auth configuration options.
sourceraw docstring

Clientclj/s

Schema for the full Supabase client map.

Schema for the full Supabase client map.
sourceraw docstring

Databaseclj/s

Schema for database configuration. Defaults to the "public" schema.

Schema for database configuration. Defaults to the `"public"` schema.
sourceraw docstring

ensure-clientclj/s

(ensure-client client)

Returns nil if client matches the Client schema, otherwise an anomaly.

Returns nil if `client` matches the Client schema, otherwise an anomaly.
sourceraw docstring

flow-typeclj/s

Schema for supported auth flow types.

Schema for supported auth flow types.
sourceraw docstring

format-client-infoclj/s

(format-client-info client-info)

Renders a client-info map of module name to version into the structured x-client-info header value: entries sorted by name, joined as "name/version; name/version".

(format-client-info {"supabase-clj" "0.7.0"
                     "supabase-clj-postgrest" "1.3.0"})
;; => "supabase-clj/0.7.0; supabase-clj-postgrest/1.3.0"
Renders a client-info map of module name to version into the structured
`x-client-info` header value: entries sorted by name, joined as
`"name/version; name/version"`.

    (format-client-info {"supabase-clj" "0.7.0"
                         "supabase-clj-postgrest" "1.3.0"})
    ;; => "supabase-clj/0.7.0; supabase-clj-postgrest/1.3.0"
sourceraw docstring

Globalclj/s

Schema for global client options, including default HTTP headers.

Schema for global client options, including default HTTP headers.
sourceraw docstring

make-clientclj/s

(make-client base-url api-key & {:as opts})

Creates a new Supabase client map from a base URL and API key.

The client is a plain immutable map containing all configuration needed to interact with Supabase services. Service URLs are derived from base-url. By default, the access-token is set to the api-key.

Returns the client map on success, or an anomaly map on validation failure.

Options (keyword args)

  • :access-token — override the default access token (defaults to api-key)
  • :db — database options, e.g. {:schema "another"}
  • :global — global options, e.g. {:headers {"x-custom" "val"}}
  • :auth — auth options, e.g. {:flow-type "pkce"}
  • :storage — storage options, e.g. {:use-new-hostname true}
  • :pool — transport pool options (connect-timeout, version, redirect-policy, ...). Builds a dedicated HTTP client used for every request from this client. JVM only; ignored on ClojureScript.
  • :transport — pre-built supabase.core.transport/Transport. Overrides :pool if both are given.
  • :log? — when true, request/response logging is enabled for every request issued via this client.
  • :client-info — map of module name to version, merged over the default {"supabase-clj" "<core-version>"} and rendered as the structured x-client-info header.
  • :retries — retry policy for transient failures: true for defaults, an integer max-attempts, or an options map (:max-attempts, :initial-delay-ms, :max-delay-ms, :multiplier). Absent means no retries. Overridable per request.
  • :on-event — 1-arg fn invoked with telemetry event maps (:request-start, :request-end, :request-retry). Handler exceptions are logged and swallowed. Overridable per request.

Examples

(make-client "https://abc.supabase.co" "my-key")

(make-client "https://abc.supabase.co" "my-key"
  :db {:schema "private"}
  :auth {:flow-type "pkce" :debug true})
Creates a new Supabase client map from a base URL and API key.

The client is a plain immutable map containing all configuration needed to
interact with Supabase services. Service URLs are derived from `base-url`.
By default, the `access-token` is set to the `api-key`.

Returns the client map on success, or an anomaly map on validation failure.

## Options (keyword args)

  - `:access-token`  — override the default access token (defaults to `api-key`)
  - `:db`            — database options, e.g. `{:schema "another"}`
  - `:global`        — global options, e.g. `{:headers {"x-custom" "val"}}`
  - `:auth`          — auth options, e.g. `{:flow-type "pkce"}`
  - `:storage`       — storage options, e.g. `{:use-new-hostname true}`
  - `:pool`          — transport pool options (connect-timeout, version,
                       redirect-policy, ...). Builds a dedicated HTTP
                       client used for every request from this client.
                       JVM only; ignored on ClojureScript.
  - `:transport`     — pre-built `supabase.core.transport/Transport`.
                       Overrides `:pool` if both are given.
  - `:log?`          — when true, request/response logging is enabled
                       for every request issued via this client.
  - `:client-info`   — map of module name to version, merged over the
                       default `{"supabase-clj" "<core-version>"}` and
                       rendered as the structured `x-client-info` header.
  - `:retries`       — retry policy for transient failures: `true` for
                       defaults, an integer max-attempts, or an options
                       map (`:max-attempts`, `:initial-delay-ms`,
                       `:max-delay-ms`, `:multiplier`). Absent means no
                       retries. Overridable per request.
  - `:on-event`      — 1-arg fn invoked with telemetry event maps
                       (`:request-start`, `:request-end`,
                       `:request-retry`). Handler exceptions are logged
                       and swallowed. Overridable per request.

## Examples

    (make-client "https://abc.supabase.co" "my-key")

    (make-client "https://abc.supabase.co" "my-key"
      :db {:schema "private"}
      :auth {:flow-type "pkce" :debug true})
sourceraw docstring

Poolclj/s

Schema for HTTP transport pool options (JVM only). See supabase.core.transport/build-http-client for the full key set.

Schema for HTTP transport pool options (JVM only). See
`supabase.core.transport/build-http-client` for the full key set.
sourceraw docstring

Retriesclj/s

Schema for the :retries client option: true for defaults, an integer max-attempts, or a full options map. Absent means retries disabled.

Schema for the `:retries` client option: `true` for defaults, an integer
max-attempts, or a full options map. Absent means retries disabled.
sourceraw docstring

RetryOptsclj/s

Schema for retry policy options. Resolution rules live in supabase.core.retry/merge-opts.

Schema for retry policy options. Resolution rules live in
`supabase.core.retry/merge-opts`.
sourceraw docstring

Storageclj/s

Schema for storage configuration options.

Schema for storage configuration options.
sourceraw docstring

transform-storage-urlclj/s

(transform-storage-url storage-url)

Transforms a storage URL to use the storage subdomain for official Supabase domains.

Official domains (.supabase.co, .supabase.in, .supabase.red) are rewritten to route through storage.supabase.*. Custom domains, localhost, IPs, and URLs already using the storage subdomain are returned unchanged.

(transform-storage-url "https://abc.supabase.co/storage/v1")
;; => "https://abc.storage.supabase.co/storage/v1"

(transform-storage-url "https://custom.example.com/storage/v1")
;; => "https://custom.example.com/storage/v1"
Transforms a storage URL to use the storage subdomain for official Supabase domains.

Official domains (`.supabase.co`, `.supabase.in`, `.supabase.red`) are rewritten
to route through `storage.supabase.*`. Custom domains, localhost, IPs, and URLs
already using the storage subdomain are returned unchanged.

    (transform-storage-url "https://abc.supabase.co/storage/v1")
    ;; => "https://abc.storage.supabase.co/storage/v1"

    (transform-storage-url "https://custom.example.com/storage/v1")
    ;; => "https://custom.example.com/storage/v1"
sourceraw docstring

update-access-tokenclj/s

(update-access-token client access-token)

Returns a new client with the given access-token swapped in.

Returns an anomaly map if client is not a valid client map.

(update-access-token client "new-jwt-token")
Returns a new client with the given `access-token` swapped in.

Returns an anomaly map if `client` is not a valid client map.

    (update-access-token client "new-jwt-token")
sourceraw docstring

with-client-infoclj/s

(with-client-info client name version)

Returns a new client with module name at version registered in the structured x-client-info header. Service modules call this on the client before issuing requests so the header identifies every SDK layer in use.

(-> client
    (client/with-client-info "supabase-clj-postgrest" "1.3.0"))
Returns a new client with module `name` at `version` registered in the
structured `x-client-info` header. Service modules call this on the client
before issuing requests so the header identifies every SDK layer in use.

    (-> client
        (client/with-client-info "supabase-clj-postgrest" "1.3.0"))
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close