supabase_functions 2.21.1__tar.gz → 2.22.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: supabase-functions
3
- Version: 2.21.1
3
+ Version: 2.22.0
4
4
  Summary: Library for Supabase Functions
5
5
  Author: Joel Lee, Andrew Smith
6
6
  Author-email: Joel Lee <joel@joellee.org>, Andrew Smith <a.smith@silentworks.co.uk>
7
7
  License-Expression: MIT
8
8
  Requires-Dist: httpx[http2]>=0.26,<0.29
9
9
  Requires-Dist: strenum>=0.4.15
10
+ Requires-Dist: yarl>=1.20.1
10
11
  Maintainer: Leonardo Santiago
11
12
  Maintainer-email: Leonardo Santiago <leonardo.santiago@supabase.io>
12
13
  Requires-Python: >=3.9
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "supabase_functions"
3
- version = "2.21.1" # {x-release-please-version}
3
+ version = "2.22.0" # {x-release-please-version}
4
4
  description = "Library for Supabase Functions"
5
5
  authors = [
6
6
  { name = "Joel Lee", email = "joel@joellee.org" },
@@ -15,6 +15,7 @@ requires-python = ">=3.9"
15
15
  dependencies = [
16
16
  "httpx[http2] >=0.26,<0.29",
17
17
  "strenum >=0.4.15",
18
+ "yarl>=1.20.1",
18
19
  ]
19
20
 
20
21
 
@@ -2,6 +2,7 @@ from typing import Any, Dict, Literal, Optional, Union
2
2
  from warnings import warn
3
3
 
4
4
  from httpx import AsyncClient, HTTPError, Response, QueryParams
5
+ from yarl import URL
5
6
 
6
7
  from ..errors import FunctionsHttpError, FunctionsRelayError
7
8
  from ..utils import (
@@ -24,7 +25,7 @@ class AsyncFunctionsClient:
24
25
  ):
25
26
  if not is_http_url(url):
26
27
  raise ValueError("url must be a valid HTTP URL string")
27
- self.url = url
28
+ self.url = URL(url)
28
29
  self.headers = {
29
30
  "User-Agent": f"supabase-py/functions-py v{__version__}",
30
31
  **headers,
@@ -51,37 +52,32 @@ class AsyncFunctionsClient:
51
52
 
52
53
  self.verify = bool(verify) if verify is not None else True
53
54
  self.timeout = int(abs(timeout)) if timeout is not None else 60
54
-
55
- if http_client is not None:
56
- http_client.base_url = self.url
57
- http_client.headers.update({**self.headers})
58
- self._client = http_client
59
- else:
60
- self._client = AsyncClient(
61
- base_url=self.url,
62
- headers=self.headers,
63
- verify=self.verify,
64
- timeout=self.timeout,
65
- proxy=proxy,
66
- follow_redirects=True,
67
- http2=True,
68
- )
55
+ self._client = http_client or AsyncClient(
56
+ verify=self.verify,
57
+ timeout=self.timeout,
58
+ proxy=proxy,
59
+ follow_redirects=True,
60
+ http2=True,
61
+ )
69
62
 
70
63
  async def _request(
71
64
  self,
72
65
  method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"],
73
- url: str,
66
+ path: list[str],
74
67
  headers: Optional[Dict[str, str]] = None,
75
68
  json: Optional[Dict[Any, Any]] = None,
76
69
  params: Optional[QueryParams] = None,
77
70
  ) -> Response:
71
+ url = self.url.joinpath(*path)
72
+ headers = headers or dict()
73
+ headers.update(self.headers)
78
74
  response = (
79
75
  await self._client.request(
80
- method, url, data=json, headers=headers, params=params
76
+ method, str(url), data=json, headers=headers, params=params
81
77
  )
82
78
  if isinstance(json, str)
83
79
  else await self._client.request(
84
- method, url, json=json, headers=headers, params=params
80
+ method, str(url), json=json, headers=headers, params=params
85
81
  )
86
82
  )
87
83
  try:
@@ -129,7 +125,6 @@ class AsyncFunctionsClient:
129
125
  params = QueryParams()
130
126
  body = None
131
127
  response_type = "text/plain"
132
- url = f"{self.url}/{function_name}"
133
128
 
134
129
  if invoke_options is not None:
135
130
  headers.update(invoke_options.get("headers", {}))
@@ -153,7 +148,7 @@ class AsyncFunctionsClient:
153
148
  headers["Content-Type"] = "application/json"
154
149
 
155
150
  response = await self._request(
156
- "POST", url, headers=headers, json=body, params=params
151
+ "POST", [function_name], headers=headers, json=body, params=params
157
152
  )
158
153
  is_relay_error = response.headers.get("x-relay-header")
159
154
 
@@ -2,6 +2,7 @@ from typing import Any, Dict, Literal, Optional, Union
2
2
  from warnings import warn
3
3
 
4
4
  from httpx import Client, HTTPError, Response, QueryParams
5
+ from yarl import URL
5
6
 
6
7
  from ..errors import FunctionsHttpError, FunctionsRelayError
7
8
  from ..utils import (
@@ -24,7 +25,7 @@ class SyncFunctionsClient:
24
25
  ):
25
26
  if not is_http_url(url):
26
27
  raise ValueError("url must be a valid HTTP URL string")
27
- self.url = url
28
+ self.url = URL(url)
28
29
  self.headers = {
29
30
  "User-Agent": f"supabase-py/functions-py v{__version__}",
30
31
  **headers,
@@ -51,35 +52,32 @@ class SyncFunctionsClient:
51
52
 
52
53
  self.verify = bool(verify) if verify is not None else True
53
54
  self.timeout = int(abs(timeout)) if timeout is not None else 60
54
-
55
- if http_client is not None:
56
- http_client.base_url = self.url
57
- http_client.headers.update({**self.headers})
58
- self._client = http_client
59
- else:
60
- self._client = Client(
61
- base_url=self.url,
62
- headers=self.headers,
63
- verify=self.verify,
64
- timeout=self.timeout,
65
- proxy=proxy,
66
- follow_redirects=True,
67
- http2=True,
68
- )
55
+ self._client = http_client or Client(
56
+ verify=self.verify,
57
+ timeout=self.timeout,
58
+ proxy=proxy,
59
+ follow_redirects=True,
60
+ http2=True,
61
+ )
69
62
 
70
63
  def _request(
71
64
  self,
72
65
  method: Literal["GET", "OPTIONS", "HEAD", "POST", "PUT", "PATCH", "DELETE"],
73
- url: str,
66
+ path: list[str],
74
67
  headers: Optional[Dict[str, str]] = None,
75
68
  json: Optional[Dict[Any, Any]] = None,
76
69
  params: Optional[QueryParams] = None,
77
70
  ) -> Response:
71
+ url = self.url.joinpath(*path)
72
+ headers = headers or dict()
73
+ headers.update(self.headers)
78
74
  response = (
79
- self._client.request(method, url, data=json, headers=headers, params=params)
75
+ self._client.request(
76
+ method, str(url), data=json, headers=headers, params=params
77
+ )
80
78
  if isinstance(json, str)
81
79
  else self._client.request(
82
- method, url, json=json, headers=headers, params=params
80
+ method, str(url), json=json, headers=headers, params=params
83
81
  )
84
82
  )
85
83
  try:
@@ -127,7 +125,6 @@ class SyncFunctionsClient:
127
125
  params = QueryParams()
128
126
  body = None
129
127
  response_type = "text/plain"
130
- url = f"{self.url}/{function_name}"
131
128
 
132
129
  if invoke_options is not None:
133
130
  headers.update(invoke_options.get("headers", {}))
@@ -150,7 +147,9 @@ class SyncFunctionsClient:
150
147
  elif isinstance(body, dict):
151
148
  headers["Content-Type"] = "application/json"
152
149
 
153
- response = self._request("POST", url, headers=headers, json=body, params=params)
150
+ response = self._request(
151
+ "POST", [function_name], headers=headers, json=body, params=params
152
+ )
154
153
  is_relay_error = response.headers.get("x-relay-header")
155
154
 
156
155
  if is_relay_error and is_relay_error == "true":
@@ -0,0 +1 @@
1
+ __version__ = "2.22.0" # {x-release-please-version}
@@ -1 +0,0 @@
1
- __version__ = "2.21.1" # {x-release-please-version}