corebase 1.0.0__py3-none-any.whl

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.
Files changed (106) hide show
  1. corebase/__init__.py +108 -0
  2. corebase/_async/__init__.py +1 -0
  3. corebase/_async/auth_client.py +55 -0
  4. corebase/_async/client.py +398 -0
  5. corebase/_sync/__init__.py +1 -0
  6. corebase/_sync/auth_client.py +55 -0
  7. corebase/_sync/client.py +393 -0
  8. corebase/auth/__init__.py +20 -0
  9. corebase/auth/_async/__init__.py +1 -0
  10. corebase/auth/_async/gotrue_admin_api.py +356 -0
  11. corebase/auth/_async/gotrue_admin_mfa_api.py +32 -0
  12. corebase/auth/_async/gotrue_admin_oauth_api.py +93 -0
  13. corebase/auth/_async/gotrue_base_api.py +78 -0
  14. corebase/auth/_async/gotrue_client.py +1404 -0
  15. corebase/auth/_async/gotrue_mfa_api.py +94 -0
  16. corebase/auth/_async/storage.py +31 -0
  17. corebase/auth/_sync/__init__.py +1 -0
  18. corebase/auth/_sync/gotrue_admin_api.py +356 -0
  19. corebase/auth/_sync/gotrue_admin_mfa_api.py +32 -0
  20. corebase/auth/_sync/gotrue_admin_oauth_api.py +93 -0
  21. corebase/auth/_sync/gotrue_base_api.py +78 -0
  22. corebase/auth/_sync/gotrue_client.py +1394 -0
  23. corebase/auth/_sync/gotrue_mfa_api.py +94 -0
  24. corebase/auth/_sync/storage.py +31 -0
  25. corebase/auth/constants.py +15 -0
  26. corebase/auth/errors.py +259 -0
  27. corebase/auth/helpers.py +288 -0
  28. corebase/auth/py.typed +0 -0
  29. corebase/auth/timer.py +53 -0
  30. corebase/auth/types.py +1021 -0
  31. corebase/auth/version.py +1 -0
  32. corebase/client.py +12 -0
  33. corebase/functions/__init__.py +47 -0
  34. corebase/functions/_async/__init__.py +1 -0
  35. corebase/functions/_async/functions_client.py +218 -0
  36. corebase/functions/_sync/__init__.py +1 -0
  37. corebase/functions/_sync/functions_client.py +218 -0
  38. corebase/functions/errors.py +62 -0
  39. corebase/functions/py.typed +0 -0
  40. corebase/functions/utils.py +33 -0
  41. corebase/functions/version.py +1 -0
  42. corebase/lib/__init__.py +3 -0
  43. corebase/lib/client_options.py +189 -0
  44. corebase/migrate/__init__.py +374 -0
  45. corebase/migrate/__main__.py +7 -0
  46. corebase/postgrest/__init__.py +62 -0
  47. corebase/postgrest/_async/__init__.py +1 -0
  48. corebase/postgrest/_async/client.py +206 -0
  49. corebase/postgrest/_async/request_builder.py +503 -0
  50. corebase/postgrest/_sync/__init__.py +1 -0
  51. corebase/postgrest/_sync/client.py +206 -0
  52. corebase/postgrest/_sync/request_builder.py +503 -0
  53. corebase/postgrest/base_client.py +61 -0
  54. corebase/postgrest/base_request_builder.py +787 -0
  55. corebase/postgrest/constants.py +6 -0
  56. corebase/postgrest/exceptions.py +115 -0
  57. corebase/postgrest/py.typed +0 -0
  58. corebase/postgrest/types.py +72 -0
  59. corebase/postgrest/utils.py +91 -0
  60. corebase/postgrest/version.py +1 -0
  61. corebase/py.typed +0 -0
  62. corebase/realtime/__init__.py +17 -0
  63. corebase/realtime/_async/__init__.py +0 -0
  64. corebase/realtime/_async/channel.py +766 -0
  65. corebase/realtime/_async/client.py +498 -0
  66. corebase/realtime/_async/presence.py +185 -0
  67. corebase/realtime/_async/push.py +162 -0
  68. corebase/realtime/_async/timer.py +41 -0
  69. corebase/realtime/_sync/__init__.py +0 -0
  70. corebase/realtime/_sync/channel.py +30 -0
  71. corebase/realtime/_sync/client.py +71 -0
  72. corebase/realtime/_sync/presence.py +10 -0
  73. corebase/realtime/exceptions.py +38 -0
  74. corebase/realtime/message.py +176 -0
  75. corebase/realtime/py.typed +0 -0
  76. corebase/realtime/transformers.py +9 -0
  77. corebase/realtime/types.py +246 -0
  78. corebase/realtime/utils.py +5 -0
  79. corebase/realtime/version.py +1 -0
  80. corebase/storage/__init__.py +56 -0
  81. corebase/storage/_async/__init__.py +1 -0
  82. corebase/storage/_async/analytics.py +82 -0
  83. corebase/storage/_async/bucket.py +142 -0
  84. corebase/storage/_async/client.py +106 -0
  85. corebase/storage/_async/file_api.py +630 -0
  86. corebase/storage/_async/request.py +32 -0
  87. corebase/storage/_async/vectors.py +213 -0
  88. corebase/storage/_sync/__init__.py +1 -0
  89. corebase/storage/_sync/analytics.py +80 -0
  90. corebase/storage/_sync/bucket.py +142 -0
  91. corebase/storage/_sync/client.py +106 -0
  92. corebase/storage/_sync/file_api.py +630 -0
  93. corebase/storage/_sync/request.py +32 -0
  94. corebase/storage/_sync/vectors.py +199 -0
  95. corebase/storage/constants.py +16 -0
  96. corebase/storage/exceptions.py +84 -0
  97. corebase/storage/py.typed +0 -0
  98. corebase/storage/types.py +313 -0
  99. corebase/storage/utils.py +26 -0
  100. corebase/storage/version.py +1 -0
  101. corebase/types.py +8 -0
  102. corebase/version.py +1 -0
  103. corebase-1.0.0.dist-info/METADATA +78 -0
  104. corebase-1.0.0.dist-info/RECORD +106 -0
  105. corebase-1.0.0.dist-info/WHEEL +4 -0
  106. corebase-1.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,6 @@
1
+ DEFAULT_POSTGREST_CLIENT_HEADERS = {
2
+ "Accept": "application/json",
3
+ "Content-Type": "application/json",
4
+ }
5
+
6
+ DEFAULT_POSTGREST_CLIENT_TIMEOUT = 120
@@ -0,0 +1,115 @@
1
+ import re
2
+ from typing import Any
3
+
4
+ from httpx import Response
5
+ from pydantic import BaseModel
6
+
7
+
8
+ class APIErrorFromJSON(BaseModel):
9
+ """
10
+ A pydantic object to validate an error info object
11
+ from a json string.
12
+ """
13
+
14
+ message: str | None = None
15
+ """The error message."""
16
+ code: str | None = None
17
+ """The error code."""
18
+ hint: str | None = None
19
+ """The error hint."""
20
+ details: Any | None = None
21
+ """The error details."""
22
+
23
+
24
+ class APIError(Exception):
25
+ """
26
+ Base exception for all API errors.
27
+ """
28
+
29
+ _raw_error: dict[str, Any]
30
+ message: str | None
31
+ """The error message."""
32
+ code: str | None
33
+ """The error code."""
34
+ hint: str | None
35
+ """The error hint."""
36
+ details: Any | None
37
+ """The error details."""
38
+
39
+ def __init__(self, error: dict[str, Any]) -> None:
40
+ self._raw_error = error
41
+ self.message = error.get("message")
42
+ self.code = error.get("code")
43
+ self.hint = error.get("hint")
44
+ self.details = error.get("details")
45
+ Exception.__init__(self, str(self))
46
+
47
+ def __repr__(self) -> str:
48
+ error_text = f"Error {self.code}:" if self.code else ""
49
+ message_text = f"\nMessage: {self.message}" if self.message else ""
50
+ hint_text = f"\nHint: {self.hint}" if self.hint else ""
51
+ details_text = f"\nDetails: {self.details}" if self.details else ""
52
+ complete_error_text = f"{error_text}{message_text}{hint_text}{details_text}"
53
+ return complete_error_text or "Empty error"
54
+
55
+ def json(self) -> dict[str, Any]:
56
+ """Convert the error into a dictionary.
57
+
58
+ Returns:
59
+ :class:`dict`
60
+ """
61
+ return self._raw_error
62
+
63
+
64
+ def _split_outside_quotes(value: str, separator: str) -> list[str]:
65
+ parts: list[str] = []
66
+ current: list[str] = []
67
+ in_quotes = False
68
+ escaped = False
69
+ for char in value:
70
+ if escaped:
71
+ escaped = False
72
+ elif in_quotes and char == "\\":
73
+ escaped = True
74
+ elif char == '"':
75
+ in_quotes = not in_quotes
76
+ elif char == separator and not in_quotes:
77
+ parts.append("".join(current))
78
+ current = []
79
+ continue
80
+ current.append(char)
81
+ parts.append("".join(current))
82
+ return parts
83
+
84
+
85
+ def _unquote(value: str) -> str:
86
+ value = value.strip()
87
+ if len(value) >= 2 and value[0] == value[-1] == '"':
88
+ return re.sub(r"\\(.)", r"\1", value[1:-1])
89
+ return value
90
+
91
+
92
+ def _proxy_status_error_code(r: Response) -> str | None:
93
+ proxy_status: str = r.headers.get("Proxy-Status", "")
94
+ for member in _split_outside_quotes(proxy_status, ","):
95
+ name, *params = _split_outside_quotes(member, ";")
96
+ if _unquote(name).lower() != "postgrest":
97
+ continue
98
+ for param in params:
99
+ key, _, value = param.partition("=")
100
+ if key.strip() == "error":
101
+ return _unquote(value) or None
102
+ return None
103
+ return None
104
+
105
+
106
+ def generate_default_error_message(r: Response) -> dict[str, Any]:
107
+ # Error bodies that are missing (HEAD) or not PostgREST JSON (for example
108
+ # a proxy error page) do not carry the error code, so read it from the
109
+ # Proxy-Status header when PostgREST set it.
110
+ return {
111
+ "message": r.reason_phrase or f"Request failed with status {r.status_code}",
112
+ "code": _proxy_status_error_code(r) or str(r.status_code),
113
+ "hint": None,
114
+ "details": r.text or None,
115
+ }
File without changes
@@ -0,0 +1,72 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping, Sequence
4
+ from enum import StrEnum
5
+
6
+ from typing_extensions import TypeAliasType
7
+
8
+ # https://docs.pydantic.dev/2.11/concepts/types/#named-recursive-types
9
+ JSON = TypeAliasType(
10
+ "JSON", "None | bool | str | int | float | Sequence[JSON] | Mapping[str, JSON]"
11
+ )
12
+
13
+ # Type checkers only treat a TypedDict as Mapping[str, object], so generated
14
+ # Insert and Update TypedDicts need it to be accepted as a body.
15
+ RequestBody = TypeAliasType(
16
+ "RequestBody", "JSON | Mapping[str, object] | Sequence[Mapping[str, object]]"
17
+ )
18
+
19
+ # A scalar value accepted by PostgREST filter operators. Used instead of ``Any``
20
+ # so the accepted types are explicit; values are still coerced to ``str`` when
21
+ # serialized into the query string.
22
+ FilterValue = str | int | float | bool
23
+
24
+
25
+ class CountMethod(StrEnum):
26
+ exact = "exact"
27
+ planned = "planned"
28
+ estimated = "estimated"
29
+
30
+
31
+ class Filters(StrEnum):
32
+ NOT = "not"
33
+ EQ = "eq"
34
+ NEQ = "neq"
35
+ GT = "gt"
36
+ GTE = "gte"
37
+ LT = "lt"
38
+ LTE = "lte"
39
+ IS = "is"
40
+ LIKE = "like"
41
+ LIKE_ALL = "like(all)"
42
+ LIKE_ANY = "like(any)"
43
+ ILIKE = "ilike"
44
+ ILIKE_ALL = "ilike(all)"
45
+ ILIKE_ANY = "ilike(any)"
46
+ FTS = "fts"
47
+ PLFTS = "plfts"
48
+ PHFTS = "phfts"
49
+ WFTS = "wfts"
50
+ IN = "in"
51
+ CS = "cs"
52
+ CD = "cd"
53
+ OV = "ov"
54
+ SL = "sl"
55
+ SR = "sr"
56
+ NXL = "nxl"
57
+ NXR = "nxr"
58
+ ADJ = "adj"
59
+
60
+
61
+ class RequestMethod(StrEnum):
62
+ GET = "GET"
63
+ POST = "POST"
64
+ PATCH = "PATCH"
65
+ PUT = "PUT"
66
+ DELETE = "DELETE"
67
+ HEAD = "HEAD"
68
+
69
+
70
+ class ReturnMethod(StrEnum):
71
+ minimal = "minimal"
72
+ representation = "representation"
@@ -0,0 +1,91 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from collections.abc import Iterable
5
+ from typing import Any
6
+
7
+ from deprecation import deprecated
8
+ from httpx import AsyncClient # noqa: F401
9
+ from httpx import Client as BaseClient
10
+ from yarl import URL
11
+
12
+ from .version import __version__
13
+
14
+
15
+ class SyncClient(BaseClient):
16
+ @deprecated(
17
+ "1.0.2", "3.0.0", __version__, "Use `Client` from the httpx package instead"
18
+ )
19
+ def __init__(self, *args, **kwargs) -> None:
20
+ super().__init__(*args, **kwargs)
21
+
22
+ @deprecated(
23
+ "1.0.2",
24
+ "3.0.0",
25
+ __version__,
26
+ "Use `close` method from `Client` in the httpx package instead",
27
+ )
28
+ def aclose(self) -> None:
29
+ self.close()
30
+
31
+
32
+ def _quote(value: Any) -> str:
33
+ escaped = str(value).replace("\\", "\\\\").replace('"', '\\"')
34
+ return f'"{escaped}"'
35
+
36
+
37
+ def sanitize_param(param: Any) -> str:
38
+ param_str = str(param)
39
+ reserved_chars = ',:()"\\'
40
+ if any(char in param_str for char in reserved_chars):
41
+ return _quote(param_str)
42
+ return param_str
43
+
44
+
45
+ def sanitize_array_element(element: Any) -> str:
46
+ """Quote a single value for use inside a PostgreSQL array literal ``{...}``.
47
+
48
+ PostgreSQL quotes an array element when it is empty, matches ``NULL``
49
+ case-insensitively, or contains a brace, the comma delimiter, a double
50
+ quote, a backslash, or whitespace; embedded double quotes and backslashes
51
+ are backslash-escaped. Without this, a value such as ``"a,b"`` is emitted
52
+ bare and parsed by PostgREST as two separate elements. ``None`` becomes an
53
+ unquoted ``NULL`` element.
54
+ """
55
+ if element is None:
56
+ return "NULL"
57
+ element_str = str(element)
58
+ needs_quoting = (
59
+ element_str == ""
60
+ or element_str.lower() == "null"
61
+ or any(char in element_str for char in '{},"\\')
62
+ or any(char.isspace() for char in element_str)
63
+ )
64
+ if not needs_quoting:
65
+ return element_str
66
+ return _quote(element_str)
67
+
68
+
69
+ def sanitize_array_param(values: Iterable[Any]) -> str:
70
+ """Render an iterable as a PostgreSQL array literal ``{elem,elem,...}``,
71
+ quoting each element as needed so values containing the comma delimiter (or
72
+ other special characters) survive as single elements."""
73
+ return f"{{{','.join(sanitize_array_element(value) for value in values)}}}"
74
+
75
+
76
+ def rpc_query_param(value: Any) -> Any:
77
+ """Format an RPC argument sent in the query string, as in GET or HEAD calls.
78
+
79
+ Lists and tuples become PostgreSQL array literals, since PostgREST keeps only
80
+ one value when a non-variadic argument is repeated. Dictionaries become JSON
81
+ for named json/jsonb arguments.
82
+ """
83
+ if isinstance(value, (list, tuple)):
84
+ return sanitize_array_param(value)
85
+ if isinstance(value, dict):
86
+ return json.dumps(value, separators=(",", ":"))
87
+ return value
88
+
89
+
90
+ def is_http_url(url: URL) -> bool:
91
+ return url.scheme in {"https", "http"}
@@ -0,0 +1 @@
1
+ __version__ = "1.0.0" # {x-release-please-version}
corebase/py.typed ADDED
File without changes
@@ -0,0 +1,17 @@
1
+ import logging
2
+
3
+ # Configure the root logger for the module
4
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
5
+
6
+ from corebase.realtime.version import __version__ as __version__
7
+
8
+ from ._async.channel import AsyncRealtimeChannel as AsyncRealtimeChannel
9
+ from ._async.client import AsyncRealtimeClient as AsyncRealtimeClient
10
+ from ._async.presence import AsyncRealtimePresence as AsyncRealtimePresence
11
+ from ._sync.channel import SyncRealtimeChannel as SyncRealtimeChannel
12
+ from ._sync.client import SyncRealtimeClient as SyncRealtimeClient
13
+ from ._sync.presence import SyncRealtimePresence as SyncRealtimePresence
14
+ from .exceptions import *
15
+ from .message import *
16
+ from .transformers import *
17
+ from .types import *
File without changes