notionary 0.3.1__py3-none-any.whl → 0.4.1__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.
- notionary/__init__.py +49 -1
- notionary/blocks/client.py +37 -11
- notionary/blocks/enums.py +0 -6
- notionary/blocks/rich_text/markdown_rich_text_converter.py +49 -15
- notionary/blocks/rich_text/models.py +13 -4
- notionary/blocks/rich_text/name_id_resolver/data_source.py +9 -3
- notionary/blocks/rich_text/name_id_resolver/person.py +6 -2
- notionary/blocks/rich_text/rich_text_markdown_converter.py +10 -3
- notionary/blocks/schemas.py +33 -78
- notionary/comments/client.py +19 -6
- notionary/comments/factory.py +10 -3
- notionary/comments/schemas.py +10 -31
- notionary/comments/service.py +12 -4
- notionary/data_source/http/data_source_instance_client.py +59 -17
- notionary/data_source/properties/schemas.py +156 -115
- notionary/data_source/query/builder.py +67 -18
- notionary/data_source/query/resolver.py +16 -5
- notionary/data_source/query/schema.py +24 -6
- notionary/data_source/query/validator.py +18 -6
- notionary/data_source/schema/registry.py +31 -12
- notionary/data_source/schema/service.py +66 -20
- notionary/data_source/schemas.py +2 -2
- notionary/data_source/service.py +103 -43
- notionary/database/client.py +27 -9
- notionary/database/database_metadata_update_client.py +12 -4
- notionary/database/schemas.py +2 -2
- notionary/database/service.py +14 -9
- notionary/exceptions/__init__.py +20 -4
- notionary/exceptions/api.py +2 -2
- notionary/exceptions/base.py +1 -1
- notionary/exceptions/block_parsing.py +9 -5
- notionary/exceptions/data_source/builder.py +13 -7
- notionary/exceptions/data_source/properties.py +6 -4
- notionary/exceptions/file_upload.py +76 -0
- notionary/exceptions/properties.py +7 -5
- notionary/exceptions/search.py +10 -6
- notionary/file_upload/__init__.py +4 -0
- notionary/file_upload/client.py +128 -210
- notionary/file_upload/config/__init__.py +17 -0
- notionary/file_upload/config/config.py +39 -0
- notionary/file_upload/config/constants.py +16 -0
- notionary/file_upload/file/reader.py +28 -0
- notionary/file_upload/query/__init__.py +7 -0
- notionary/file_upload/query/builder.py +58 -0
- notionary/file_upload/query/models.py +37 -0
- notionary/file_upload/schemas.py +80 -0
- notionary/file_upload/service.py +182 -291
- notionary/file_upload/validation/factory.py +66 -0
- notionary/file_upload/validation/impl/file_name_length.py +25 -0
- notionary/file_upload/validation/models.py +134 -0
- notionary/file_upload/validation/port.py +7 -0
- notionary/file_upload/validation/service.py +17 -0
- notionary/file_upload/validation/validators/__init__.py +11 -0
- notionary/file_upload/validation/validators/file_exists.py +15 -0
- notionary/file_upload/validation/validators/file_extension.py +131 -0
- notionary/file_upload/validation/validators/file_name_length.py +21 -0
- notionary/file_upload/validation/validators/upload_limit.py +31 -0
- notionary/http/client.py +33 -30
- notionary/page/content/__init__.py +9 -0
- notionary/page/content/factory.py +21 -7
- notionary/page/content/markdown/builder.py +85 -23
- notionary/page/content/markdown/nodes/audio.py +8 -4
- notionary/page/content/markdown/nodes/base.py +3 -3
- notionary/page/content/markdown/nodes/bookmark.py +5 -3
- notionary/page/content/markdown/nodes/breadcrumb.py +2 -2
- notionary/page/content/markdown/nodes/bulleted_list.py +5 -3
- notionary/page/content/markdown/nodes/callout.py +2 -2
- notionary/page/content/markdown/nodes/code.py +5 -3
- notionary/page/content/markdown/nodes/columns.py +3 -3
- notionary/page/content/markdown/nodes/container.py +9 -5
- notionary/page/content/markdown/nodes/divider.py +2 -2
- notionary/page/content/markdown/nodes/embed.py +8 -4
- notionary/page/content/markdown/nodes/equation.py +4 -2
- notionary/page/content/markdown/nodes/file.py +8 -4
- notionary/page/content/markdown/nodes/heading.py +2 -2
- notionary/page/content/markdown/nodes/image.py +8 -4
- notionary/page/content/markdown/nodes/mixins/caption.py +5 -3
- notionary/page/content/markdown/nodes/numbered_list.py +5 -3
- notionary/page/content/markdown/nodes/paragraph.py +4 -2
- notionary/page/content/markdown/nodes/pdf.py +8 -4
- notionary/page/content/markdown/nodes/quote.py +2 -2
- notionary/page/content/markdown/nodes/space.py +2 -2
- notionary/page/content/markdown/nodes/table.py +8 -5
- notionary/page/content/markdown/nodes/table_of_contents.py +2 -2
- notionary/page/content/markdown/nodes/todo.py +15 -7
- notionary/page/content/markdown/nodes/toggle.py +2 -2
- notionary/page/content/markdown/nodes/video.py +8 -4
- notionary/page/content/markdown/structured_output/__init__.py +73 -0
- notionary/page/content/markdown/structured_output/models.py +391 -0
- notionary/page/content/markdown/structured_output/service.py +211 -0
- notionary/page/content/parser/context.py +1 -1
- notionary/page/content/parser/factory.py +26 -8
- notionary/page/content/parser/parsers/audio.py +12 -32
- notionary/page/content/parser/parsers/base.py +2 -2
- notionary/page/content/parser/parsers/bookmark.py +2 -2
- notionary/page/content/parser/parsers/breadcrumb.py +2 -2
- notionary/page/content/parser/parsers/bulleted_list.py +19 -6
- notionary/page/content/parser/parsers/callout.py +15 -5
- notionary/page/content/parser/parsers/caption.py +9 -3
- notionary/page/content/parser/parsers/code.py +21 -7
- notionary/page/content/parser/parsers/column.py +8 -4
- notionary/page/content/parser/parsers/column_list.py +19 -7
- notionary/page/content/parser/parsers/divider.py +2 -2
- notionary/page/content/parser/parsers/embed.py +2 -4
- notionary/page/content/parser/parsers/equation.py +8 -4
- notionary/page/content/parser/parsers/file.py +12 -34
- notionary/page/content/parser/parsers/file_like_block.py +109 -0
- notionary/page/content/parser/parsers/heading.py +31 -10
- notionary/page/content/parser/parsers/image.py +12 -34
- notionary/page/content/parser/parsers/numbered_list.py +18 -6
- notionary/page/content/parser/parsers/paragraph.py +3 -1
- notionary/page/content/parser/parsers/pdf.py +12 -34
- notionary/page/content/parser/parsers/quote.py +28 -9
- notionary/page/content/parser/parsers/space.py +2 -2
- notionary/page/content/parser/parsers/table.py +31 -10
- notionary/page/content/parser/parsers/table_of_contents.py +7 -3
- notionary/page/content/parser/parsers/todo.py +15 -5
- notionary/page/content/parser/parsers/toggle.py +15 -5
- notionary/page/content/parser/parsers/video.py +12 -34
- notionary/page/content/parser/post_processing/handlers/rich_text_length.py +8 -2
- notionary/page/content/parser/post_processing/handlers/rich_text_length_truncation.py +8 -2
- notionary/page/content/parser/post_processing/service.py +3 -1
- notionary/page/content/parser/pre_processsing/handlers/column_syntax.py +21 -7
- notionary/page/content/parser/pre_processsing/handlers/indentation.py +11 -4
- notionary/page/content/parser/pre_processsing/handlers/video_syntax.py +13 -6
- notionary/page/content/parser/service.py +4 -1
- notionary/page/content/renderer/context.py +15 -5
- notionary/page/content/renderer/factory.py +12 -6
- notionary/page/content/renderer/post_processing/handlers/numbered_list.py +19 -9
- notionary/page/content/renderer/renderers/audio.py +20 -23
- notionary/page/content/renderer/renderers/base.py +3 -3
- notionary/page/content/renderer/renderers/bookmark.py +3 -1
- notionary/page/content/renderer/renderers/bulleted_list.py +11 -5
- notionary/page/content/renderer/renderers/callout.py +19 -7
- notionary/page/content/renderer/renderers/captioned_block.py +11 -5
- notionary/page/content/renderer/renderers/code.py +6 -2
- notionary/page/content/renderer/renderers/column.py +3 -1
- notionary/page/content/renderer/renderers/column_list.py +3 -1
- notionary/page/content/renderer/renderers/embed.py +3 -1
- notionary/page/content/renderer/renderers/equation.py +3 -1
- notionary/page/content/renderer/renderers/file.py +20 -23
- notionary/page/content/renderer/renderers/file_like_block.py +47 -0
- notionary/page/content/renderer/renderers/heading.py +22 -8
- notionary/page/content/renderer/renderers/image.py +20 -23
- notionary/page/content/renderer/renderers/numbered_list.py +8 -3
- notionary/page/content/renderer/renderers/paragraph.py +12 -4
- notionary/page/content/renderer/renderers/pdf.py +20 -23
- notionary/page/content/renderer/renderers/quote.py +14 -6
- notionary/page/content/renderer/renderers/table.py +15 -5
- notionary/page/content/renderer/renderers/todo.py +16 -6
- notionary/page/content/renderer/renderers/toggle.py +8 -4
- notionary/page/content/renderer/renderers/video.py +20 -23
- notionary/page/content/renderer/service.py +9 -3
- notionary/page/content/service.py +21 -7
- notionary/page/content/syntax/definition/__init__.py +11 -0
- notionary/page/content/syntax/definition/models.py +57 -0
- notionary/page/content/syntax/definition/registry.py +371 -0
- notionary/page/content/syntax/prompts/__init__.py +4 -0
- notionary/page/content/syntax/prompts/models.py +11 -0
- notionary/page/content/syntax/prompts/registry.py +703 -0
- notionary/page/page_metadata_update_client.py +12 -4
- notionary/page/properties/client.py +46 -16
- notionary/page/properties/factory.py +6 -2
- notionary/page/properties/{models.py → schemas.py} +93 -107
- notionary/page/properties/service.py +111 -37
- notionary/page/schemas.py +3 -3
- notionary/page/service.py +21 -7
- notionary/shared/entity/client.py +6 -2
- notionary/shared/entity/dto_parsers.py +4 -37
- notionary/shared/entity/entity_metadata_update_client.py +25 -5
- notionary/shared/entity/schemas.py +6 -6
- notionary/shared/entity/service.py +89 -35
- notionary/shared/models/file.py +36 -6
- notionary/shared/models/icon.py +5 -12
- notionary/user/base.py +6 -2
- notionary/user/bot.py +22 -14
- notionary/user/client.py +3 -1
- notionary/user/person.py +3 -1
- notionary/user/schemas.py +3 -1
- notionary/user/service.py +6 -2
- notionary/utils/decorators.py +13 -9
- notionary/utils/fuzzy.py +6 -2
- notionary/utils/mixins/logging.py +3 -1
- notionary/utils/pagination.py +14 -4
- notionary/workspace/__init__.py +6 -2
- notionary/workspace/query/__init__.py +2 -1
- notionary/workspace/query/service.py +42 -13
- notionary/workspace/service.py +74 -46
- {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/METADATA +1 -1
- notionary-0.4.1.dist-info/RECORD +236 -0
- notionary/file_upload/models.py +0 -69
- notionary/page/blocks/client.py +0 -1
- notionary/page/content/syntax/__init__.py +0 -4
- notionary/page/content/syntax/models.py +0 -66
- notionary/page/content/syntax/registry.py +0 -393
- notionary/page/page_context.py +0 -50
- notionary/shared/models/cover.py +0 -20
- notionary-0.3.1.dist-info/RECORD +0 -211
- /notionary/page/content/syntax/{grammar.py → definition/grammar.py} +0 -0
- {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/WHEEL +0 -0
- {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/licenses/LICENSE +0 -0
notionary/comments/client.py
CHANGED
|
@@ -8,7 +8,10 @@ from notionary.comments.schemas import (
|
|
|
8
8
|
CommentListResponse,
|
|
9
9
|
)
|
|
10
10
|
from notionary.http.client import NotionHttpClient
|
|
11
|
-
from notionary.utils.pagination import
|
|
11
|
+
from notionary.utils.pagination import (
|
|
12
|
+
paginate_notion_api,
|
|
13
|
+
paginate_notion_api_generator,
|
|
14
|
+
)
|
|
12
15
|
|
|
13
16
|
|
|
14
17
|
class CommentClient(NotionHttpClient):
|
|
@@ -21,16 +24,24 @@ class CommentClient(NotionHttpClient):
|
|
|
21
24
|
total_results_limit: int | None = None,
|
|
22
25
|
) -> AsyncGenerator[CommentDto]:
|
|
23
26
|
async for comment in paginate_notion_api_generator(
|
|
24
|
-
self._list_comments_page,
|
|
27
|
+
self._list_comments_page,
|
|
28
|
+
block_id=block_id,
|
|
29
|
+
total_results_limit=total_results_limit,
|
|
25
30
|
):
|
|
26
31
|
yield comment
|
|
27
32
|
|
|
28
|
-
async def get_all_comments(
|
|
33
|
+
async def get_all_comments(
|
|
34
|
+
self, block_id: str, *, total_results_limit: int | None = None
|
|
35
|
+
) -> list[CommentDto]:
|
|
29
36
|
all_comments = await paginate_notion_api(
|
|
30
|
-
self._list_comments_page,
|
|
37
|
+
self._list_comments_page,
|
|
38
|
+
block_id=block_id,
|
|
39
|
+
total_results_limit=total_results_limit,
|
|
31
40
|
)
|
|
32
41
|
|
|
33
|
-
self.logger.debug(
|
|
42
|
+
self.logger.debug(
|
|
43
|
+
"Retrieved %d total comments for block %s", len(all_comments), block_id
|
|
44
|
+
)
|
|
34
45
|
return all_comments
|
|
35
46
|
|
|
36
47
|
async def _list_comments_page(
|
|
@@ -65,7 +76,9 @@ class CommentClient(NotionHttpClient):
|
|
|
65
76
|
rich_text: list[RichText],
|
|
66
77
|
discussion_id: str,
|
|
67
78
|
) -> CommentDto:
|
|
68
|
-
request = CommentCreateRequest.for_discussion(
|
|
79
|
+
request = CommentCreateRequest.for_discussion(
|
|
80
|
+
discussion_id=discussion_id, rich_text=rich_text
|
|
81
|
+
)
|
|
69
82
|
|
|
70
83
|
body = request.model_dump(exclude_unset=True, exclude_none=True)
|
|
71
84
|
|
notionary/comments/factory.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
|
|
3
|
-
from notionary.blocks.rich_text.rich_text_markdown_converter import
|
|
3
|
+
from notionary.blocks.rich_text.rich_text_markdown_converter import (
|
|
4
|
+
RichTextToMarkdownConverter,
|
|
5
|
+
)
|
|
4
6
|
from notionary.comments.models import Comment
|
|
5
7
|
from notionary.comments.schemas import CommentDto
|
|
6
8
|
from notionary.user.base import BaseUser
|
|
@@ -20,7 +22,9 @@ class CommentFactory(LoggingMixin):
|
|
|
20
22
|
self.markdown_converter = markdown_converter or RichTextToMarkdownConverter()
|
|
21
23
|
|
|
22
24
|
async def create_from_dto(self, dto: CommentDto) -> Comment:
|
|
23
|
-
author_name, content = await asyncio.gather(
|
|
25
|
+
author_name, content = await asyncio.gather(
|
|
26
|
+
self._resolve_user_name(dto), self._resolve_content(dto)
|
|
27
|
+
)
|
|
24
28
|
|
|
25
29
|
return Comment(author_name=author_name, content=content)
|
|
26
30
|
|
|
@@ -30,7 +34,10 @@ class CommentFactory(LoggingMixin):
|
|
|
30
34
|
try:
|
|
31
35
|
return await BaseUser.from_id_auto(created_by_id, self.http_client)
|
|
32
36
|
except Exception:
|
|
33
|
-
self.logger.warning(
|
|
37
|
+
self.logger.warning(
|
|
38
|
+
f"Failed to resolve user name for user_id: {created_by_id}",
|
|
39
|
+
exc_info=True,
|
|
40
|
+
)
|
|
34
41
|
|
|
35
42
|
return self.UNKNOWN_AUTHOR
|
|
36
43
|
|
notionary/comments/schemas.py
CHANGED
|
@@ -8,10 +8,6 @@ from pydantic import BaseModel, Field
|
|
|
8
8
|
|
|
9
9
|
from notionary.blocks.rich_text.models import RichText
|
|
10
10
|
|
|
11
|
-
# ---------------------------
|
|
12
|
-
# Comment Parent
|
|
13
|
-
# ---------------------------
|
|
14
|
-
|
|
15
11
|
|
|
16
12
|
class CommentParentType(StrEnum):
|
|
17
13
|
PAGE_ID = "page_id"
|
|
@@ -28,7 +24,7 @@ class BlockCommentParent(BaseModel):
|
|
|
28
24
|
block_id: str
|
|
29
25
|
|
|
30
26
|
|
|
31
|
-
CommentParent = PageCommentParent | BlockCommentParent
|
|
27
|
+
type CommentParent = PageCommentParent | BlockCommentParent
|
|
32
28
|
|
|
33
29
|
|
|
34
30
|
# ---------------------------
|
|
@@ -65,7 +61,9 @@ class CommentAttachmentFileUploadType(StrEnum):
|
|
|
65
61
|
|
|
66
62
|
class CommentAttachmentInput(BaseModel):
|
|
67
63
|
file_upload_id: str
|
|
68
|
-
type: Literal[CommentAttachmentFileUploadType.FILE_UPLOAD] =
|
|
64
|
+
type: Literal[CommentAttachmentFileUploadType.FILE_UPLOAD] = (
|
|
65
|
+
CommentAttachmentFileUploadType.FILE_UPLOAD
|
|
66
|
+
)
|
|
69
67
|
|
|
70
68
|
|
|
71
69
|
# ---------------------------
|
|
@@ -84,7 +82,9 @@ class CustomDisplayName(BaseModel):
|
|
|
84
82
|
|
|
85
83
|
|
|
86
84
|
class IntegrationDisplayName(BaseModel):
|
|
87
|
-
type: Literal[CommentDisplayNameType.INTEGRATION] =
|
|
85
|
+
type: Literal[CommentDisplayNameType.INTEGRATION] = (
|
|
86
|
+
CommentDisplayNameType.INTEGRATION
|
|
87
|
+
)
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
class UserDisplayName(BaseModel):
|
|
@@ -96,7 +96,9 @@ class CustomCommentDisplayName(BaseModel):
|
|
|
96
96
|
custom: CustomDisplayName
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
CommentDisplayNameInput =
|
|
99
|
+
type CommentDisplayNameInput = (
|
|
100
|
+
IntegrationDisplayName | UserDisplayName | CustomCommentDisplayName
|
|
101
|
+
)
|
|
100
102
|
|
|
101
103
|
|
|
102
104
|
class CommentDisplayNameDto(BaseModel):
|
|
@@ -189,8 +191,6 @@ class UserRef(BaseModel):
|
|
|
189
191
|
|
|
190
192
|
|
|
191
193
|
class CommentDto(BaseModel):
|
|
192
|
-
"""Comment object as returned by the API"""
|
|
193
|
-
|
|
194
194
|
object: Literal["comment"] = "comment"
|
|
195
195
|
id: str
|
|
196
196
|
|
|
@@ -217,24 +217,3 @@ class CommentListResponse(BaseModel):
|
|
|
217
217
|
results: list[CommentDto] = Field(default_factory=list)
|
|
218
218
|
next_cursor: str | None = None
|
|
219
219
|
has_more: bool = False
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
# ---------------------------
|
|
223
|
-
# Convenience Builders
|
|
224
|
-
# ---------------------------
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
class CommentDisplayNameBuilder:
|
|
228
|
-
"""Helper class to build display names easily"""
|
|
229
|
-
|
|
230
|
-
@staticmethod
|
|
231
|
-
def integration() -> IntegrationDisplayName:
|
|
232
|
-
return IntegrationDisplayName()
|
|
233
|
-
|
|
234
|
-
@staticmethod
|
|
235
|
-
def user() -> UserDisplayName:
|
|
236
|
-
return UserDisplayName()
|
|
237
|
-
|
|
238
|
-
@staticmethod
|
|
239
|
-
def custom(name: str) -> CustomCommentDisplayName:
|
|
240
|
-
return CustomCommentDisplayName(custom=CustomDisplayName(name=name))
|
notionary/comments/service.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
|
|
3
|
-
from notionary.blocks.rich_text.markdown_rich_text_converter import
|
|
3
|
+
from notionary.blocks.rich_text.markdown_rich_text_converter import (
|
|
4
|
+
MarkdownRichTextConverter,
|
|
5
|
+
)
|
|
4
6
|
from notionary.comments.client import CommentClient
|
|
5
7
|
from notionary.comments.factory import CommentFactory
|
|
6
8
|
from notionary.comments.models import Comment
|
|
@@ -20,15 +22,21 @@ class CommentService:
|
|
|
20
22
|
async def list_all_comments_for_page(self, page_id: str) -> list[Comment]:
|
|
21
23
|
comment_dtos = [dto async for dto in self.client.iter_comments(page_id)]
|
|
22
24
|
|
|
23
|
-
comments = await asyncio.gather(
|
|
25
|
+
comments = await asyncio.gather(
|
|
26
|
+
*(self.factory.create_from_dto(dto) for dto in comment_dtos)
|
|
27
|
+
)
|
|
24
28
|
return comments
|
|
25
29
|
|
|
26
30
|
async def create_comment_on_page(self, page_id: str, text: str) -> Comment:
|
|
27
31
|
rich_text = await self._converter.to_rich_text(text)
|
|
28
|
-
comment_dto = await self.client.create_comment_for_page(
|
|
32
|
+
comment_dto = await self.client.create_comment_for_page(
|
|
33
|
+
rich_text=rich_text, page_id=page_id
|
|
34
|
+
)
|
|
29
35
|
return await self.factory.create_from_dto(comment_dto)
|
|
30
36
|
|
|
31
37
|
async def reply_to_discussion_by_id(self, discussion_id: str, text: str) -> Comment:
|
|
32
38
|
rich_text = await self._converter.to_rich_text(text)
|
|
33
|
-
comment_dto = await self.client.create_comment_for_discussion(
|
|
39
|
+
comment_dto = await self.client.create_comment_for_discussion(
|
|
40
|
+
rich_text=rich_text, discussion_id=discussion_id
|
|
41
|
+
)
|
|
34
42
|
return await self.factory.create_from_dto(comment_dto)
|
|
@@ -3,14 +3,25 @@ from __future__ import annotations
|
|
|
3
3
|
from collections.abc import AsyncIterator
|
|
4
4
|
from typing import TYPE_CHECKING, Any, override
|
|
5
5
|
|
|
6
|
-
from notionary.blocks.rich_text.rich_text_markdown_converter import
|
|
6
|
+
from notionary.blocks.rich_text.rich_text_markdown_converter import (
|
|
7
|
+
RichTextToMarkdownConverter,
|
|
8
|
+
)
|
|
7
9
|
from notionary.data_source.query.schema import DataSourceQueryParams
|
|
8
|
-
from notionary.data_source.schemas import
|
|
10
|
+
from notionary.data_source.schemas import (
|
|
11
|
+
DataSourceDto,
|
|
12
|
+
QueryDataSourceResponse,
|
|
13
|
+
UpdateDataSourceDto,
|
|
14
|
+
)
|
|
9
15
|
from notionary.http.client import NotionHttpClient
|
|
10
16
|
from notionary.page.schemas import NotionPageDto
|
|
11
|
-
from notionary.shared.entity.entity_metadata_update_client import
|
|
17
|
+
from notionary.shared.entity.entity_metadata_update_client import (
|
|
18
|
+
EntityMetadataUpdateClient,
|
|
19
|
+
)
|
|
12
20
|
from notionary.shared.typings import JsonDict
|
|
13
|
-
from notionary.utils.pagination import
|
|
21
|
+
from notionary.utils.pagination import (
|
|
22
|
+
paginate_notion_api,
|
|
23
|
+
paginate_notion_api_generator,
|
|
24
|
+
)
|
|
14
25
|
|
|
15
26
|
if TYPE_CHECKING:
|
|
16
27
|
from notionary import NotionPage
|
|
@@ -22,9 +33,15 @@ class DataSourceInstanceClient(NotionHttpClient, EntityMetadataUpdateClient):
|
|
|
22
33
|
self._data_source_id = data_source_id
|
|
23
34
|
|
|
24
35
|
@override
|
|
25
|
-
async def patch_metadata(
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
async def patch_metadata(
|
|
37
|
+
self, update_data_source_dto: UpdateDataSourceDto
|
|
38
|
+
) -> DataSourceDto:
|
|
39
|
+
update_data_source_dto_dict = update_data_source_dto.model_dump(
|
|
40
|
+
exclude_none=True
|
|
41
|
+
)
|
|
42
|
+
response = await self.patch(
|
|
43
|
+
f"data_sources/{self._data_source_id}", data=update_data_source_dto_dict
|
|
44
|
+
)
|
|
28
45
|
return DataSourceDto.model_validate(response)
|
|
29
46
|
|
|
30
47
|
async def update_title(self, title: str) -> DataSourceDto:
|
|
@@ -40,28 +57,38 @@ class DataSourceInstanceClient(NotionHttpClient, EntityMetadataUpdateClient):
|
|
|
40
57
|
await self.patch_metadata(update_data_source_dto)
|
|
41
58
|
|
|
42
59
|
async def update_description(self, description: str) -> str:
|
|
43
|
-
from notionary.blocks.rich_text.markdown_rich_text_converter import
|
|
60
|
+
from notionary.blocks.rich_text.markdown_rich_text_converter import (
|
|
61
|
+
MarkdownRichTextConverter,
|
|
62
|
+
)
|
|
44
63
|
|
|
45
64
|
markdown_rich_text_converter = MarkdownRichTextConverter()
|
|
46
|
-
rich_text_description = await markdown_rich_text_converter.to_rich_text(
|
|
65
|
+
rich_text_description = await markdown_rich_text_converter.to_rich_text(
|
|
66
|
+
description
|
|
67
|
+
)
|
|
47
68
|
update_data_source_dto = UpdateDataSourceDto(description=rich_text_description)
|
|
48
69
|
|
|
49
70
|
updated_data_source_dto = await self.patch_metadata(update_data_source_dto)
|
|
50
71
|
|
|
51
72
|
markdown_rich_text_converter = RichTextToMarkdownConverter()
|
|
52
73
|
updated_markdown_description = (
|
|
53
|
-
await markdown_rich_text_converter.to_markdown(
|
|
74
|
+
await markdown_rich_text_converter.to_markdown(
|
|
75
|
+
updated_data_source_dto.description
|
|
76
|
+
)
|
|
54
77
|
if updated_data_source_dto.description
|
|
55
78
|
else None
|
|
56
79
|
)
|
|
57
80
|
return updated_markdown_description
|
|
58
81
|
|
|
59
|
-
async def query(
|
|
82
|
+
async def query(
|
|
83
|
+
self, query_params: DataSourceQueryParams | None = None
|
|
84
|
+
) -> QueryDataSourceResponse:
|
|
60
85
|
query_params_dict = query_params.to_api_params() if query_params else {}
|
|
61
86
|
total_result_limit = query_params.total_results_limit if query_params else None
|
|
62
87
|
|
|
63
88
|
all_results = await paginate_notion_api(
|
|
64
|
-
self._make_query_request,
|
|
89
|
+
self._make_query_request,
|
|
90
|
+
query_data=query_params_dict or {},
|
|
91
|
+
total_result_limit=total_result_limit,
|
|
65
92
|
)
|
|
66
93
|
|
|
67
94
|
return QueryDataSourceResponse(
|
|
@@ -70,17 +97,24 @@ class DataSourceInstanceClient(NotionHttpClient, EntityMetadataUpdateClient):
|
|
|
70
97
|
has_more=False,
|
|
71
98
|
)
|
|
72
99
|
|
|
73
|
-
async def query_stream(
|
|
100
|
+
async def query_stream(
|
|
101
|
+
self, query_params: DataSourceQueryParams | None = None
|
|
102
|
+
) -> AsyncIterator[Any]:
|
|
74
103
|
query_params_dict = query_params.model_dump() if query_params else {}
|
|
75
104
|
total_result_limit = query_params.total_results_limit if query_params else None
|
|
76
105
|
|
|
77
106
|
async for result in paginate_notion_api_generator(
|
|
78
|
-
self._make_query_request,
|
|
107
|
+
self._make_query_request,
|
|
108
|
+
query_data=query_params_dict or {},
|
|
109
|
+
total_results_limit=total_result_limit,
|
|
79
110
|
):
|
|
80
111
|
yield result
|
|
81
112
|
|
|
82
113
|
async def _make_query_request(
|
|
83
|
-
self,
|
|
114
|
+
self,
|
|
115
|
+
query_data: JsonDict,
|
|
116
|
+
start_cursor: str | None = None,
|
|
117
|
+
page_size: int | None = None,
|
|
84
118
|
) -> QueryDataSourceResponse:
|
|
85
119
|
current_query_data = query_data.copy()
|
|
86
120
|
if start_cursor:
|
|
@@ -88,13 +122,21 @@ class DataSourceInstanceClient(NotionHttpClient, EntityMetadataUpdateClient):
|
|
|
88
122
|
if page_size:
|
|
89
123
|
current_query_data["page_size"] = page_size
|
|
90
124
|
|
|
91
|
-
response = await self.post(
|
|
125
|
+
response = await self.post(
|
|
126
|
+
f"data_sources/{self._data_source_id}/query", data=current_query_data
|
|
127
|
+
)
|
|
92
128
|
return QueryDataSourceResponse.model_validate(response)
|
|
93
129
|
|
|
94
130
|
async def create_blank_page(self, title: str | None = None) -> NotionPage:
|
|
95
131
|
from notionary import NotionPage
|
|
96
132
|
|
|
97
|
-
data = {
|
|
133
|
+
data = {
|
|
134
|
+
"parent": {
|
|
135
|
+
"type": "data_source_id",
|
|
136
|
+
"data_source_id": self._data_source_id,
|
|
137
|
+
},
|
|
138
|
+
"properties": {},
|
|
139
|
+
}
|
|
98
140
|
|
|
99
141
|
if title:
|
|
100
142
|
data["properties"]["Name"] = {"title": [{"text": {"content": title}}]}
|