numerous 0.24.0__py3-none-win_arm64.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.

Potentially problematic release.


This version of numerous might be problematic. Click here for more details.

Files changed (57) hide show
  1. numerous/__init__.py +6 -0
  2. numerous/__main__.py +51 -0
  3. numerous/_client/__init__.py +0 -0
  4. numerous/_client/_fs_client.py +257 -0
  5. numerous/_client/_get_client.py +29 -0
  6. numerous/_client/_graphql_client.py +311 -0
  7. numerous/_plotly.py +5 -0
  8. numerous/appdev/__init__.py +1 -0
  9. numerous/appdev/commands.py +208 -0
  10. numerous/apps.py +155 -0
  11. numerous/cli/__init__.py +6 -0
  12. numerous/cli/__main__.py +7 -0
  13. numerous/cli/_color.py +48 -0
  14. numerous/cli/_upgrade.py +116 -0
  15. numerous/cli/bin/cli +0 -0
  16. numerous/cli/run.py +69 -0
  17. numerous/collection/__init__.py +7 -0
  18. numerous/collection/_client.py +48 -0
  19. numerous/collection/collection.py +18 -0
  20. numerous/collection/exceptions.py +9 -0
  21. numerous/collection/numerous_collection.py +112 -0
  22. numerous/collection/numerous_document.py +189 -0
  23. numerous/data_model.py +210 -0
  24. numerous/experimental/__init__.py +8 -0
  25. numerous/experimental/marimo.py +172 -0
  26. numerous/experimental/model.py +372 -0
  27. numerous/generated/graphql/__init__.py +263 -0
  28. numerous/generated/graphql/all_elements.py +128 -0
  29. numerous/generated/graphql/async_base_client.py +372 -0
  30. numerous/generated/graphql/base_model.py +29 -0
  31. numerous/generated/graphql/client.py +541 -0
  32. numerous/generated/graphql/collection_collections.py +55 -0
  33. numerous/generated/graphql/collection_create.py +27 -0
  34. numerous/generated/graphql/collection_document.py +33 -0
  35. numerous/generated/graphql/collection_document_delete.py +31 -0
  36. numerous/generated/graphql/collection_document_set.py +29 -0
  37. numerous/generated/graphql/collection_document_tag_add.py +31 -0
  38. numerous/generated/graphql/collection_document_tag_delete.py +31 -0
  39. numerous/generated/graphql/collection_documents.py +55 -0
  40. numerous/generated/graphql/enums.py +49 -0
  41. numerous/generated/graphql/exceptions.py +85 -0
  42. numerous/generated/graphql/fragments.py +105 -0
  43. numerous/generated/graphql/input_types.py +119 -0
  44. numerous/generated/graphql/update_element.py +29 -0
  45. numerous/generated/graphql/updates.py +160 -0
  46. numerous/jsonbase64.py +23 -0
  47. numerous/py.typed +0 -0
  48. numerous/session.py +489 -0
  49. numerous/threaded_event_loop.py +44 -0
  50. numerous/tools/__init__.py +11 -0
  51. numerous/updates.py +180 -0
  52. numerous/utils.py +12 -0
  53. numerous-0.24.0.dist-info/METADATA +129 -0
  54. numerous-0.24.0.dist-info/RECORD +57 -0
  55. numerous-0.24.0.dist-info/WHEEL +5 -0
  56. numerous-0.24.0.dist-info/entry_points.txt +2 -0
  57. numerous-0.24.0.dist-info/top_level.txt +1 -0
numerous/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """The python SDK for numerous."""
2
+
3
+ __all__ = ("action", "app", "container", "field", "html", "slider", "collection")
4
+
5
+ from .apps import action, app, container, field, html, slider
6
+ from .collection import collection
numerous/__main__.py ADDED
@@ -0,0 +1,51 @@
1
+ """An entrypoint for creating and running app sessions."""
2
+
3
+ import argparse
4
+ import asyncio
5
+ import logging
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ from numerous.appdev.commands import (
10
+ read_app,
11
+ run_app_session,
12
+ )
13
+
14
+
15
+ log = logging.getLogger(__name__)
16
+
17
+
18
+ if __name__ == "__main__":
19
+ parser = argparse.ArgumentParser()
20
+
21
+ shared_parser = argparse.ArgumentParser()
22
+ shared_parser.add_argument("module_path", type=Path)
23
+ shared_parser.add_argument("class_name")
24
+
25
+ cmd_parsers = parser.add_subparsers(title="Command", dest="cmd")
26
+ read_parser = cmd_parsers.add_parser(
27
+ "read",
28
+ parents=[shared_parser],
29
+ add_help=False,
30
+ )
31
+ run_parser = cmd_parsers.add_parser("run", parents=[shared_parser], add_help=False)
32
+ run_parser.add_argument("--graphql-url", required=True)
33
+ run_parser.add_argument("--graphql-ws-url", required=True)
34
+ run_parser.add_argument("session_id")
35
+
36
+ ns = parser.parse_args()
37
+
38
+ if ns.cmd == "read":
39
+ read_app(ns.module_path, ns.class_name)
40
+ elif ns.cmd == "run":
41
+ coroutine = run_app_session(
42
+ ns.graphql_url,
43
+ ns.graphql_ws_url,
44
+ ns.session_id,
45
+ ns.module_path,
46
+ ns.class_name,
47
+ )
48
+ asyncio.run(coroutine)
49
+ else:
50
+ print(f"Unsupported command {ns.cmd!r}") # noqa: T201
51
+ sys.exit(1)
File without changes
@@ -0,0 +1,257 @@
1
+ import json
2
+ from dataclasses import asdict, dataclass
3
+ from pathlib import Path
4
+ from typing import Any, Optional
5
+
6
+ from numerous.generated.graphql.fragments import (
7
+ CollectionDocumentReference,
8
+ CollectionDocumentReferenceTags,
9
+ CollectionReference,
10
+ )
11
+ from numerous.generated.graphql.input_types import TagInput
12
+ from numerous.jsonbase64 import base64_to_dict, dict_to_base64
13
+
14
+
15
+ @dataclass
16
+ class FileSystemCollectionTag:
17
+ key: str
18
+ value: str
19
+
20
+ @staticmethod
21
+ def load(tag: dict[str, Any]) -> "FileSystemCollectionTag":
22
+ key = tag.get("key")
23
+ if not isinstance(key, str):
24
+ tname = type(key).__name__
25
+ msg = f"FileSystemCollectionTag key must be str, found {tname}"
26
+ raise TypeError(msg)
27
+
28
+ value = tag.get("value")
29
+ if not isinstance(value, str):
30
+ tname = type(value).__name__
31
+ msg = f"FileSystemCollectionTag value must be str, found {tname}"
32
+ raise TypeError(msg)
33
+
34
+ return FileSystemCollectionTag(key=key, value=value)
35
+
36
+ def to_reference_tag(self) -> CollectionDocumentReferenceTags:
37
+ return CollectionDocumentReferenceTags(
38
+ key=self.key,
39
+ value=self.value,
40
+ )
41
+
42
+
43
+ @dataclass
44
+ class FileSystemCollectionDocument:
45
+ data: dict[str, Any]
46
+ tags: list[FileSystemCollectionTag]
47
+
48
+ def save(self, path: Path) -> None:
49
+ with path.open("w") as f:
50
+ json.dump(asdict(self), f)
51
+
52
+ @staticmethod
53
+ def load(path: Path) -> "FileSystemCollectionDocument":
54
+ with path.open("r") as f:
55
+ file_content = json.load(f)
56
+
57
+ if not isinstance(file_content, dict):
58
+ tname = type(file_content).__name__
59
+ msg = f"FileSystemCollection document must be a dict, found {tname}"
60
+ raise TypeError(msg)
61
+
62
+ tags = file_content.get("tags", [])
63
+ if not isinstance(tags, list):
64
+ tname = type(tags).__name__
65
+ msg = f"FileSystemCollection tags must be a list, found {tname}"
66
+ raise TypeError(msg)
67
+
68
+ data = file_content.get("data", {})
69
+ if not isinstance(data, dict):
70
+ tname = type(data).__name__
71
+ msg = f"FileSystemCollection data must be a dict, found {tname}"
72
+ raise TypeError(msg)
73
+
74
+ return FileSystemCollectionDocument(
75
+ data=data, tags=[FileSystemCollectionTag.load(tag) for tag in tags]
76
+ )
77
+
78
+ def reference_tags(self) -> list[CollectionDocumentReferenceTags]:
79
+ return [
80
+ CollectionDocumentReferenceTags(
81
+ key=tag.key,
82
+ value=tag.value,
83
+ )
84
+ for tag in self.tags
85
+ ]
86
+
87
+ def tag_matches(self, tag_input: TagInput) -> bool:
88
+ matching_tag = next(
89
+ (
90
+ tag
91
+ for tag in self.tags
92
+ if tag.key == tag_input.key and tag.value == tag_input.value
93
+ ),
94
+ None,
95
+ )
96
+
97
+ return matching_tag is not None
98
+
99
+
100
+ class FileSystemClient:
101
+ def __init__(self, base_path: Path) -> None:
102
+ self._base_path = base_path
103
+ self._base_path.mkdir(exist_ok=True)
104
+
105
+ def get_collection_reference(
106
+ self, collection_key: str, parent_collection_id: Optional[str] = None
107
+ ) -> CollectionReference:
108
+ collection_relpath = (
109
+ Path(parent_collection_id) / collection_key
110
+ if parent_collection_id is not None
111
+ else Path(collection_key)
112
+ )
113
+ collection_id = str(collection_relpath)
114
+ collection_path = self._base_path / collection_relpath
115
+ collection_path.mkdir(parents=True, exist_ok=True)
116
+ return CollectionReference(id=collection_id, key=collection_key)
117
+
118
+ def get_collection_document(
119
+ self, collection_id: str, document_key: str
120
+ ) -> Optional[CollectionDocumentReference]:
121
+ path = self._base_path / collection_id / f"{document_key}.json"
122
+ if not path.exists():
123
+ return None
124
+
125
+ doc = FileSystemCollectionDocument.load(path)
126
+
127
+ doc_id = str(Path(collection_id) / document_key)
128
+ return CollectionDocumentReference(
129
+ id=doc_id,
130
+ key=document_key,
131
+ data=dict_to_base64(doc.data),
132
+ tags=[tag.to_reference_tag() for tag in doc.tags],
133
+ )
134
+
135
+ def set_collection_document(
136
+ self, collection_id: str, document_key: str, encoded_data: str
137
+ ) -> Optional[CollectionDocumentReference]:
138
+ doc_path = self._base_path / collection_id / f"{document_key}.json"
139
+ data = base64_to_dict(encoded_data)
140
+ if doc_path.exists():
141
+ doc = FileSystemCollectionDocument.load(doc_path)
142
+ doc.data = data
143
+ else:
144
+ doc = FileSystemCollectionDocument(data, [])
145
+ doc.save(doc_path)
146
+
147
+ doc_id = str(Path(collection_id) / document_key)
148
+ return CollectionDocumentReference(
149
+ id=doc_id,
150
+ key=document_key,
151
+ data=encoded_data,
152
+ tags=[],
153
+ )
154
+
155
+ def delete_collection_document(
156
+ self, document_id: str
157
+ ) -> Optional[CollectionDocumentReference]:
158
+ doc_path = self._base_path / (document_id + ".json")
159
+ if not doc_path.exists():
160
+ return None
161
+
162
+ doc = FileSystemCollectionDocument.load(doc_path)
163
+
164
+ doc_path.unlink()
165
+
166
+ return CollectionDocumentReference(
167
+ id=document_id,
168
+ key=doc_path.stem,
169
+ data=dict_to_base64(doc.data),
170
+ tags=doc.reference_tags(),
171
+ )
172
+
173
+ def add_collection_document_tag(
174
+ self, document_id: str, tag: TagInput
175
+ ) -> Optional[CollectionDocumentReference]:
176
+ doc_path = self._base_path / (document_id + ".json")
177
+ if not doc_path.exists():
178
+ return None
179
+
180
+ doc = FileSystemCollectionDocument.load(doc_path)
181
+ doc.tags.append(FileSystemCollectionTag(key=tag.key, value=tag.value))
182
+ doc.save(doc_path)
183
+
184
+ return CollectionDocumentReference(
185
+ id=document_id,
186
+ key=doc_path.stem,
187
+ data=dict_to_base64(doc.data),
188
+ tags=doc.reference_tags(),
189
+ )
190
+
191
+ def delete_collection_document_tag(
192
+ self, document_id: str, tag_key: str
193
+ ) -> Optional[CollectionDocumentReference]:
194
+ doc_path = self._base_path / (document_id + ".json")
195
+ if not doc_path.exists():
196
+ return None
197
+
198
+ doc = FileSystemCollectionDocument.load(doc_path)
199
+ doc.tags = [tag for tag in doc.tags if tag.key != tag_key]
200
+ doc.save(doc_path)
201
+
202
+ return CollectionDocumentReference(
203
+ id=document_id,
204
+ key=doc_path.stem,
205
+ data=dict_to_base64(doc.data),
206
+ tags=doc.reference_tags(),
207
+ )
208
+
209
+ def get_collection_documents(
210
+ self,
211
+ collection_key: str,
212
+ end_cursor: str, # noqa: ARG002
213
+ tag_input: Optional[TagInput],
214
+ ) -> tuple[Optional[list[Optional[CollectionDocumentReference]]], bool, str]:
215
+ col_path = self._base_path / collection_key
216
+ if not col_path.exists():
217
+ return [], False, ""
218
+
219
+ documents: list[Optional[CollectionDocumentReference]] = []
220
+ for doc_path in col_path.iterdir():
221
+ if doc_path.suffix != ".json":
222
+ continue
223
+
224
+ doc = FileSystemCollectionDocument.load(doc_path)
225
+
226
+ if tag_input and not doc.tag_matches(tag_input):
227
+ # skips files that do not match tag input, if it is given
228
+ continue
229
+
230
+ doc_id = str(doc_path.relative_to(self._base_path).with_suffix(""))
231
+ documents.append(
232
+ CollectionDocumentReference(
233
+ id=doc_id,
234
+ key=doc_path.stem,
235
+ data=dict_to_base64(doc.data),
236
+ tags=doc.reference_tags(),
237
+ )
238
+ )
239
+
240
+ return documents, False, ""
241
+
242
+ def get_collection_collections(
243
+ self,
244
+ collection_key: str,
245
+ end_cursor: str, # noqa: ARG002
246
+ ) -> tuple[Optional[list[CollectionReference]], bool, str]:
247
+ col_path = self._base_path / collection_key
248
+ if not col_path.exists():
249
+ return [], False, ""
250
+
251
+ collections: list[CollectionReference] = []
252
+ for item in col_path.iterdir():
253
+ if item.is_dir():
254
+ col_id = str(item.relative_to(self._base_path))
255
+ collections.append(CollectionReference(id=col_id, key=item.name))
256
+
257
+ return collections, False, ""
@@ -0,0 +1,29 @@
1
+ import os
2
+ from pathlib import Path
3
+ from typing import Optional
4
+
5
+ from numerous.collection._client import Client
6
+ from numerous.generated.graphql.client import Client as GQLClient
7
+
8
+ from ._fs_client import FileSystemClient
9
+ from ._graphql_client import GraphQLClient
10
+
11
+
12
+ _client: Optional[Client] = None
13
+
14
+
15
+ def get_client() -> Client:
16
+ global _client # noqa: PLW0603
17
+
18
+ if _client is not None:
19
+ return _client
20
+
21
+ url = os.getenv("NUMEROUS_API_URL")
22
+ if url:
23
+ _client = GraphQLClient(GQLClient(url=url))
24
+ else:
25
+ _client = FileSystemClient(
26
+ Path(os.getenv("NUMEROUS_COLLECTIONS_BASE_PATH", "collections"))
27
+ )
28
+
29
+ return _client
@@ -0,0 +1,311 @@
1
+ """GraphQL client wrapper for numerous."""
2
+
3
+ import os
4
+ from typing import Optional, Union
5
+
6
+ from numerous.collection.exceptions import ParentCollectionNotFoundError
7
+ from numerous.generated.graphql.client import Client as GQLClient
8
+ from numerous.generated.graphql.collection_collections import (
9
+ CollectionCollectionsCollectionCreateCollection,
10
+ CollectionCollectionsCollectionCreateCollectionCollectionsEdgesNode,
11
+ )
12
+ from numerous.generated.graphql.collection_document import (
13
+ CollectionDocumentCollectionCreateCollectionDocument,
14
+ CollectionDocumentCollectionCreateCollectionNotFound,
15
+ )
16
+ from numerous.generated.graphql.collection_document_delete import (
17
+ CollectionDocumentDeleteCollectionDocumentDeleteCollectionDocument,
18
+ CollectionDocumentDeleteCollectionDocumentDeleteCollectionDocumentNotFound,
19
+ )
20
+ from numerous.generated.graphql.collection_document_set import (
21
+ CollectionDocumentSetCollectionDocumentSetCollectionDocument,
22
+ CollectionDocumentSetCollectionDocumentSetCollectionNotFound,
23
+ )
24
+ from numerous.generated.graphql.collection_document_tag_add import (
25
+ CollectionDocumentTagAddCollectionDocumentTagAddCollectionDocument,
26
+ CollectionDocumentTagAddCollectionDocumentTagAddCollectionDocumentNotFound,
27
+ )
28
+ from numerous.generated.graphql.collection_document_tag_delete import (
29
+ CollectionDocumentTagDeleteCollectionDocumentTagDeleteCollectionDocument,
30
+ CollectionDocumentTagDeleteCollectionDocumentTagDeleteCollectionDocumentNotFound,
31
+ )
32
+ from numerous.generated.graphql.collection_documents import (
33
+ CollectionDocumentsCollectionCreateCollection,
34
+ CollectionDocumentsCollectionCreateCollectionDocumentsEdgesNode,
35
+ )
36
+ from numerous.generated.graphql.fragments import (
37
+ CollectionDocumentReference,
38
+ CollectionNotFound,
39
+ CollectionReference,
40
+ )
41
+ from numerous.generated.graphql.input_types import TagInput
42
+ from numerous.threaded_event_loop import ThreadedEventLoop
43
+
44
+
45
+ COLLECTED_OBJECTS_NUMBER = 100
46
+
47
+
48
+ class APIURLMissingError(Exception):
49
+ _msg = "NUMEROUS_API_URL environment variable is not set"
50
+
51
+ def __init__(self) -> None:
52
+ super().__init__(self._msg)
53
+
54
+
55
+ class APIAccessTokenMissingError(Exception):
56
+ _msg = "NUMEROUS_API_ACCESS_TOKEN environment variable is not set"
57
+
58
+ def __init__(self) -> None:
59
+ super().__init__(self._msg)
60
+
61
+
62
+ class OrganizationIDMissingError(Exception):
63
+ _msg = "NUMEROUS_ORGANIZATION_ID environment variable is not set"
64
+
65
+ def __init__(self) -> None:
66
+ super().__init__(self._msg)
67
+
68
+
69
+ class GraphQLClient:
70
+ def __init__(self, gql: GQLClient) -> None:
71
+ self._gql = gql
72
+ self._threaded_event_loop = ThreadedEventLoop()
73
+ self._threaded_event_loop.start()
74
+
75
+ organization_id = os.getenv("NUMEROUS_ORGANIZATION_ID")
76
+ if not organization_id:
77
+ raise OrganizationIDMissingError
78
+ self._organization_id = organization_id
79
+
80
+ auth_token = os.getenv("NUMEROUS_API_ACCESS_TOKEN")
81
+ if not auth_token:
82
+ raise APIAccessTokenMissingError
83
+
84
+ self._headers = {"Authorization": f"Bearer {auth_token}"}
85
+
86
+ def _create_collection_ref(
87
+ self,
88
+ collection_response: Union[
89
+ CollectionReference,
90
+ CollectionCollectionsCollectionCreateCollectionCollectionsEdgesNode,
91
+ CollectionNotFound,
92
+ ],
93
+ ) -> CollectionReference:
94
+ if isinstance(collection_response, CollectionNotFound):
95
+ raise ParentCollectionNotFoundError(collection_id=collection_response.id)
96
+
97
+ return CollectionReference(
98
+ id=collection_response.id, key=collection_response.key
99
+ )
100
+
101
+ async def _create_collection(
102
+ self, collection_key: str, parent_collection_id: Optional[str] = None
103
+ ) -> CollectionReference:
104
+ response = await self._gql.collection_create(
105
+ self._organization_id,
106
+ collection_key,
107
+ parent_collection_id,
108
+ headers=self._headers,
109
+ )
110
+ return self._create_collection_ref(response.collection_create)
111
+
112
+ def get_collection_reference(
113
+ self, collection_key: str, parent_collection_id: Optional[str] = None
114
+ ) -> CollectionReference:
115
+ """
116
+ Retrieve a collection by its key and parent key.
117
+
118
+ This method retrieves a collection based on its key and parent key,
119
+ or creates it if it doesn't exist.
120
+ """
121
+ return self._threaded_event_loop.await_coro(
122
+ self._create_collection(collection_key, parent_collection_id)
123
+ )
124
+
125
+ def _create_collection_document_ref(
126
+ self,
127
+ collection_response: Optional[
128
+ Union[
129
+ CollectionDocumentTagDeleteCollectionDocumentTagDeleteCollectionDocument,
130
+ CollectionDocumentTagAddCollectionDocumentTagAddCollectionDocument,
131
+ CollectionDocumentDeleteCollectionDocumentDeleteCollectionDocument,
132
+ CollectionDocumentSetCollectionDocumentSetCollectionDocument,
133
+ CollectionDocumentTagAddCollectionDocumentTagAddCollectionDocumentNotFound,
134
+ CollectionDocumentSetCollectionDocumentSetCollectionNotFound,
135
+ CollectionDocumentDeleteCollectionDocumentDeleteCollectionDocumentNotFound,
136
+ CollectionDocumentCollectionCreateCollectionDocument,
137
+ CollectionDocumentsCollectionCreateCollectionDocumentsEdgesNode,
138
+ CollectionDocumentTagDeleteCollectionDocumentTagDeleteCollectionDocumentNotFound,
139
+ ]
140
+ ],
141
+ ) -> Optional[CollectionDocumentReference]:
142
+ if isinstance(collection_response, CollectionDocumentReference):
143
+ return CollectionDocumentReference(
144
+ id=collection_response.id,
145
+ key=collection_response.key,
146
+ data=collection_response.data,
147
+ tags=collection_response.tags,
148
+ )
149
+ return None
150
+
151
+ async def _get_collection_document(
152
+ self, collection_key: str, document_key: str
153
+ ) -> Optional[CollectionDocumentReference]:
154
+ response = await self._gql.collection_document(
155
+ self._organization_id,
156
+ collection_key,
157
+ document_key,
158
+ headers=self._headers,
159
+ )
160
+ if isinstance(
161
+ response.collection_create,
162
+ CollectionDocumentCollectionCreateCollectionNotFound,
163
+ ):
164
+ return None
165
+ return self._create_collection_document_ref(response.collection_create.document)
166
+
167
+ def get_collection_document(
168
+ self, collection_key: str, document_key: str
169
+ ) -> Optional[CollectionDocumentReference]:
170
+ return self._threaded_event_loop.await_coro(
171
+ self._get_collection_document(collection_key, document_key)
172
+ )
173
+
174
+ async def _set_collection_document(
175
+ self, collection_id: str, document_key: str, document_data: str
176
+ ) -> Optional[CollectionDocumentReference]:
177
+ response = await self._gql.collection_document_set(
178
+ collection_id,
179
+ document_key,
180
+ document_data,
181
+ headers=self._headers,
182
+ )
183
+ return self._create_collection_document_ref(response.collection_document_set)
184
+
185
+ def set_collection_document(
186
+ self, collection_id: str, document_key: str, document_data: str
187
+ ) -> Optional[CollectionDocumentReference]:
188
+ return self._threaded_event_loop.await_coro(
189
+ self._set_collection_document(collection_id, document_key, document_data)
190
+ )
191
+
192
+ async def _delete_collection_document(
193
+ self, document_id: str
194
+ ) -> Optional[CollectionDocumentReference]:
195
+ response = await self._gql.collection_document_delete(
196
+ document_id, headers=self._headers
197
+ )
198
+ return self._create_collection_document_ref(response.collection_document_delete)
199
+
200
+ def delete_collection_document(
201
+ self, document_id: str
202
+ ) -> Optional[CollectionDocumentReference]:
203
+ return self._threaded_event_loop.await_coro(
204
+ self._delete_collection_document(document_id)
205
+ )
206
+
207
+ async def _add_collection_document_tag(
208
+ self, document_id: str, tag: TagInput
209
+ ) -> Optional[CollectionDocumentReference]:
210
+ response = await self._gql.collection_document_tag_add(
211
+ document_id, tag, headers=self._headers
212
+ )
213
+ return self._create_collection_document_ref(
214
+ response.collection_document_tag_add
215
+ )
216
+
217
+ def add_collection_document_tag(
218
+ self, document_id: str, tag: TagInput
219
+ ) -> Optional[CollectionDocumentReference]:
220
+ return self._threaded_event_loop.await_coro(
221
+ self._add_collection_document_tag(document_id, tag)
222
+ )
223
+
224
+ async def _delete_collection_document_tag(
225
+ self, document_id: str, tag_key: str
226
+ ) -> Optional[CollectionDocumentReference]:
227
+ response = await self._gql.collection_document_tag_delete(
228
+ document_id, tag_key, headers=self._headers
229
+ )
230
+ return self._create_collection_document_ref(
231
+ response.collection_document_tag_delete
232
+ )
233
+
234
+ def delete_collection_document_tag(
235
+ self, document_id: str, tag_key: str
236
+ ) -> Optional[CollectionDocumentReference]:
237
+ return self._threaded_event_loop.await_coro(
238
+ self._delete_collection_document_tag(document_id, tag_key)
239
+ )
240
+
241
+ async def _get_collection_documents(
242
+ self,
243
+ collection_key: str,
244
+ end_cursor: str,
245
+ tag_input: Optional[TagInput],
246
+ ) -> tuple[Optional[list[Optional[CollectionDocumentReference]]], bool, str]:
247
+ response = await self._gql.collection_documents(
248
+ self._organization_id,
249
+ collection_key,
250
+ tag_input,
251
+ after=end_cursor,
252
+ first=COLLECTED_OBJECTS_NUMBER,
253
+ headers=self._headers,
254
+ )
255
+
256
+ collection = response.collection_create
257
+ if not isinstance(collection, CollectionDocumentsCollectionCreateCollection):
258
+ return [], False, ""
259
+
260
+ documents = collection.documents
261
+ edges = documents.edges
262
+ page_info = documents.page_info
263
+
264
+ result = [self._create_collection_document_ref(edge.node) for edge in edges]
265
+
266
+ end_cursor = page_info.end_cursor or ""
267
+ has_next_page = page_info.has_next_page
268
+
269
+ return result, has_next_page, end_cursor
270
+
271
+ def get_collection_documents(
272
+ self, collection_key: str, end_cursor: str, tag_input: Optional[TagInput]
273
+ ) -> tuple[Optional[list[Optional[CollectionDocumentReference]]], bool, str]:
274
+ return self._threaded_event_loop.await_coro(
275
+ self._get_collection_documents(collection_key, end_cursor, tag_input)
276
+ )
277
+
278
+ async def _get_collection_collections(
279
+ self, collection_key: str, end_cursor: str
280
+ ) -> tuple[Optional[list[CollectionReference]], bool, str]:
281
+ response = await self._gql.collection_collections(
282
+ self._organization_id,
283
+ collection_key,
284
+ after=end_cursor,
285
+ first=COLLECTED_OBJECTS_NUMBER,
286
+ headers=self._headers,
287
+ )
288
+
289
+ collection = response.collection_create
290
+ if not isinstance(collection, CollectionCollectionsCollectionCreateCollection):
291
+ return [], False, ""
292
+
293
+ collections = collection.collections
294
+ edges = collections.edges
295
+ page_info = collections.page_info
296
+
297
+ result = [
298
+ CollectionReference(id=edge.node.id, key=edge.node.key) for edge in edges
299
+ ]
300
+
301
+ end_cursor = page_info.end_cursor or ""
302
+ has_next_page = page_info.has_next_page
303
+
304
+ return result, has_next_page, end_cursor
305
+
306
+ def get_collection_collections(
307
+ self, collection_key: str, end_cursor: str
308
+ ) -> tuple[Optional[list[CollectionReference]], bool, str]:
309
+ return self._threaded_event_loop.await_coro(
310
+ self._get_collection_collections(collection_key, end_cursor)
311
+ )
numerous/_plotly.py ADDED
@@ -0,0 +1,5 @@
1
+ import plotly.graph_objects as go
2
+
3
+
4
+ def plotly_html(figure: go.Figure) -> str:
5
+ return figure.to_html(include_plotlyjs="cdn", full_html=False) # type: ignore[no-any-return]
@@ -0,0 +1 @@
1
+ """Functionality related to the app development CLI."""