Finaliza ajustes para iniciar Repositorio Git do SDK de Integração do Notion separado do meu projeto original
--- - Cria singleton de `client` com func `configure` para inicializar e `get_instance` para buscar instância do client; - Ajusta clients para buscar headers vindo do pai `client` e fixa versão legacy no client de databases; - Adiciona inicialização de `client` no init do projeto com api_token e api_version informados pelo usuário; - Altera `NotionConfig` para inserir `database_id` no lugar de `database_name`; - Altera sistema para receber `database_id` no lugar de `database_name`; - Altera tipo de `properties` em `schemas.responses.pages.Page` de `Union[Dict[str, Any]], TDB` para `Union[Any, TDB]` para resolver reclamações de type hint; - Adiciona param `generic_response` no init de `client` e nos clients e databases e pages para pular uso de mapping ao usar `.generic`; - Adiciona param `raw_response` para pular parser e mappings e retornar resposta original da api; - Finaliza `types` com subpastas para importações mas com init mãe vazio para evitar dependência circular e permitir uso de `notion.types.` pelo usuário; - Remove importações do projeto original não relacionadas com o SDK; - Adiciona param `timezone` na func `start_date` em `orm.common.SetProperty` que antes vinha do env, para posteriormente puxar da init da integração; - Monta `LICENSE`, `README.md` e `pyproject.toml` base simples para commit inicial do projeto permitindo build de pacote; ---
This commit is contained in:
+93
@@ -0,0 +1,93 @@
|
||||
from typing import Optional, Literal, Generic, TypeVar
|
||||
from pydantic import validate_call
|
||||
from ....schemas.responses import Schemas as _schm
|
||||
from ...mapping.database import NotionDatabase as _NotionDatabase
|
||||
from ...mapping import Mapping as _map
|
||||
from ...parsers import Parser as _parser
|
||||
from ...common.SetProperty import SetProperty as _setProperty
|
||||
from ..pages.CreatePage import CreatePage as _CreatePage
|
||||
|
||||
TDB = TypeVar('TDB', bound = _NotionDatabase)
|
||||
|
||||
class CreateDatabasePage(Generic[TDB]):
|
||||
|
||||
def __init__(self,
|
||||
database_id : str,
|
||||
generic_response : bool = False
|
||||
) -> None:
|
||||
self._database_id = database_id
|
||||
self._generic_response = generic_response
|
||||
self._instance = _CreatePage().set_parent(
|
||||
type = "database_id",
|
||||
parent_id = self._database_id
|
||||
)
|
||||
self.set_property = _setProperty(self, self._instance.data["properties"])
|
||||
|
||||
@validate_call
|
||||
def set_template(self,
|
||||
type : Literal["default", "template_id"],
|
||||
template_id : Optional[str] = None
|
||||
):
|
||||
self._instance.set_template(
|
||||
type = type,
|
||||
template_id = template_id
|
||||
)
|
||||
return self
|
||||
|
||||
@validate_call
|
||||
def set_title(self,
|
||||
prop_name : Optional[str],
|
||||
prop_value : Optional[str]
|
||||
):
|
||||
self._instance.set_title(
|
||||
prop_name = prop_name,
|
||||
prop_value = prop_value
|
||||
)
|
||||
return self
|
||||
|
||||
@validate_call
|
||||
def set_icon(self,
|
||||
type : Literal["external"],
|
||||
content : Optional[str] = None
|
||||
):
|
||||
self._instance.set_icon(
|
||||
type = type,
|
||||
content = content
|
||||
)
|
||||
return self
|
||||
|
||||
@validate_call
|
||||
async def call(self,
|
||||
map_properties : bool = True,
|
||||
raw_response : bool = False
|
||||
) -> _schm.pages.Page[TDB]:
|
||||
|
||||
page = await self._instance.call(
|
||||
parse_properties = False
|
||||
)
|
||||
|
||||
if not raw_response:
|
||||
|
||||
if map_properties:
|
||||
|
||||
parser = None
|
||||
if not self._generic_response:
|
||||
# Tenta pegar parser do registry
|
||||
parser = _map.registry.get_parser(
|
||||
database_id = self._database_id,
|
||||
page_parser = _parser.page_props
|
||||
)
|
||||
|
||||
# Fallback: se database não registrada, usa parser genérico
|
||||
if not parser:
|
||||
parser = _parser.page_props
|
||||
|
||||
page = page.model_dump()
|
||||
mapped_properties = parser(page = page)
|
||||
page["properties"] = mapped_properties
|
||||
|
||||
page = _schm.pages.Page(**page)
|
||||
|
||||
return page
|
||||
|
||||
__all__ = ["CreateDatabasePage"]
|
||||
Reference in New Issue
Block a user