dex-connector-supabase 0.1.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.
- dex_connector_supabase-0.1.0/.gitignore +6 -0
- dex_connector_supabase-0.1.0/PKG-INFO +57 -0
- dex_connector_supabase-0.1.0/README.md +46 -0
- dex_connector_supabase-0.1.0/examples/sample_supabase/__init__.py +3 -0
- dex_connector_supabase-0.1.0/examples/sample_supabase/flow.py +79 -0
- dex_connector_supabase-0.1.0/examples/sample_supabase/worker.py +51 -0
- dex_connector_supabase-0.1.0/pyproject.toml +37 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/__init__.py +50 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/_generated/__init__.py +2 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/_generated/config.py +25 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/_generated/connection.py +139 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/_generated/definitions.py +55 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/_generated/mock.py +107 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/_generated/models.py +68 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/_generated/steps.py +131 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/client.py +387 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/connection.py +49 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/dex-connector.json +77 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/models.py +32 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/py.typed +0 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/steps.py +36 -0
- dex_connector_supabase-0.1.0/src/dex_connectors/supabase/supabasemock/__init__.py +53 -0
- dex_connector_supabase-0.1.0/tests/test_conformance.py +33 -0
- dex_connector_supabase-0.1.0/tests/test_manifest_contract.py +15 -0
- dex_connector_supabase-0.1.0/tests/test_operations.py +218 -0
- dex_connector_supabase-0.1.0/uv.lock +932 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-supabase
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Supabase connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: dex-connectors-sdk==0.1.0
|
|
8
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
9
|
+
Requires-Dist: httpx>=0.27
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# Supabase connector for Python
|
|
13
|
+
|
|
14
|
+
Install with `pip install dex-connector-supabase==0.1.0`. The package requires
|
|
15
|
+
`dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`, and implements the
|
|
16
|
+
manifest operations `selectRows` (Query) and `upsertRows` (Mutation) with the
|
|
17
|
+
same branches, defaults, and failure classification as the Go module.
|
|
18
|
+
|
|
19
|
+
## Operations
|
|
20
|
+
|
|
21
|
+
| Operation | Factory | Happy branch | Optional branches |
|
|
22
|
+
| --- | --- | --- | --- |
|
|
23
|
+
| `selectRows` | `new_select_rows_step` | `selected` | `providerRejected`, `invalidResponse`, `defect` |
|
|
24
|
+
| `upsertRows` | `new_upsert_rows_step` | `upserted` | `providerRejected`, `invalidResponse`, `defect` |
|
|
25
|
+
|
|
26
|
+
`selectRows` reads one PostgREST page of an exposed table: `columns` is a
|
|
27
|
+
comma-separated identifier list (blank selects all), `limit` ranges from 1
|
|
28
|
+
through 1000 (zero means 100), and the JSON row array is returned untouched.
|
|
29
|
+
`upsertRows` posts 1 through 100 rows with
|
|
30
|
+
`Prefer: resolution=merge-duplicates,return=representation` and
|
|
31
|
+
`on_conflict=<onConflict>`. Every row must carry non-null, distinct values for
|
|
32
|
+
the conflict columns, which the database must declare unique, so a retry merges
|
|
33
|
+
into the same rows. HTTP 201 or 200 with a row array selects `upserted`.
|
|
34
|
+
|
|
35
|
+
Both operations retry on 408, 429, 5xx, and transport failures; other non-200
|
|
36
|
+
statuses select `providerRejected` with authentication (401), authorization
|
|
37
|
+
(403), or validation (400, 422) kinds.
|
|
38
|
+
|
|
39
|
+
## Authorization
|
|
40
|
+
|
|
41
|
+
Create a Dex Web connection named `supabase` as described in the
|
|
42
|
+
[connector README](../README.md#authorization-and-configuration), with the
|
|
43
|
+
project's Data API URL as `baseUrl`. The API key travels only in the `apikey`
|
|
44
|
+
header and is resolved for every attempt.
|
|
45
|
+
|
|
46
|
+
## Example
|
|
47
|
+
|
|
48
|
+
[`examples/sample_supabase`](examples/sample_supabase/flow.py) selects one
|
|
49
|
+
page of rows. Run the Worker with
|
|
50
|
+
`uv run python -m examples.sample_supabase.worker` after `dexcli dev` has
|
|
51
|
+
loaded a project containing the `supabase` connection.
|
|
52
|
+
|
|
53
|
+
## Tests
|
|
54
|
+
|
|
55
|
+
`supabasemock.Mock` scripts both operations and defaults to the manifest
|
|
56
|
+
answers. Run `uv run pytest tests` for provider parity and manifest contract
|
|
57
|
+
checks.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Supabase connector for Python
|
|
2
|
+
|
|
3
|
+
Install with `pip install dex-connector-supabase==0.1.0`. The package requires
|
|
4
|
+
`dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`, and implements the
|
|
5
|
+
manifest operations `selectRows` (Query) and `upsertRows` (Mutation) with the
|
|
6
|
+
same branches, defaults, and failure classification as the Go module.
|
|
7
|
+
|
|
8
|
+
## Operations
|
|
9
|
+
|
|
10
|
+
| Operation | Factory | Happy branch | Optional branches |
|
|
11
|
+
| --- | --- | --- | --- |
|
|
12
|
+
| `selectRows` | `new_select_rows_step` | `selected` | `providerRejected`, `invalidResponse`, `defect` |
|
|
13
|
+
| `upsertRows` | `new_upsert_rows_step` | `upserted` | `providerRejected`, `invalidResponse`, `defect` |
|
|
14
|
+
|
|
15
|
+
`selectRows` reads one PostgREST page of an exposed table: `columns` is a
|
|
16
|
+
comma-separated identifier list (blank selects all), `limit` ranges from 1
|
|
17
|
+
through 1000 (zero means 100), and the JSON row array is returned untouched.
|
|
18
|
+
`upsertRows` posts 1 through 100 rows with
|
|
19
|
+
`Prefer: resolution=merge-duplicates,return=representation` and
|
|
20
|
+
`on_conflict=<onConflict>`. Every row must carry non-null, distinct values for
|
|
21
|
+
the conflict columns, which the database must declare unique, so a retry merges
|
|
22
|
+
into the same rows. HTTP 201 or 200 with a row array selects `upserted`.
|
|
23
|
+
|
|
24
|
+
Both operations retry on 408, 429, 5xx, and transport failures; other non-200
|
|
25
|
+
statuses select `providerRejected` with authentication (401), authorization
|
|
26
|
+
(403), or validation (400, 422) kinds.
|
|
27
|
+
|
|
28
|
+
## Authorization
|
|
29
|
+
|
|
30
|
+
Create a Dex Web connection named `supabase` as described in the
|
|
31
|
+
[connector README](../README.md#authorization-and-configuration), with the
|
|
32
|
+
project's Data API URL as `baseUrl`. The API key travels only in the `apikey`
|
|
33
|
+
header and is resolved for every attempt.
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
[`examples/sample_supabase`](examples/sample_supabase/flow.py) selects one
|
|
38
|
+
page of rows. Run the Worker with
|
|
39
|
+
`uv run python -m examples.sample_supabase.worker` after `dexcli dev` has
|
|
40
|
+
loaded a project containing the `supabase` connection.
|
|
41
|
+
|
|
42
|
+
## Tests
|
|
43
|
+
|
|
44
|
+
`supabasemock.Mock` scripts both operations and defaults to the manifest
|
|
45
|
+
answers. Run `uv run pytest tests` for provider parity and manifest contract
|
|
46
|
+
checks.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Runnable Supabase sample Flow using the selectRows Query."""
|
|
4
|
+
|
|
5
|
+
import dex
|
|
6
|
+
from dex_connectors.sdk import QueryResult
|
|
7
|
+
|
|
8
|
+
from dex_connectors.supabase import (
|
|
9
|
+
Connection,
|
|
10
|
+
SelectRowsInput,
|
|
11
|
+
SelectRowsOutput,
|
|
12
|
+
new_select_rows_step,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
FLOW_TYPE = "SupabaseSample"
|
|
16
|
+
CONNECTION_NAME = "supabase"
|
|
17
|
+
_CALL_STEP_TYPE = "CallSupabase"
|
|
18
|
+
_RESULT = dex.Attribute("supabase-sample-result", SelectRowsOutput)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def map_to_operation_input(request: SelectRowsInput) -> SelectRowsInput:
|
|
22
|
+
"""Pass the validated Flow request to the connector."""
|
|
23
|
+
return request
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# dex:group group-id:supabase-start group-label:"Supabase sample"
|
|
27
|
+
# dex:explanation text:"Pass the start input to the connector operation."
|
|
28
|
+
class _StartRequest(dex.Step[SelectRowsInput]):
|
|
29
|
+
def get_step_type(self) -> str:
|
|
30
|
+
return "StartSupabaseRequest"
|
|
31
|
+
|
|
32
|
+
def execute(self, context: dex.Context, input: SelectRowsInput) -> dex.StepDecision:
|
|
33
|
+
return dex.go_to(dex.StepRef(_CALL_STEP_TYPE), input)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# dex:group group-id:supabase-complete group-label:"Supabase sample"
|
|
37
|
+
# dex:explanation text:"Complete the Flow with the provider response."
|
|
38
|
+
class _CompleteRequest(dex.Step[QueryResult[SelectRowsOutput]]):
|
|
39
|
+
def get_step_type(self) -> str:
|
|
40
|
+
return "CompleteSupabaseRequest"
|
|
41
|
+
|
|
42
|
+
def execute(self, context: dex.Context, input: QueryResult[SelectRowsOutput]) -> dex.StepDecision:
|
|
43
|
+
_RESULT.set(context, input.value)
|
|
44
|
+
return dex.graceful_complete(input.value)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class SampleFlow(dex.Flow[SelectRowsInput]):
|
|
48
|
+
"""Run one selectRows read through the static supabase connection."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, connection: Connection) -> None:
|
|
51
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
52
|
+
raise ValueError("the sample requires the static supabase connection")
|
|
53
|
+
self._start = _StartRequest()
|
|
54
|
+
self._complete = _CompleteRequest()
|
|
55
|
+
self._call = new_select_rows_step(
|
|
56
|
+
step_type=_CALL_STEP_TYPE,
|
|
57
|
+
step_input_type=SelectRowsInput,
|
|
58
|
+
annotations={
|
|
59
|
+
"groupId": "supabase",
|
|
60
|
+
"groupLabel": "Supabase",
|
|
61
|
+
"explanation": "Select a bounded page of table rows through PostgREST.",
|
|
62
|
+
},
|
|
63
|
+
connection=connection,
|
|
64
|
+
connection_name=CONNECTION_NAME,
|
|
65
|
+
map_to_operation_input=map_to_operation_input,
|
|
66
|
+
selected=self._complete,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def get_flow_type(self) -> str:
|
|
70
|
+
"""Return the stable Flow identity used in Dex Web."""
|
|
71
|
+
return FLOW_TYPE
|
|
72
|
+
|
|
73
|
+
def get_steps(self) -> dex.StepList[SelectRowsInput]:
|
|
74
|
+
"""Register the start, provider read, and completion Steps."""
|
|
75
|
+
return dex.StepList.start_step(self._start).other_steps(self._call, self._complete)
|
|
76
|
+
|
|
77
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
78
|
+
"""Persist the provider result."""
|
|
79
|
+
return dex.PersistenceSchema.of(_RESULT)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Worker entrypoint for the Supabase sample Flow."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import dex
|
|
11
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
12
|
+
|
|
13
|
+
from dex_connectors.supabase import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, SampleFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run_worker() -> None:
|
|
19
|
+
"""Load the named Dex Web connection and select rows."""
|
|
20
|
+
project = await load_from_environment()
|
|
21
|
+
connection = None
|
|
22
|
+
cache = None
|
|
23
|
+
try:
|
|
24
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
25
|
+
registry = dex.Registry([SampleFlow(connection)], allow_async_handlers=True)
|
|
26
|
+
cache_directory = os.environ.get(
|
|
27
|
+
"DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-supabase-sample-blobs")
|
|
28
|
+
)
|
|
29
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 30))
|
|
30
|
+
worker = dex.AsyncWorker(
|
|
31
|
+
registry,
|
|
32
|
+
cache,
|
|
33
|
+
dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
|
|
34
|
+
)
|
|
35
|
+
async with worker:
|
|
36
|
+
await worker.start()
|
|
37
|
+
finally:
|
|
38
|
+
if connection is not None:
|
|
39
|
+
await connection.aclose()
|
|
40
|
+
if cache is not None:
|
|
41
|
+
cache.close()
|
|
42
|
+
await project.close()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main() -> None:
|
|
46
|
+
"""Run until the Worker stops or the process receives an interrupt."""
|
|
47
|
+
asyncio.run(run_worker())
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dex-connector-supabase"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Supabase connector for Dex Flows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = ["dex-connectors-sdk==0.1.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
|
|
13
|
+
|
|
14
|
+
[dependency-groups]
|
|
15
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7", "pyyaml>=6", "types-PyYAML>=6"]
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build.targets.wheel]
|
|
18
|
+
packages = ["src/dex_connectors"]
|
|
19
|
+
|
|
20
|
+
[tool.pytest.ini_options]
|
|
21
|
+
testpaths = ["tests"]
|
|
22
|
+
pythonpath = [".", "src"]
|
|
23
|
+
asyncio_mode = "auto"
|
|
24
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
25
|
+
|
|
26
|
+
[tool.mypy]
|
|
27
|
+
python_version = "3.11"
|
|
28
|
+
strict = true
|
|
29
|
+
mypy_path = "src"
|
|
30
|
+
explicit_package_bases = true
|
|
31
|
+
|
|
32
|
+
[tool.ruff]
|
|
33
|
+
target-version = "py311"
|
|
34
|
+
line-length = 110
|
|
35
|
+
|
|
36
|
+
[tool.ruff.lint]
|
|
37
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Supabase table row selection and upsert operations for Dex connector Steps."""
|
|
4
|
+
|
|
5
|
+
from .client import (
|
|
6
|
+
CONNECTOR_ID,
|
|
7
|
+
DEFECT,
|
|
8
|
+
INVALID_RESPONSE,
|
|
9
|
+
PROVIDER_REJECTED,
|
|
10
|
+
SELECT_ROWS_DEFINITION,
|
|
11
|
+
SELECTED,
|
|
12
|
+
UPSERT_PREFERENCE,
|
|
13
|
+
UPSERT_ROWS_DEFINITION,
|
|
14
|
+
UPSERTED,
|
|
15
|
+
Client,
|
|
16
|
+
Config,
|
|
17
|
+
Credentials,
|
|
18
|
+
SelectRowsOperation,
|
|
19
|
+
UpsertRowsOperation,
|
|
20
|
+
)
|
|
21
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
22
|
+
from .models import SelectRowsInput, SelectRowsOutput, UpsertRowsInput, UpsertRowsOutput
|
|
23
|
+
from .steps import new_select_rows_step, new_upsert_rows_step
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"Client",
|
|
27
|
+
"Config",
|
|
28
|
+
"Connection",
|
|
29
|
+
"Credentials",
|
|
30
|
+
"SelectRowsInput",
|
|
31
|
+
"SelectRowsOperation",
|
|
32
|
+
"SelectRowsOutput",
|
|
33
|
+
"UpsertRowsInput",
|
|
34
|
+
"UpsertRowsOperation",
|
|
35
|
+
"UpsertRowsOutput",
|
|
36
|
+
"new_connection",
|
|
37
|
+
"new_connection_with_operations",
|
|
38
|
+
"new_project_connection",
|
|
39
|
+
"new_select_rows_step",
|
|
40
|
+
"new_upsert_rows_step",
|
|
41
|
+
"CONNECTOR_ID",
|
|
42
|
+
"DEFECT",
|
|
43
|
+
"INVALID_RESPONSE",
|
|
44
|
+
"PROVIDER_REJECTED",
|
|
45
|
+
"SELECT_ROWS_DEFINITION",
|
|
46
|
+
"SELECTED",
|
|
47
|
+
"UPSERT_PREFERENCE",
|
|
48
|
+
"UPSERT_ROWS_DEFINITION",
|
|
49
|
+
"UPSERTED",
|
|
50
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
base_url: str
|
|
14
|
+
timeout_seconds: float = 15
|
|
15
|
+
max_response_bytes: int = 2097152
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.supabase.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
api_key: SecretString
|
|
24
|
+
|
|
25
|
+
setattr(Credentials, '__module__', 'dex_connectors.supabase.client')
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from dex_connectors.sdk import ConnectionRef, Mutation, Query, Call, SecretString
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
|
|
11
|
+
from ..client import Client, Config, Credentials
|
|
12
|
+
from .definitions import CONNECTOR_ID, SELECT_ROWS_DEFINITION, UPSERT_ROWS_DEFINITION
|
|
13
|
+
from ..models import SelectRowsInput, SelectRowsOutput, UpsertRowsInput, UpsertRowsOutput
|
|
14
|
+
|
|
15
|
+
class Connection:
|
|
16
|
+
|
|
17
|
+
__slots__ = ('_upsert_rows', '_select_rows', '_client', 'reference')
|
|
18
|
+
|
|
19
|
+
def __init__(self,
|
|
20
|
+
reference: ConnectionRef,
|
|
21
|
+
upsert_rows: Mutation[UpsertRowsInput, UpsertRowsOutput],
|
|
22
|
+
select_rows: Query[SelectRowsInput, SelectRowsOutput],
|
|
23
|
+
client: Client | None = None,
|
|
24
|
+
) -> None:
|
|
25
|
+
reference.validate()
|
|
26
|
+
if reference.provider != CONNECTOR_ID or upsert_rows is None or select_rows is None:
|
|
27
|
+
raise ValueError("Supabase connection provider and operations are required")
|
|
28
|
+
if upsert_rows.definition().operation != UPSERT_ROWS_DEFINITION.operation:
|
|
29
|
+
raise ValueError("Supabase connection operation identity differs")
|
|
30
|
+
if select_rows.definition().operation != SELECT_ROWS_DEFINITION.operation:
|
|
31
|
+
raise ValueError("Supabase connection operation identity differs")
|
|
32
|
+
self.reference = reference
|
|
33
|
+
self._upsert_rows = upsert_rows
|
|
34
|
+
self._select_rows = select_rows
|
|
35
|
+
self._client = client
|
|
36
|
+
|
|
37
|
+
def upsert_rows(self) -> Mutation[UpsertRowsInput, UpsertRowsOutput]:
|
|
38
|
+
return self._upsert_rows
|
|
39
|
+
|
|
40
|
+
def select_rows(self) -> Query[SelectRowsInput, SelectRowsOutput]:
|
|
41
|
+
return self._select_rows
|
|
42
|
+
|
|
43
|
+
async def aclose(self) -> None:
|
|
44
|
+
if self._client is not None:
|
|
45
|
+
await self._client.aclose()
|
|
46
|
+
|
|
47
|
+
def __repr__(self) -> str:
|
|
48
|
+
return "supabase.Connection([REDACTED])"
|
|
49
|
+
|
|
50
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
51
|
+
raise TypeError("Supabase connections cannot be serialized")
|
|
52
|
+
|
|
53
|
+
setattr(Connection, '__module__', 'dex_connectors.supabase.connection')
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
57
|
+
if client is None:
|
|
58
|
+
raise ValueError("Supabase client is required")
|
|
59
|
+
return Connection(reference, client.upsert_rows(), client.select_rows(), client)
|
|
60
|
+
|
|
61
|
+
setattr(new_connection, '__module__', 'dex_connectors.supabase.connection')
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def new_connection_with_operations(
|
|
65
|
+
upsert_rows: Mutation[UpsertRowsInput, UpsertRowsOutput],
|
|
66
|
+
select_rows: Query[SelectRowsInput, SelectRowsOutput],
|
|
67
|
+
reference: ConnectionRef,
|
|
68
|
+
) -> Connection:
|
|
69
|
+
return Connection(reference, upsert_rows, select_rows)
|
|
70
|
+
|
|
71
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.supabase.connection')
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class _ProjectCredentialSource:
|
|
75
|
+
|
|
76
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey) -> None:
|
|
77
|
+
self.project = project
|
|
78
|
+
self.key = key
|
|
79
|
+
|
|
80
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
81
|
+
material = await self.project.resolve_credential(self.key, str(call.id))
|
|
82
|
+
if not isinstance(material, dict):
|
|
83
|
+
raise ValueError("Supabase stored credential does not match the connector credential fields")
|
|
84
|
+
if set(material) - set(('api_key',)):
|
|
85
|
+
raise ValueError("Supabase stored credential does not match the connector credential fields")
|
|
86
|
+
api_key = material.get("api_key")
|
|
87
|
+
if api_key is not None and not (isinstance(api_key, str)):
|
|
88
|
+
raise ValueError("Supabase credential api_key has an invalid type")
|
|
89
|
+
if not api_key:
|
|
90
|
+
raise ValueError("Supabase credential api_key is required")
|
|
91
|
+
return Credentials(SecretString(api_key))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def new_project_connection(
|
|
95
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
96
|
+
) -> Connection:
|
|
97
|
+
if project is None:
|
|
98
|
+
raise ValueError("Supabase connection requires loaded project configuration")
|
|
99
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
100
|
+
reference.validate()
|
|
101
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
102
|
+
matching = [
|
|
103
|
+
entry
|
|
104
|
+
for entry in project.configuration.connections
|
|
105
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
106
|
+
]
|
|
107
|
+
if len(matching) != 1:
|
|
108
|
+
raise ValueError("Supabase project connection is missing or duplicated")
|
|
109
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
110
|
+
raise ValueError("Supabase project connection provider differs")
|
|
111
|
+
config = _decode_config(matching[0].configuration)
|
|
112
|
+
client = Client(config, _ProjectCredentialSource(project, key), http_client)
|
|
113
|
+
return new_connection(client, reference)
|
|
114
|
+
|
|
115
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.supabase.connection')
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
119
|
+
if set(value) - {"baseUrl", "timeout", "maxResponseBytes"}:
|
|
120
|
+
raise ValueError("Supabase configuration has unknown fields")
|
|
121
|
+
config_arguments: dict[str, Any] = {}
|
|
122
|
+
if "baseUrl" in value:
|
|
123
|
+
base_url = value["baseUrl"]
|
|
124
|
+
if not (isinstance(base_url, str)):
|
|
125
|
+
raise ValueError("Supabase configuration baseUrl has an invalid type")
|
|
126
|
+
config_arguments['base_url'] = base_url
|
|
127
|
+
else:
|
|
128
|
+
raise ValueError("Supabase configuration baseUrl is required")
|
|
129
|
+
if "timeout" in value:
|
|
130
|
+
timeout = value["timeout"]
|
|
131
|
+
if not (type(timeout) is int):
|
|
132
|
+
raise ValueError("Supabase configuration timeout has an invalid type")
|
|
133
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
134
|
+
if "maxResponseBytes" in value:
|
|
135
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
136
|
+
if not (type(max_response_bytes) is int):
|
|
137
|
+
raise ValueError("Supabase configuration maxResponseBytes has an invalid type")
|
|
138
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
139
|
+
return Config(**config_arguments)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import (
|
|
8
|
+
BranchDefinition,
|
|
9
|
+
MutationDefinition,
|
|
10
|
+
OperationRef,
|
|
11
|
+
QueryDefinition,
|
|
12
|
+
RetryPolicy,
|
|
13
|
+
StepDefaults,
|
|
14
|
+
default_connector_step_execute_retry_policy,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTOR_ID = "supabase"
|
|
18
|
+
PROVIDER = "supabase"
|
|
19
|
+
UPSERT_ROWS_OPERATION_ID = "upsertRows"
|
|
20
|
+
SELECT_ROWS_OPERATION_ID = "selectRows"
|
|
21
|
+
DEFECT = "defect"
|
|
22
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
23
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
24
|
+
SELECTED = "selected"
|
|
25
|
+
UPSERTED = "upserted"
|
|
26
|
+
|
|
27
|
+
UPSERT_ROWS_DEFINITION = MutationDefinition(
|
|
28
|
+
OperationRef(CONNECTOR_ID, UPSERT_ROWS_OPERATION_ID),
|
|
29
|
+
(
|
|
30
|
+
BranchDefinition(UPSERTED, "Upsert rows with a declared unique conflict key and merge duplicates.", False),
|
|
31
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider conclusively rejected the request or credentials.", True),
|
|
32
|
+
BranchDefinition(INVALID_RESPONSE, "The provider returned malformed or oversized JSON.", True),
|
|
33
|
+
BranchDefinition(DEFECT, "Local input, configuration, or credentials are invalid.", True),
|
|
34
|
+
),
|
|
35
|
+
StepDefaults(
|
|
36
|
+
timedelta(seconds=30),
|
|
37
|
+
2,
|
|
38
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
SELECT_ROWS_DEFINITION = QueryDefinition(
|
|
43
|
+
OperationRef(CONNECTOR_ID, SELECT_ROWS_OPERATION_ID),
|
|
44
|
+
(
|
|
45
|
+
BranchDefinition(SELECTED, "Select a bounded page of table rows through PostgREST.", False),
|
|
46
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider conclusively rejected the request or credentials.", True),
|
|
47
|
+
BranchDefinition(INVALID_RESPONSE, "The provider returned malformed or oversized JSON.", True),
|
|
48
|
+
BranchDefinition(DEFECT, "Local input, configuration, or credentials are invalid.", True),
|
|
49
|
+
),
|
|
50
|
+
StepDefaults(
|
|
51
|
+
timedelta(seconds=30),
|
|
52
|
+
2,
|
|
53
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
54
|
+
),
|
|
55
|
+
)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import ConnectionRef, Failure, FailureKind
|
|
8
|
+
from dex_connectors.sdk.connectormock import Case, Mutation, Query
|
|
9
|
+
|
|
10
|
+
from ..connection import Connection, new_connection_with_operations
|
|
11
|
+
from ..models import SelectRowsInput, SelectRowsOutput, UpsertRowsInput, UpsertRowsOutput
|
|
12
|
+
from .definitions import CONNECTOR_ID, DEFECT, INVALID_RESPONSE, PROVIDER_REJECTED, SELECTED, SELECT_ROWS_DEFINITION, UPSERTED, UPSERT_ROWS_DEFINITION
|
|
13
|
+
|
|
14
|
+
def upsert_rows_upserted(value: UpsertRowsOutput, failure: Failure | None = None) -> Case[UpsertRowsOutput]:
|
|
15
|
+
return Case.branch_result(UPSERTED, value, failure)
|
|
16
|
+
|
|
17
|
+
setattr(upsert_rows_upserted, '__module__', "dex_connectors.supabase.supabasemock")
|
|
18
|
+
|
|
19
|
+
def upsert_rows_provider_rejected(value: UpsertRowsOutput, failure: Failure | None = None) -> Case[UpsertRowsOutput]:
|
|
20
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
21
|
+
|
|
22
|
+
setattr(upsert_rows_provider_rejected, '__module__', "dex_connectors.supabase.supabasemock")
|
|
23
|
+
|
|
24
|
+
def upsert_rows_invalid_response(value: UpsertRowsOutput, failure: Failure | None = None) -> Case[UpsertRowsOutput]:
|
|
25
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
26
|
+
|
|
27
|
+
setattr(upsert_rows_invalid_response, '__module__', "dex_connectors.supabase.supabasemock")
|
|
28
|
+
|
|
29
|
+
def upsert_rows_defect(value: UpsertRowsOutput, failure: Failure | None = None) -> Case[UpsertRowsOutput]:
|
|
30
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
31
|
+
|
|
32
|
+
setattr(upsert_rows_defect, '__module__', "dex_connectors.supabase.supabasemock")
|
|
33
|
+
|
|
34
|
+
def upsert_rows_retry(failure: Failure, after_seconds: float = 0) -> Case[UpsertRowsOutput]:
|
|
35
|
+
return Case.retry(failure, after_seconds)
|
|
36
|
+
|
|
37
|
+
setattr(upsert_rows_retry, '__module__', "dex_connectors.supabase.supabasemock")
|
|
38
|
+
|
|
39
|
+
def upsert_rows_default_upsert_rows() -> Case[UpsertRowsOutput]:
|
|
40
|
+
return Case.branch_result(UPSERTED, UpsertRowsOutput(data=[{'id': 1, 'name': 'Meridian'}]))
|
|
41
|
+
|
|
42
|
+
setattr(upsert_rows_default_upsert_rows, '__module__', "dex_connectors.supabase.supabasemock")
|
|
43
|
+
|
|
44
|
+
def select_rows_selected(value: SelectRowsOutput, failure: Failure | None = None) -> Case[SelectRowsOutput]:
|
|
45
|
+
return Case.branch_result(SELECTED, value, failure)
|
|
46
|
+
|
|
47
|
+
setattr(select_rows_selected, '__module__', "dex_connectors.supabase.supabasemock")
|
|
48
|
+
|
|
49
|
+
def select_rows_provider_rejected(value: SelectRowsOutput, failure: Failure | None = None) -> Case[SelectRowsOutput]:
|
|
50
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
51
|
+
|
|
52
|
+
setattr(select_rows_provider_rejected, '__module__', "dex_connectors.supabase.supabasemock")
|
|
53
|
+
|
|
54
|
+
def select_rows_invalid_response(value: SelectRowsOutput, failure: Failure | None = None) -> Case[SelectRowsOutput]:
|
|
55
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
56
|
+
|
|
57
|
+
setattr(select_rows_invalid_response, '__module__', "dex_connectors.supabase.supabasemock")
|
|
58
|
+
|
|
59
|
+
def select_rows_defect(value: SelectRowsOutput, failure: Failure | None = None) -> Case[SelectRowsOutput]:
|
|
60
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
61
|
+
|
|
62
|
+
setattr(select_rows_defect, '__module__', "dex_connectors.supabase.supabasemock")
|
|
63
|
+
|
|
64
|
+
def select_rows_retry(failure: Failure, after_seconds: float = 0) -> Case[SelectRowsOutput]:
|
|
65
|
+
return Case.retry(failure, after_seconds)
|
|
66
|
+
|
|
67
|
+
setattr(select_rows_retry, '__module__', "dex_connectors.supabase.supabasemock")
|
|
68
|
+
|
|
69
|
+
def select_rows_default_select_rows() -> Case[SelectRowsOutput]:
|
|
70
|
+
return Case.branch_result(SELECTED, SelectRowsOutput(data=[{'id': 1, 'name': 'Meridian'}]))
|
|
71
|
+
|
|
72
|
+
setattr(select_rows_default_select_rows, '__module__', "dex_connectors.supabase.supabasemock")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class Mock:
|
|
76
|
+
|
|
77
|
+
def __init__(self, connection_name: str = "supabase") -> None:
|
|
78
|
+
self.upsert_rows_script: Mutation[UpsertRowsInput, UpsertRowsOutput] = Mutation(UPSERT_ROWS_DEFINITION)
|
|
79
|
+
self.upsert_rows_script.default(upsert_rows_default_upsert_rows())
|
|
80
|
+
self.select_rows_script: Query[SelectRowsInput, SelectRowsOutput] = Query(SELECT_ROWS_DEFINITION)
|
|
81
|
+
self.select_rows_script.default(select_rows_default_select_rows())
|
|
82
|
+
self._connection = new_connection_with_operations(
|
|
83
|
+
upsert_rows=self.upsert_rows_script,
|
|
84
|
+
select_rows=self.select_rows_script,
|
|
85
|
+
reference=ConnectionRef(CONNECTOR_ID, connection_name),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def connection(self) -> Connection:
|
|
89
|
+
return self._connection
|
|
90
|
+
|
|
91
|
+
setattr(Mock, '__module__', "dex_connectors.supabase.supabasemock")
|
|
92
|
+
|
|
93
|
+
__all__ = [
|
|
94
|
+
"Mock",
|
|
95
|
+
"upsert_rows_upserted",
|
|
96
|
+
"upsert_rows_provider_rejected",
|
|
97
|
+
"upsert_rows_invalid_response",
|
|
98
|
+
"upsert_rows_defect",
|
|
99
|
+
"upsert_rows_retry",
|
|
100
|
+
"upsert_rows_default_upsert_rows",
|
|
101
|
+
"select_rows_selected",
|
|
102
|
+
"select_rows_provider_rejected",
|
|
103
|
+
"select_rows_invalid_response",
|
|
104
|
+
"select_rows_defect",
|
|
105
|
+
"select_rows_retry",
|
|
106
|
+
"select_rows_default_select_rows",
|
|
107
|
+
]
|