superfunctions-core 0.1.1__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.
- superfunctions_core-0.1.1/.gitignore +121 -0
- superfunctions_core-0.1.1/PKG-INFO +94 -0
- superfunctions_core-0.1.1/README.md +64 -0
- superfunctions_core-0.1.1/pyproject.toml +67 -0
- superfunctions_core-0.1.1/superfunctions/__init__.py +11 -0
- superfunctions_core-0.1.1/superfunctions/auth/__init__.py +114 -0
- superfunctions_core-0.1.1/superfunctions/db/__init__.py +115 -0
- superfunctions_core-0.1.1/superfunctions/db/errors.py +176 -0
- superfunctions_core-0.1.1/superfunctions/db/namespace.py +62 -0
- superfunctions_core-0.1.1/superfunctions/db/types.py +513 -0
- superfunctions_core-0.1.1/superfunctions/http/__init__.py +81 -0
- superfunctions_core-0.1.1/superfunctions/http/executor.py +36 -0
- superfunctions_core-0.1.1/superfunctions/http/openapi.py +150 -0
- superfunctions_core-0.1.1/superfunctions/http/types.py +374 -0
- superfunctions_core-0.1.1/superfunctions/oauth/__init__.py +173 -0
- superfunctions_core-0.1.1/superfunctions/oauth/core.py +223 -0
- superfunctions_core-0.1.1/superfunctions/oauth/flow.py +922 -0
- superfunctions_core-0.1.1/superfunctions/oauth/http.py +226 -0
- superfunctions_core-0.1.1/superfunctions/oauth/storage.py +506 -0
- superfunctions_core-0.1.1/superfunctions/py.typed +1 -0
- superfunctions_core-0.1.1/superfunctions/schema_helpers.py +11 -0
- superfunctions_core-0.1.1/tests/conftest.py +12 -0
- superfunctions_core-0.1.1/tests/test_auth_http_types.py +83 -0
- superfunctions_core-0.1.1/tests/test_oauth.py +184 -0
- superfunctions_core-0.1.1/tests/test_oauth_modules.py +216 -0
- superfunctions_core-0.1.1/tests/test_openapi.py +275 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
**/node_modules
|
|
4
|
+
.pnp
|
|
5
|
+
.pnp.js
|
|
6
|
+
|
|
7
|
+
# Build outputs
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
*.tsbuildinfo
|
|
11
|
+
**/*.js
|
|
12
|
+
**/*.d.ts
|
|
13
|
+
!apifn/docsfn/src/svelte/ApifnApiReference.svelte.d.ts
|
|
14
|
+
!superconsole/src/app.d.ts
|
|
15
|
+
!uifn/catalog/generated/primitive-contracts.d.ts
|
|
16
|
+
**/*.d.ts.map
|
|
17
|
+
**/*.js.map
|
|
18
|
+
|
|
19
|
+
# But allow config files
|
|
20
|
+
!*.config.js
|
|
21
|
+
!**/vitest.config.js
|
|
22
|
+
!**/tsup.config.js
|
|
23
|
+
|
|
24
|
+
# Logs
|
|
25
|
+
logs
|
|
26
|
+
*.log
|
|
27
|
+
npm-debug.log*
|
|
28
|
+
yarn-debug.log*
|
|
29
|
+
yarn-error.log*
|
|
30
|
+
lerna-debug.log*
|
|
31
|
+
.pnpm-debug.log*
|
|
32
|
+
|
|
33
|
+
# Environment variables
|
|
34
|
+
.env
|
|
35
|
+
.env.*
|
|
36
|
+
!.env.example
|
|
37
|
+
|
|
38
|
+
# Security
|
|
39
|
+
*.pem
|
|
40
|
+
!uifn/registry/trust/registry-ed25519-public.pem
|
|
41
|
+
*.p12
|
|
42
|
+
*.key
|
|
43
|
+
*-key.pem
|
|
44
|
+
|
|
45
|
+
# Testing
|
|
46
|
+
coverage/
|
|
47
|
+
.vite-vitest/
|
|
48
|
+
.nyc_output
|
|
49
|
+
test-results/
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
__pycache__/
|
|
52
|
+
*.py[cod]
|
|
53
|
+
.venv/
|
|
54
|
+
.venv*/
|
|
55
|
+
|
|
56
|
+
# OCR integration tests download language models into their working directory
|
|
57
|
+
/filefn/server/*.traineddata
|
|
58
|
+
/filefn/processing/*.traineddata
|
|
59
|
+
|
|
60
|
+
# Editors
|
|
61
|
+
.vscode/
|
|
62
|
+
.idea/
|
|
63
|
+
*.swp
|
|
64
|
+
*.swo
|
|
65
|
+
*~
|
|
66
|
+
.DS_Store
|
|
67
|
+
|
|
68
|
+
# Turbo
|
|
69
|
+
.turbo/
|
|
70
|
+
|
|
71
|
+
# Vite writes these next to a config while bundling it
|
|
72
|
+
**/vite.config.ts.timestamp-*
|
|
73
|
+
**/vite.config.js.timestamp-*
|
|
74
|
+
|
|
75
|
+
# Misc
|
|
76
|
+
*.tgz
|
|
77
|
+
.cache/
|
|
78
|
+
*.bundled_*.mjs
|
|
79
|
+
|
|
80
|
+
.agent
|
|
81
|
+
.venv
|
|
82
|
+
|
|
83
|
+
__pycache__
|
|
84
|
+
venv
|
|
85
|
+
|
|
86
|
+
# AI tool configs
|
|
87
|
+
.claude/
|
|
88
|
+
.entire/*
|
|
89
|
+
!.entire/.gitignore
|
|
90
|
+
!.entire/settings.json
|
|
91
|
+
.cursor/
|
|
92
|
+
.gemini/
|
|
93
|
+
|
|
94
|
+
# Python build artifacts
|
|
95
|
+
*.egg-info/
|
|
96
|
+
|
|
97
|
+
# Sub-package lock files (keep root only)
|
|
98
|
+
**/package-lock.json
|
|
99
|
+
!/package-lock.json
|
|
100
|
+
!.github/apifn-cli-install/package-lock.json
|
|
101
|
+
.vercel
|
|
102
|
+
|
|
103
|
+
.next/
|
|
104
|
+
.source/
|
|
105
|
+
.svelte-kit/
|
|
106
|
+
.docsfn/
|
|
107
|
+
docsfn/.tmp/
|
|
108
|
+
.tmp/browsefn-*/
|
|
109
|
+
.tmp/jscpd/langfn/
|
|
110
|
+
.reviewfn/artifacts/
|
|
111
|
+
.reviewfn/output/
|
|
112
|
+
|
|
113
|
+
# Apple / Xcode user artifacts
|
|
114
|
+
DerivedData/
|
|
115
|
+
**/xcuserdata/
|
|
116
|
+
**/*.xcuserstate
|
|
117
|
+
**/.swiftpm/
|
|
118
|
+
**/.build/
|
|
119
|
+
|
|
120
|
+
# Codex hooks are global (~/.codex/hooks.json); never commit repo-level ones
|
|
121
|
+
.codex/hooks.json
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: superfunctions-core
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Core HTTP abstractions for the superfunctions ecosystem
|
|
5
|
+
Project-URL: Documentation, https://docs.superfunctions.dev
|
|
6
|
+
Project-URL: Repository, https://github.com/21nCo/super-functions
|
|
7
|
+
Project-URL: Issues, https://github.com/21nCo/super-functions/issues
|
|
8
|
+
Author-email: 21n <support@superfunctions.dev>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Keywords: adapter,http,openapi,superfunctions,web
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: pydantic>=2.5.0
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: black>=23.11.0; extra == 'dev'
|
|
23
|
+
Requires-Dist: httpx>=0.25.0; extra == 'dev'
|
|
24
|
+
Requires-Dist: mypy>=1.7.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.1.6; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# superfunctions-core
|
|
32
|
+
|
|
33
|
+
> Core HTTP abstractions for the superfunctions ecosystem
|
|
34
|
+
|
|
35
|
+
**Location:** `packages/python-core/`
|
|
36
|
+
**Package:** `superfunctions-core`
|
|
37
|
+
**Import:** `from superfunctions.http import ...`
|
|
38
|
+
|
|
39
|
+
The distribution is named `superfunctions-core`; Python imports remain under `superfunctions`. When migrating an environment with the old `superfunctions` distribution, uninstall it before installing this package to avoid overlapping installed files.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install 'superfunctions-core>=0.1.1,<0.2.0'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The distribution name changed because PyPI's `superfunctions` belongs to an
|
|
48
|
+
unrelated Youssef/youssefa metafunction project; its `0.1.3` release is not a
|
|
49
|
+
21n baseline. The Python import namespace remains `superfunctions`, with no
|
|
50
|
+
old-distribution compatibility shim. The initial core version is `0.1.1`.
|
|
51
|
+
Publish this prerequisite before releasing dependent Python SDKs or adapters;
|
|
52
|
+
until then, validate with the actual locally built wheel via `PIP_FIND_LINKS`.
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
### HTTP Abstractions
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from superfunctions.http import Request, Response, RouteContext, NotFoundError
|
|
60
|
+
|
|
61
|
+
async def get_user_handler(request: Request, context: RouteContext) -> Response:
|
|
62
|
+
user_id = context.params.get("id")
|
|
63
|
+
|
|
64
|
+
user = await db.find_one(...)
|
|
65
|
+
if not user:
|
|
66
|
+
raise NotFoundError(f"User {user_id} not found")
|
|
67
|
+
|
|
68
|
+
return Response(status=200, body=user)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Adapters
|
|
72
|
+
|
|
73
|
+
Install adapter packages separately based on your stack:
|
|
74
|
+
|
|
75
|
+
### HTTP Framework Adapters
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# FastAPI
|
|
79
|
+
pip install superfunctions-fastapi
|
|
80
|
+
|
|
81
|
+
# Flask
|
|
82
|
+
pip install superfunctions-flask
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Additional framework adapters will be added over time.
|
|
86
|
+
|
|
87
|
+
## Documentation
|
|
88
|
+
|
|
89
|
+
- [HTTP Documentation](https://docs.superfunctions.dev/http)
|
|
90
|
+
- [API Reference](https://docs.superfunctions.dev/api)
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# superfunctions-core
|
|
2
|
+
|
|
3
|
+
> Core HTTP abstractions for the superfunctions ecosystem
|
|
4
|
+
|
|
5
|
+
**Location:** `packages/python-core/`
|
|
6
|
+
**Package:** `superfunctions-core`
|
|
7
|
+
**Import:** `from superfunctions.http import ...`
|
|
8
|
+
|
|
9
|
+
The distribution is named `superfunctions-core`; Python imports remain under `superfunctions`. When migrating an environment with the old `superfunctions` distribution, uninstall it before installing this package to avoid overlapping installed files.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install 'superfunctions-core>=0.1.1,<0.2.0'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The distribution name changed because PyPI's `superfunctions` belongs to an
|
|
18
|
+
unrelated Youssef/youssefa metafunction project; its `0.1.3` release is not a
|
|
19
|
+
21n baseline. The Python import namespace remains `superfunctions`, with no
|
|
20
|
+
old-distribution compatibility shim. The initial core version is `0.1.1`.
|
|
21
|
+
Publish this prerequisite before releasing dependent Python SDKs or adapters;
|
|
22
|
+
until then, validate with the actual locally built wheel via `PIP_FIND_LINKS`.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### HTTP Abstractions
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from superfunctions.http import Request, Response, RouteContext, NotFoundError
|
|
30
|
+
|
|
31
|
+
async def get_user_handler(request: Request, context: RouteContext) -> Response:
|
|
32
|
+
user_id = context.params.get("id")
|
|
33
|
+
|
|
34
|
+
user = await db.find_one(...)
|
|
35
|
+
if not user:
|
|
36
|
+
raise NotFoundError(f"User {user_id} not found")
|
|
37
|
+
|
|
38
|
+
return Response(status=200, body=user)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Adapters
|
|
42
|
+
|
|
43
|
+
Install adapter packages separately based on your stack:
|
|
44
|
+
|
|
45
|
+
### HTTP Framework Adapters
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# FastAPI
|
|
49
|
+
pip install superfunctions-fastapi
|
|
50
|
+
|
|
51
|
+
# Flask
|
|
52
|
+
pip install superfunctions-flask
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Additional framework adapters will be added over time.
|
|
56
|
+
|
|
57
|
+
## Documentation
|
|
58
|
+
|
|
59
|
+
- [HTTP Documentation](https://docs.superfunctions.dev/http)
|
|
60
|
+
- [API Reference](https://docs.superfunctions.dev/api)
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
MIT
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "superfunctions-core"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Core HTTP abstractions for the superfunctions ecosystem"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = ["superfunctions", "http", "adapter", "web", "openapi"]
|
|
13
|
+
authors = [{ name = "21n", email = "support@superfunctions.dev" }]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
]
|
|
24
|
+
dependencies = ["pydantic>=2.5.0"]
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
dev = [
|
|
28
|
+
"pytest>=7.4.0",
|
|
29
|
+
"pytest-asyncio>=0.21.0",
|
|
30
|
+
"pytest-cov>=4.1.0",
|
|
31
|
+
"mypy>=1.7.0",
|
|
32
|
+
"ruff>=0.1.6",
|
|
33
|
+
"black>=23.11.0",
|
|
34
|
+
"httpx>=0.25.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Documentation = "https://docs.superfunctions.dev"
|
|
39
|
+
Repository = "https://github.com/21nCo/super-functions"
|
|
40
|
+
Issues = "https://github.com/21nCo/super-functions/issues"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["superfunctions"]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
asyncio_mode = "auto"
|
|
48
|
+
addopts = ["--import-mode=importlib"]
|
|
49
|
+
|
|
50
|
+
[tool.mypy]
|
|
51
|
+
plugins = ["pydantic.mypy"]
|
|
52
|
+
python_version = "3.10"
|
|
53
|
+
warn_return_any = true
|
|
54
|
+
warn_unused_configs = true
|
|
55
|
+
disallow_untyped_defs = true
|
|
56
|
+
|
|
57
|
+
[tool.ruff]
|
|
58
|
+
target-version = "py310"
|
|
59
|
+
line-length = 100
|
|
60
|
+
|
|
61
|
+
[tool.ruff.lint]
|
|
62
|
+
select = ["E", "W", "F", "I", "B", "C4"]
|
|
63
|
+
ignore = ["E501"]
|
|
64
|
+
|
|
65
|
+
[tool.black]
|
|
66
|
+
line-length = 100
|
|
67
|
+
target-version = ["py310", "py311", "py312"]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Superfunctions - Core abstractions for the superfunctions ecosystem.
|
|
3
|
+
|
|
4
|
+
This is a namespace package that provides core HTTP abstractions and
|
|
5
|
+
utilities for framework adapters.
|
|
6
|
+
|
|
7
|
+
Example:
|
|
8
|
+
>>> from superfunctions.http import Request, Response
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.1"
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Shared auth abstractions for the superfunctions ecosystem."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from typing import Any, Dict, List, Optional, Protocol, runtime_checkable
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, Field, ValidationError
|
|
9
|
+
|
|
10
|
+
from superfunctions.http import Request
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AuthValidationError(Exception):
|
|
14
|
+
"""Structured validation error for shared auth payloads."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, message: str = "Invalid auth payload", details: Optional[Dict[str, Any]] = None):
|
|
17
|
+
super().__init__(message)
|
|
18
|
+
self.message = message
|
|
19
|
+
self.code = "AUTH_VALIDATION_ERROR"
|
|
20
|
+
self.status = 400
|
|
21
|
+
self.details = details or {}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AuthSubject(BaseModel):
|
|
25
|
+
"""Actor information attached to an authenticated session."""
|
|
26
|
+
|
|
27
|
+
actor_id: str = Field(alias="actorId")
|
|
28
|
+
actor_type: str = Field(alias="actorType")
|
|
29
|
+
tenant_id: Optional[str] = Field(None, alias="tenantId")
|
|
30
|
+
region_id: Optional[str] = Field(None, alias="regionId")
|
|
31
|
+
email: Optional[str] = None
|
|
32
|
+
attributes: Optional[Dict[str, Any]] = None
|
|
33
|
+
|
|
34
|
+
class Config:
|
|
35
|
+
populate_by_name = True
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class AuthSession(BaseModel):
|
|
39
|
+
"""Actor-centric shared auth session."""
|
|
40
|
+
|
|
41
|
+
id: str
|
|
42
|
+
type: str
|
|
43
|
+
subject: AuthSubject
|
|
44
|
+
resource_ids: Optional[List[str]] = Field(None, alias="resourceIds")
|
|
45
|
+
scopes: Optional[List[str]] = None
|
|
46
|
+
methods: Optional[List[str]] = None
|
|
47
|
+
expires_at: Optional[datetime] = Field(None, alias="expiresAt")
|
|
48
|
+
metadata: Optional[Dict[str, Any]] = None
|
|
49
|
+
|
|
50
|
+
class Config:
|
|
51
|
+
populate_by_name = True
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class AuthContext(BaseModel):
|
|
55
|
+
"""Optional client-side auth context."""
|
|
56
|
+
|
|
57
|
+
user_id: str = Field(alias="userId")
|
|
58
|
+
tenant_id: Optional[str] = Field(None, alias="tenantId")
|
|
59
|
+
region_id: Optional[str] = Field(None, alias="regionId")
|
|
60
|
+
metadata: Optional[Dict[str, Any]] = None
|
|
61
|
+
|
|
62
|
+
class Config:
|
|
63
|
+
populate_by_name = True
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@runtime_checkable
|
|
67
|
+
class AuthProvider(Protocol):
|
|
68
|
+
"""Framework-agnostic auth provider protocol."""
|
|
69
|
+
|
|
70
|
+
async def authenticate(self, request: Request) -> Optional[AuthSession]:
|
|
71
|
+
pass
|
|
72
|
+
|
|
73
|
+
async def authorize(self, session: AuthSession, resource_id: str) -> bool:
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
async def revoke(self, session_id: str) -> None:
|
|
77
|
+
pass
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def validate_auth_subject(value: Dict[str, Any]) -> AuthSubject:
|
|
81
|
+
"""Validate and normalize an auth subject."""
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
subject = AuthSubject.model_validate(value)
|
|
85
|
+
except ValidationError as exc:
|
|
86
|
+
raise AuthValidationError("Invalid auth subject", {"errors": exc.errors()}) from exc
|
|
87
|
+
|
|
88
|
+
if subject.actor_type not in {"user", "api-key", "service"}:
|
|
89
|
+
raise AuthValidationError("Invalid auth subject", {"actorType": subject.actor_type})
|
|
90
|
+
|
|
91
|
+
return subject
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def validate_auth_session(value: Dict[str, Any]) -> AuthSession:
|
|
95
|
+
"""Validate and normalize an auth session."""
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
session = AuthSession.model_validate(value)
|
|
99
|
+
except ValidationError as exc:
|
|
100
|
+
raise AuthValidationError("Invalid auth session", {"errors": exc.errors()}) from exc
|
|
101
|
+
|
|
102
|
+
validate_auth_subject(session.subject.model_dump(by_alias=True))
|
|
103
|
+
return session
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
__all__ = [
|
|
107
|
+
"AuthValidationError",
|
|
108
|
+
"AuthSubject",
|
|
109
|
+
"AuthSession",
|
|
110
|
+
"AuthContext",
|
|
111
|
+
"AuthProvider",
|
|
112
|
+
"validate_auth_subject",
|
|
113
|
+
"validate_auth_session",
|
|
114
|
+
]
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""
|
|
2
|
+
superfunctions.db - Database adapter system.
|
|
3
|
+
|
|
4
|
+
Provides protocol-based database abstractions that work with any ORM.
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
>>> from superfunctions.db import Adapter, CreateParams, FindManyParams
|
|
8
|
+
>>>
|
|
9
|
+
>>> # Use with any adapter implementation
|
|
10
|
+
>>> user = await adapter.create(
|
|
11
|
+
... CreateParams(model="users", data={"name": "Alice"})
|
|
12
|
+
... )
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from .errors import (
|
|
16
|
+
AdapterConnectionError,
|
|
17
|
+
AdapterError,
|
|
18
|
+
AdapterErrorCode,
|
|
19
|
+
AdapterTimeoutError,
|
|
20
|
+
ConstraintViolationError,
|
|
21
|
+
DuplicateKeyError,
|
|
22
|
+
NotFoundError,
|
|
23
|
+
OperationNotSupportedError,
|
|
24
|
+
QueryFailedError,
|
|
25
|
+
SchemaValidationError,
|
|
26
|
+
TransactionError,
|
|
27
|
+
)
|
|
28
|
+
from .namespace import NamespaceManager, create_namespace_manager
|
|
29
|
+
from .types import (
|
|
30
|
+
Adapter,
|
|
31
|
+
AdapterCapabilities,
|
|
32
|
+
AdapterConfig,
|
|
33
|
+
AtomicUpdateTransactionAdapter,
|
|
34
|
+
ConstraintSchema,
|
|
35
|
+
CountParams,
|
|
36
|
+
CreateManyParams,
|
|
37
|
+
CreateParams,
|
|
38
|
+
CreateSchemaParams,
|
|
39
|
+
DeleteManyParams,
|
|
40
|
+
DeleteParams,
|
|
41
|
+
Direction,
|
|
42
|
+
FieldSchema,
|
|
43
|
+
FieldType,
|
|
44
|
+
FindManyParams,
|
|
45
|
+
FindOneParams,
|
|
46
|
+
HealthStatus,
|
|
47
|
+
IndexSchema,
|
|
48
|
+
JoinConfig,
|
|
49
|
+
NamespaceConfig,
|
|
50
|
+
Operator,
|
|
51
|
+
OrderBy,
|
|
52
|
+
SchemaCreation,
|
|
53
|
+
TableSchema,
|
|
54
|
+
TransactionAdapter,
|
|
55
|
+
TransactionIsolation,
|
|
56
|
+
UpdateManyParams,
|
|
57
|
+
UpdateParams,
|
|
58
|
+
UpsertParams,
|
|
59
|
+
ValidationResult,
|
|
60
|
+
WhereClause,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
__all__ = [
|
|
64
|
+
# Core protocols
|
|
65
|
+
"Adapter",
|
|
66
|
+
"AtomicUpdateTransactionAdapter",
|
|
67
|
+
"TransactionAdapter",
|
|
68
|
+
# Configuration
|
|
69
|
+
"AdapterCapabilities",
|
|
70
|
+
"AdapterConfig",
|
|
71
|
+
"NamespaceConfig",
|
|
72
|
+
"HealthStatus",
|
|
73
|
+
# Operation parameters
|
|
74
|
+
"CreateParams",
|
|
75
|
+
"FindOneParams",
|
|
76
|
+
"FindManyParams",
|
|
77
|
+
"UpdateParams",
|
|
78
|
+
"DeleteParams",
|
|
79
|
+
"CreateManyParams",
|
|
80
|
+
"UpdateManyParams",
|
|
81
|
+
"DeleteManyParams",
|
|
82
|
+
"UpsertParams",
|
|
83
|
+
"CountParams",
|
|
84
|
+
# Query builders
|
|
85
|
+
"WhereClause",
|
|
86
|
+
"OrderBy",
|
|
87
|
+
"JoinConfig",
|
|
88
|
+
"Operator",
|
|
89
|
+
"Direction",
|
|
90
|
+
# Schema types
|
|
91
|
+
"FieldSchema",
|
|
92
|
+
"FieldType",
|
|
93
|
+
"ConstraintSchema",
|
|
94
|
+
"IndexSchema",
|
|
95
|
+
"TableSchema",
|
|
96
|
+
"ValidationResult",
|
|
97
|
+
"CreateSchemaParams",
|
|
98
|
+
"SchemaCreation",
|
|
99
|
+
"TransactionIsolation",
|
|
100
|
+
# Errors
|
|
101
|
+
"AdapterError",
|
|
102
|
+
"AdapterErrorCode",
|
|
103
|
+
"AdapterConnectionError",
|
|
104
|
+
"ConstraintViolationError",
|
|
105
|
+
"NotFoundError",
|
|
106
|
+
"DuplicateKeyError",
|
|
107
|
+
"QueryFailedError",
|
|
108
|
+
"TransactionError",
|
|
109
|
+
"SchemaValidationError",
|
|
110
|
+
"OperationNotSupportedError",
|
|
111
|
+
"AdapterTimeoutError",
|
|
112
|
+
# Utils
|
|
113
|
+
"NamespaceManager",
|
|
114
|
+
"create_namespace_manager",
|
|
115
|
+
]
|