dokuments 2.0.0__tar.gz → 3.1.0__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.
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: dokuments
3
- Version: 2.0.0
3
+ Version: 3.1.0
4
4
  Summary: The python client for dokuments, the arkitekt document service
5
5
  Author-email: jhnnsrs <jhnnsrs@gmail.com>
6
6
  Requires-Python: >=3.11
7
7
  Requires-Dist: aiohttp<4,>=3.9.5
8
- Requires-Dist: arkitekt-spec>=3.19.1
8
+ Requires-Dist: arkitekt-spec>=5.0
9
9
  Requires-Dist: fakts>=6.1
10
10
  Requires-Dist: koil>=1.0.0
11
11
  Requires-Dist: mikro>=9.0.0
@@ -71,7 +71,7 @@ from dokuments import dokuments_service
71
71
  with easy("my-script", dokuments_service) as dokuments:
72
72
  file = dokuments.from_file_like(file="scan.pdf") # a path, a Path or a binary file object
73
73
  document = dokuments.create_document(title="My scan", file=file.id)
74
- print(document.id, file.store.presigned_url)
74
+ print(document.id, file.store.download()) # the bytes, through a scoped read grant
75
75
  ```
76
76
 
77
77
  Uploads go straight to the datalayer: the client asks the server for upload
@@ -56,7 +56,7 @@ from dokuments import dokuments_service
56
56
  with easy("my-script", dokuments_service) as dokuments:
57
57
  file = dokuments.from_file_like(file="scan.pdf") # a path, a Path or a binary file object
58
58
  document = dokuments.create_document(title="My scan", file=file.id)
59
- print(document.id, file.store.presigned_url)
59
+ print(document.id, file.store.download()) # the bytes, through a scoped read grant
60
60
  ```
61
61
 
62
62
  Uploads go straight to the datalayer: the client asks the server for upload
@@ -69,7 +69,7 @@
69
69
  ]
70
70
  },
71
71
  "additional_config": {},
72
- "directive_class_vars": [],
72
+ "class_fields": [],
73
73
  "force_plugin_order": true,
74
74
  "omitted_document_rules": [],
75
75
  "parsers": [],
@@ -89,6 +89,18 @@
89
89
  {
90
90
  "type": "turms.plugins.client.ClientPlugin",
91
91
  "client_class": "DokumentsApi",
92
+ "client_fields": [
93
+ {
94
+ "name": "__scopes__",
95
+ "kind": "tuple[str, ...]",
96
+ "collector": {
97
+ "type": "root_field_directive",
98
+ "directive": "auth",
99
+ "argument": "required_scopes"
100
+ },
101
+ "combine": "union"
102
+ }
103
+ ],
92
104
  "reserved_from": [
93
105
  "dokuments.dokuments.Dokuments"
94
106
  ],
@@ -94,14 +94,13 @@ input FromFileLike {
94
94
 
95
95
  """Temporary S3 credentials for reading a media object."""
96
96
  type GeneralMediaAccessGrant {
97
- path: String!
98
- store: String
99
97
  status: String!
100
98
  accessKey: String!
101
99
  secretKey: String!
102
100
  sessionToken: String!
103
101
  region: String!
104
102
  bucket: String!
103
+ prefix: String!
105
104
  expiresIn: Int!
106
105
  }
107
106
 
@@ -163,28 +162,33 @@ type Mutation {
163
162
  """
164
163
  Request temporary S3 credentials to upload one file (a document, or a page's image).
165
164
  """
166
- requestMediaUpload(input: RequestMediaUploadInput!): MediaUploadGrant! @auth(any_role_of: ["admin", "editor", "bot"])
165
+ requestMediaUpload(input: RequestMediaUploadInput!): MediaUploadGrant! @auth(required_scopes: ["dokuments_write"], any_role_of: ["dokuments_editor"])
167
166
 
168
167
  """Finalize an upload after the client has written the object."""
169
- finishMediaUpload(input: FinishMediaUploadInput!): MediaStore! @auth(any_role_of: ["admin", "editor", "bot"])
168
+ finishMediaUpload(input: FinishMediaUploadInput!): MediaStore! @auth(required_scopes: ["dokuments_write"], any_role_of: ["dokuments_editor"])
169
+
170
+ """
171
+ Reissue upload credentials for a media upload still in flight, to the same key, so a write that outlives its credentials carries on. Only the uploader may, never for a finished store, and never past the upload's time limit
172
+ """
173
+ refreshMediaUpload(input: RefreshUploadInput!): MediaUploadGrant! @auth(required_scopes: ["dokuments_write"], any_role_of: ["dokuments_editor"])
170
174
 
171
175
  """Request temporary S3 read credentials for an uploaded file."""
172
- requestMediaAccess(input: RequestMediaAccessInput!): MediaAccessGrant!
176
+ requestMediaAccess(input: RequestMediaAccessInput!): MediaAccessGrant! @auth(required_scopes: ["dokuments_read"])
173
177
 
174
178
  """Request temporary S3 read credentials for the organization's files."""
175
- requestGeneralMediaAccess(input: RequestGeneralMediaAccessInput!): GeneralMediaAccessGrant!
179
+ requestGeneralMediaAccess(input: RequestGeneralMediaAccessInput!): GeneralMediaAccessGrant! @auth(required_scopes: ["dokuments_read"])
176
180
 
177
181
  """Create a file from file-like data"""
178
- fromFileLike(input: FromFileLike!): File!
182
+ fromFileLike(input: FromFileLike!): File! @auth(required_scopes: ["dokuments_write"], any_role_of: ["dokuments_editor"])
179
183
 
180
184
  """Delete an existing file"""
181
- deleteFile(input: DeleteFileInput!): ID!
185
+ deleteFile(input: DeleteFileInput!): ID! @auth(required_scopes: ["dokuments_write"], any_role_of: ["dokuments_editor"])
182
186
 
183
187
  """Create a new document"""
184
- createDocument(input: CreateDocumentInput!): Document!
188
+ createDocument(input: CreateDocumentInput!): Document! @auth(required_scopes: ["dokuments_write"], any_role_of: ["dokuments_editor"])
185
189
 
186
190
  """Create a new page in a document"""
187
- createPage(input: CreatePageInput!): Page!
191
+ createPage(input: CreatePageInput!): Page! @auth(required_scopes: ["dokuments_write"], any_role_of: ["dokuments_editor"])
188
192
  }
189
193
 
190
194
  type OCRPageResult {
@@ -242,21 +246,25 @@ input PageFilter {
242
246
  type Query {
243
247
  _entities(representations: [_Any!]!): [_Entity]!
244
248
  _service: _Service!
245
- files(filters: FileFilter, pagination: OffsetPaginationInput): [File!]!
246
- documents(filters: DocumentFilter, pagination: OffsetPaginationInput): [Document!]!
247
- pages(filters: PageFilter, pagination: OffsetPaginationInput): [Page!]!
249
+ files(filters: FileFilter, pagination: OffsetPaginationInput): [File!]! @auth(required_scopes: ["dokuments_read"])
250
+ documents(filters: DocumentFilter, pagination: OffsetPaginationInput): [Document!]! @auth(required_scopes: ["dokuments_read"])
251
+ pages(filters: PageFilter, pagination: OffsetPaginationInput): [Page!]! @auth(required_scopes: ["dokuments_read"])
248
252
  file(
249
253
  """The unique identifier of an object"""
250
254
  id: ID!
251
- ): File!
255
+ ): File! @auth(required_scopes: ["dokuments_read"])
252
256
  document(
253
257
  """The unique identifier of an object"""
254
258
  id: ID!
255
- ): Document!
259
+ ): Document! @auth(required_scopes: ["dokuments_read"])
256
260
  page(
257
261
  """The unique identifier of an object"""
258
262
  id: ID!
259
- ): Page!
263
+ ): Page! @auth(required_scopes: ["dokuments_read"])
264
+ }
265
+
266
+ input RefreshUploadInput {
267
+ storeId: String!
260
268
  }
261
269
 
262
270
  input RequestGeneralMediaAccessInput {
@@ -269,7 +277,7 @@ input RequestMediaAccessInput {
269
277
 
270
278
  input RequestMediaUploadInput {
271
279
  originalFileName: String!
272
- fileSize: ByteCount = null
280
+ fileSize: ByteCount!
273
281
  contentType: String = null
274
282
  }
275
283
 
@@ -295,7 +303,7 @@ input StrFilterLookup {
295
303
 
296
304
  type Subscription {
297
305
  """Subscribe to real-time file updates"""
298
- files(dataset: ID = null): FileEvent!
306
+ files(dataset: ID = null): FileEvent! @auth(required_scopes: ["dokuments_read"])
299
307
  }
300
308
 
301
309
  scalar _Any
@@ -4,7 +4,7 @@ from dokuments.traits import HasDownloadAccessor
4
4
  from enum import Enum
5
5
  from pydantic import AliasChoices, BaseModel, ConfigDict, Field
6
6
  from rath.scalars import ID, IDCoercible
7
- from typing import Annotated, AsyncIterator, Iterable, Iterator, Literal
7
+ from typing import Annotated, AsyncIterator, ClassVar, Iterable, Iterator, Literal
8
8
 
9
9
 
10
10
  class GraphQLDefault:
@@ -110,6 +110,18 @@ class OCRTextLineInput(BaseModel):
110
110
  )
111
111
 
112
112
 
113
+ class RefreshUploadInput(BaseModel):
114
+ """No documentation"""
115
+
116
+ store_id: str = Field(
117
+ validation_alias=AliasChoices("store_id", "storeId"),
118
+ serialization_alias="storeId",
119
+ )
120
+ model_config = ConfigDict(
121
+ frozen=True, extra="forbid", populate_by_name=True, use_enum_values=True
122
+ )
123
+
124
+
113
125
  class RequestMediaAccessInput(BaseModel):
114
126
  """No documentation"""
115
127
 
@@ -129,10 +141,9 @@ class RequestMediaUploadInput(BaseModel):
129
141
  validation_alias=AliasChoices("original_file_name", "originalFileName"),
130
142
  serialization_alias="originalFileName",
131
143
  )
132
- file_size: int | None = Field(
144
+ file_size: int = Field(
133
145
  validation_alias=AliasChoices("file_size", "fileSize"),
134
146
  serialization_alias="fileSize",
135
- default=None,
136
147
  )
137
148
  content_type: str | None = Field(
138
149
  validation_alias=AliasChoices("content_type", "contentType"),
@@ -357,6 +368,25 @@ class RequestMediaAccessMutation(BaseModel):
357
368
  document = "fragment MediaAccessGrant on MediaAccessGrant {\n accessKey\n secretKey\n sessionToken\n path\n key\n bucket\n region\n expiresIn\n store\n __typename\n}\n\nmutation RequestMediaAccess($input: RequestMediaAccessInput!) {\n requestMediaAccess(input: $input) {\n ...MediaAccessGrant\n __typename\n }\n}"
358
369
 
359
370
 
371
+ class RefreshMediaUploadMutation(BaseModel):
372
+ """Reissues credentials for an upload still in flight, to the same key: a write that outlives its
373
+ credentials asks for this before they expire and carries on. Only the uploader may.
374
+ """
375
+
376
+ refresh_media_upload: MediaUploadGrant = Field(alias="refreshMediaUpload")
377
+ "Reissue upload credentials for a media upload still in flight, to the same key, so a write that outlives its credentials carries on. Only the uploader may, never for a finished store, and never past the upload's time limit"
378
+
379
+ class Arguments(BaseModel):
380
+ """Arguments for RefreshMediaUpload"""
381
+
382
+ input: RefreshUploadInput
383
+
384
+ class Meta:
385
+ """Meta class for RefreshMediaUpload"""
386
+
387
+ document = "fragment MediaUploadGrant on MediaUploadGrant {\n accessKey\n secretKey\n sessionToken\n path\n key\n bucket\n region\n expiresIn\n maxBytes\n store\n __typename\n}\n\nmutation RefreshMediaUpload($input: RefreshUploadInput!) {\n refreshMediaUpload(input: $input) {\n ...MediaUploadGrant\n __typename\n }\n}"
388
+
389
+
360
390
  class CreatePageMutation(BaseModel):
361
391
  """No documentation found for this operation."""
362
392
 
@@ -451,6 +481,8 @@ class DokumentsApi:
451
481
  Each method hands its operation to ``execute``, ``aexecute``, ``subscribe``, ``asubscribe`` of ``self``, which the class this one is mixed into (or a base of it) provides.
452
482
  """
453
483
 
484
+ __scopes__: ClassVar[tuple[str, ...]] = ("dokuments_read", "dokuments_write")
485
+
454
486
  async def acreate_document(
455
487
  self, title: str, file: IDCoercible | None | UnsetType = UNSET
456
488
  ) -> Document:
@@ -554,7 +586,7 @@ class DokumentsApi:
554
586
  async def arequest_media_upload(
555
587
  self,
556
588
  original_file_name: str,
557
- file_size: int | None | UnsetType = UNSET,
589
+ file_size: int,
558
590
  content_type: str | None | UnsetType = UNSET,
559
591
  ) -> MediaUploadGrant:
560
592
  """RequestMediaUpload
@@ -563,7 +595,7 @@ class DokumentsApi:
563
595
 
564
596
  Args:
565
597
  original_file_name: The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. (required)
566
- file_size: A number of bytes. 64-bit, unlike Int: serialized as a JSON number, and accepted as a number or a numeric string.
598
+ file_size: A number of bytes. 64-bit, unlike Int: serialized as a JSON number, and accepted as a number or a numeric string. (required)
567
599
  content_type: The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
568
600
 
569
601
  Returns:
@@ -572,8 +604,7 @@ class DokumentsApi:
572
604
  variables: dict[str, builtins.object] = {}
573
605
  _input: dict[str, builtins.object] = {}
574
606
  _input["originalFileName"] = original_file_name
575
- if file_size is not UNSET:
576
- _input["fileSize"] = file_size
607
+ _input["fileSize"] = file_size
577
608
  if content_type is not UNSET:
578
609
  _input["contentType"] = content_type
579
610
  variables["input"] = _input
@@ -584,7 +615,7 @@ class DokumentsApi:
584
615
  def request_media_upload(
585
616
  self,
586
617
  original_file_name: str,
587
- file_size: int | None | UnsetType = UNSET,
618
+ file_size: int,
588
619
  content_type: str | None | UnsetType = UNSET,
589
620
  ) -> MediaUploadGrant:
590
621
  """RequestMediaUpload
@@ -593,7 +624,7 @@ class DokumentsApi:
593
624
 
594
625
  Args:
595
626
  original_file_name: The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. (required)
596
- file_size: A number of bytes. 64-bit, unlike Int: serialized as a JSON number, and accepted as a number or a numeric string.
627
+ file_size: A number of bytes. 64-bit, unlike Int: serialized as a JSON number, and accepted as a number or a numeric string. (required)
597
628
  content_type: The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
598
629
 
599
630
  Returns:
@@ -602,8 +633,7 @@ class DokumentsApi:
602
633
  variables: dict[str, builtins.object] = {}
603
634
  _input: dict[str, builtins.object] = {}
604
635
  _input["originalFileName"] = original_file_name
605
- if file_size is not UNSET:
606
- _input["fileSize"] = file_size
636
+ _input["fileSize"] = file_size
607
637
  if content_type is not UNSET:
608
638
  _input["contentType"] = content_type
609
639
  variables["input"] = _input
@@ -685,6 +715,42 @@ class DokumentsApi:
685
715
  variables["input"] = _input
686
716
  return self.execute(RequestMediaAccessMutation, variables).request_media_access
687
717
 
718
+ async def arefresh_media_upload(self, store_id: str) -> MediaUploadGrant:
719
+ """RefreshMediaUpload
720
+ Reissues credentials for an upload still in flight, to the same key: a write that outlives its
721
+ credentials asks for this before they expire and carries on. Only the uploader may.
722
+
723
+ Args:
724
+ store_id: The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. (required)
725
+
726
+ Returns:
727
+ MediaUploadGrant
728
+ """
729
+ variables: dict[str, builtins.object] = {}
730
+ _input: dict[str, builtins.object] = {}
731
+ _input["storeId"] = store_id
732
+ variables["input"] = _input
733
+ return (
734
+ await self.aexecute(RefreshMediaUploadMutation, variables)
735
+ ).refresh_media_upload
736
+
737
+ def refresh_media_upload(self, store_id: str) -> MediaUploadGrant:
738
+ """RefreshMediaUpload
739
+ Reissues credentials for an upload still in flight, to the same key: a write that outlives its
740
+ credentials asks for this before they expire and carries on. Only the uploader may.
741
+
742
+ Args:
743
+ store_id: The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. (required)
744
+
745
+ Returns:
746
+ MediaUploadGrant
747
+ """
748
+ variables: dict[str, builtins.object] = {}
749
+ _input: dict[str, builtins.object] = {}
750
+ _input["storeId"] = store_id
751
+ variables["input"] = _input
752
+ return self.execute(RefreshMediaUploadMutation, variables).refresh_media_upload
753
+
688
754
  async def acreate_page(
689
755
  self,
690
756
  image: FileLike,
@@ -1,5 +1,5 @@
1
1
  import asyncio
2
- import os
2
+ import io
3
3
 
4
4
 
5
5
  from dokuments.scalars import FileLike
@@ -53,12 +53,19 @@ async def apply_recursive(
53
53
  return obj # type: ignore
54
54
 
55
55
 
56
- def _size_of(file: FileLike) -> int | None:
57
- """The file's size, when it can be learned without reading it: what the grant is budgeted for."""
58
- try:
59
- return os.fstat(file.value.fileno()).st_size
60
- except (AttributeError, OSError, ValueError):
61
- return None
56
+ def _size_of(file: FileLike) -> int:
57
+ """How many bytes the upload will send: the size the grant declares, and is then held to.
58
+
59
+ A file object is measured from where it stands to its end -- that is what gets read --
60
+ and left where it was; raw bytes by their length.
61
+ """
62
+ value = file.value
63
+ if isinstance(value, (bytes, bytearray, memoryview)):
64
+ return len(value)
65
+ position = value.tell()
66
+ end = value.seek(0, io.SEEK_END)
67
+ value.seek(position)
68
+ return end - position
62
69
 
63
70
 
64
71
  class UploadLink(ParsingLink):
@@ -27,4 +27,4 @@ class HasDownloadAccessor(ContextBound, BaseModel):
27
27
  if not isinstance(client, Dokuments):
28
28
  raise ValueError("This store was not fetched through a Dokuments client, so there is none to ask for a read grant.")
29
29
  store_id, key = get_attributes_or_error(self, "id", "key")
30
- return download_file(client, store_id, file_name or key)
30
+ return download_file(client, store_id, file_name or key.rsplit("/", 1)[-1])
@@ -12,8 +12,9 @@ dependencies = [
12
12
  "mikro>=9.0.0",
13
13
  "rath>=4.1.1",
14
14
  "websockets>=15.0.1",
15
- # The service and structures are declared with arkitekt-spec, its aliases resolved by fakts.
16
- "arkitekt-spec>=3.19.1",
15
+ # The service and structures are declared with arkitekt-spec, its aliases resolved by fakts
16
+ # (4.1: a service's scopes).
17
+ "arkitekt-spec>=5.0",
17
18
  "fakts>=6.1",
18
19
  ]
19
20
 
@@ -27,7 +28,7 @@ dev-dependencies = [
27
28
  "pytest-cov>=5.0.0,<6",
28
29
  "python-semantic-release>=9.21.1",
29
30
  "ruff>0.11",
30
- "turms>=2.3.0",
31
+ "turms>=3.0",
31
32
  "basedpyright>=1.21",
32
33
  ]
33
34
 
File without changes
File without changes
File without changes