Skip to content

Commit 31ca8d2

Browse files
authored
Merge pull request #179 from supabase-community/j0_add_magic
feat: Add functions
2 parents 0fdb70d + 47ac882 commit 31ca8d2

File tree

7 files changed

+147
-120
lines changed

7 files changed

+147
-120
lines changed

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
]
3636

3737
- repo: https://github.com/psf/black
38-
rev: "22.3.0"
38+
rev: "22.10.0"
3939
hooks:
4040
- id: black
4141

Diff for: examples/.gitkeep

Whitespace-only changes.

Diff for: poetry.lock

+117-102
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ realtime = "^0.0.5"
2121
gotrue = "^0.5.0"
2222
httpx = "^0.21.3"
2323
storage3 = "^0.3.4"
24+
supafunc = "^0.2.0"
2425
python-semantic-release = "7.32.1"
2526

2627
[tool.poetry.dev-dependencies]
2728
pre-commit = "^2.19.0"
2829
black = "^22.10"
2930
pytest = "^7.1.2"
3031
flake8 = "^5.0.4"
31-
isort = "^5.9.3"
32+
isort = "^5.10.1"
3233
pytest-cov = "^4.0.0"
3334
commitizen = "^2.35.0"
3435
python-semantic-release = "^7.32.1"

Diff for: supabase/client.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import re
12
from typing import Any, Dict, Union
23

34
from httpx import Timeout
45
from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder
56
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
7+
from supafunc import FunctionsClient
68

79
from .lib.auth_client import SupabaseAuthClient
810
from .lib.client_options import ClientOptions
@@ -42,6 +44,15 @@ def __init__(
4244
self.realtime_url: str = f"{supabase_url}/realtime/v1".replace("http", "ws")
4345
self.auth_url: str = f"{supabase_url}/auth/v1"
4446
self.storage_url = f"{supabase_url}/storage/v1"
47+
is_platform = re.search(r"(supabase\.co)|(supabase\.in)", supabase_url)
48+
if is_platform:
49+
url_parts = supabase_url.split(".")
50+
self.functions_url = (
51+
f"{url_parts[0]}.functions.{url_parts[1]}.{url_parts[2]}"
52+
)
53+
54+
else:
55+
self.functions_url = f"{supabase_url}/functions/v1"
4556
self.schema: str = options.schema
4657

4758
# Instantiate clients.
@@ -63,6 +74,9 @@ def __init__(
6374
schema=options.schema,
6475
)
6576

77+
def functions(self) -> FunctionsClient:
78+
return FunctionsClient(self.functions_url, self._get_auth_headers())
79+
6680
def storage(self) -> SupabaseStorageClient:
6781
"""Create instance of the storage client"""
6882
return SupabaseStorageClient(self.storage_url, self._get_auth_headers())

Diff for: tests/test_dummy.py

-16
This file was deleted.

Diff for: tests/test_function_configuration.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import supabase
2+
3+
4+
def test_functions_client_initialization() -> None:
5+
ref = "ooqqmozurnggtljmjkii"
6+
url = f"https://{ref}.supabase.co"
7+
sp = supabase.Client(url, "testkey")
8+
func = sp.functions()
9+
assert sp.functions_url == f"https://{ref}.functions.supabase.co"
10+
11+
url = "https://localhost:54322"
12+
sp_local = supabase.Client(url, "testkey")
13+
assert sp_local.functions_url == f"{url}/functions/v1"

0 commit comments

Comments
 (0)