diff --git a/pyproject.toml b/pyproject.toml index f98d3eaf..2de10a5a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ [tool.poetry] name = "royalnet" - version = "5.5a3" + version = "5.5a4" description = "A multipurpose bot and web framework" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" diff --git a/royalnet/backpack/stars/api_login_royalnet.py b/royalnet/backpack/stars/api_login_royalnet.py index a8b03e4c..2340d427 100644 --- a/royalnet/backpack/stars/api_login_royalnet.py +++ b/royalnet/backpack/stars/api_login_royalnet.py @@ -9,7 +9,9 @@ from ..tables.tokens import Token class ApiLoginRoyalnetStar(ApiStar): path = "/api/login/royalnet/v1" - async def api(self, data: ApiData) -> dict: + methods = ["POST"] + + async def api(self, data: ApiData) -> ru.JSON: TokenT = self.alchemy.get(Token) UserT = self.alchemy.get(User) AliasT = self.alchemy.get(Alias) diff --git a/royalnet/backpack/stars/api_royalnet_version.py b/royalnet/backpack/stars/api_royalnet_version.py index 65a17425..74092984 100644 --- a/royalnet/backpack/stars/api_royalnet_version.py +++ b/royalnet/backpack/stars/api_royalnet_version.py @@ -1,11 +1,12 @@ import royalnet.version as rv from royalnet.constellation.api import * +import royalnet.utils as ru class ApiRoyalnetVersionStar(ApiStar): path = "/api/royalnet/version/v1" - async def api(self, data: ApiData) -> dict: + async def api(self, data: ApiData) -> ru.JSON: return { "semantic": rv.semantic } diff --git a/royalnet/backpack/stars/api_token_create.py b/royalnet/backpack/stars/api_token_create.py index 5465b468..4c1f6211 100644 --- a/royalnet/backpack/stars/api_token_create.py +++ b/royalnet/backpack/stars/api_token_create.py @@ -3,13 +3,14 @@ import datetime import royalnet.utils as ru from royalnet.constellation.api import * from ..tables.tokens import Token -from sqlalchemy import and_ class ApiTokenCreateStar(ApiStar): path = "/api/token/create/v1" - async def api(self, data: ApiData) -> dict: + methods = ["POST"] + + async def api(self, data: ApiData) -> ru.JSON: user = await data.user() try: duration = int(data["duration"]) diff --git a/royalnet/backpack/stars/api_token_info.py b/royalnet/backpack/stars/api_token_info.py index 3a5e888f..7174df36 100644 --- a/royalnet/backpack/stars/api_token_info.py +++ b/royalnet/backpack/stars/api_token_info.py @@ -1,13 +1,10 @@ -import datetime import royalnet.utils as ru from royalnet.constellation.api import * -from ..tables.users import User -from ..tables.aliases import Alias class ApiTokenInfoStar(ApiStar): path = "/api/token/info/v1" - async def api(self, data: ApiData) -> dict: + async def api(self, data: ApiData) -> ru.JSON: token = await data.token() return token.json() diff --git a/royalnet/backpack/stars/api_token_passwd.py b/royalnet/backpack/stars/api_token_passwd.py index 22a63720..323dd930 100644 --- a/royalnet/backpack/stars/api_token_passwd.py +++ b/royalnet/backpack/stars/api_token_passwd.py @@ -9,7 +9,9 @@ from ..tables.tokens import Token class ApiTokenPasswdStar(ApiStar): path = "/api/token/passwd/v1" - async def api(self, data: ApiData) -> dict: + methods = ["POST"] + + async def api(self, data: ApiData) -> ru.JSON: TokenT = self.alchemy.get(Token) token = await data.token() user = token.user diff --git a/royalnet/constellation/api/apistar.py b/royalnet/constellation/api/apistar.py index 2d9a6c4e..afa58fc2 100644 --- a/royalnet/constellation/api/apistar.py +++ b/royalnet/constellation/api/apistar.py @@ -7,7 +7,7 @@ from ..pagestar import PageStar from .jsonapi import api_error, api_success from .apidata import ApiData from .apierrors import * -from royalnet.utils import sentry_exc +import royalnet.utils as ru class ApiStar(PageStar, ABC): @@ -31,12 +31,12 @@ class ApiStar(PageStar, ABC): except BadRequestError as e: return api_error(e, code=400) except Exception as e: - sentry_exc(e) + ru.sentry_exc(e) return api_error(e, code=500) else: return api_success(response) finally: await apidata.session_close() - async def api(self, data: dict) -> dict: + async def api(self, data: ApiData) -> ru.JSON: raise NotImplementedError() diff --git a/royalnet/utils/__init__.py b/royalnet/utils/__init__.py index deb9539b..88893c75 100644 --- a/royalnet/utils/__init__.py +++ b/royalnet/utils/__init__.py @@ -5,6 +5,7 @@ from .urluuid import to_urluuid, from_urluuid from .multilock import MultiLock from .sentry import init_sentry, sentry_exc from .log import init_logging +from .royaltyping import JSON __all__ = [ "asyncify", @@ -20,4 +21,5 @@ __all__ = [ "init_sentry", "sentry_exc", "init_logging", + "JSON", ] diff --git a/royalnet/utils/royaltyping.py b/royalnet/utils/royaltyping.py new file mode 100644 index 00000000..93eca407 --- /dev/null +++ b/royalnet/utils/royaltyping.py @@ -0,0 +1,3 @@ +from typing import * + +JSON = Union[None, int, str, List["JSON"], Dict[str, "JSON"]] diff --git a/royalnet/version.py b/royalnet/version.py index a65bd8c3..384e124e 100644 --- a/royalnet/version.py +++ b/royalnet/version.py @@ -1 +1 @@ -semantic = "5.5a3" +semantic = "5.5a4"