Skip to content

Commit 9aeaede

Browse files
committed
webserver api
1 parent 1ec915d commit 9aeaede

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed

packages/models-library/src/models_library/api_schemas_storage/storage_schemas.py

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88

99
from datetime import datetime
1010
from enum import Enum
11-
12-
# /data-export
11+
from pathlib import Path
1312
from typing import Annotated, Any, Literal, Self, TypeAlias
1413
from uuid import UUID
1514

16-
from models_library.projects import ProjectID
17-
from models_library.users import UserID
1815
from pydantic import (
1916
BaseModel,
2017
ByteSize,
@@ -28,16 +25,23 @@
2825
)
2926
from pydantic.networks import AnyUrl
3027

31-
from ..basic_regex import DATCORE_DATASET_NAME_RE, S3_BUCKET_NAME_RE
28+
from ..basic_regex import (
29+
DATCORE_COLLECTION_NAME_RE,
30+
DATCORE_DATASET_NAME_RE,
31+
DATCORE_FILE_ID_RE,
32+
S3_BUCKET_NAME_RE,
33+
)
3234
from ..basic_types import SHA256Str
3335
from ..generics import ListModel
36+
from ..projects import ProjectID
3437
from ..projects_nodes_io import (
3538
LocationID,
3639
LocationName,
3740
NodeID,
3841
SimcoreS3FileID,
3942
StorageFileID,
4043
)
44+
from ..users import UserID
4145

4246
ETag: TypeAlias = str
4347

@@ -46,6 +50,12 @@
4650
DatCoreDatasetName: TypeAlias = Annotated[
4751
str, StringConstraints(pattern=DATCORE_DATASET_NAME_RE)
4852
]
53+
DatCoreCollectionName: TypeAlias = Annotated[
54+
str, StringConstraints(pattern=DATCORE_COLLECTION_NAME_RE)
55+
]
56+
DatCorePackageName: TypeAlias = Annotated[
57+
str, StringConstraints(pattern=DATCORE_FILE_ID_RE)
58+
]
4959

5060

5161
# /
@@ -263,9 +273,6 @@ class FileMetaDataArray(RootModel[list[FileMetaDataGet]]):
263273
root: list[FileMetaDataGet] = Field(default_factory=list)
264274

265275

266-
# /locations/{location_id}/files/{file_id}
267-
268-
269276
class LinkType(str, Enum):
270277
PRESIGNED = "PRESIGNED"
271278
S3 = "S3"
@@ -370,3 +377,53 @@ def ensure_consistent_entries(self: Self) -> Self:
370377

371378
class SoftCopyBody(BaseModel):
372379
link_id: SimcoreS3FileID
380+
381+
382+
class PathMetaDataGet(BaseModel):
383+
path: Annotated[Path, Field(description="the path to the current path")]
384+
display_path: Annotated[
385+
Path, Field(description="the path to display with UUID replaced")
386+
]
387+
388+
file_meta_data: Annotated[
389+
FileMetaDataGet | None,
390+
Field(description="if filled, this is the file meta data of the s3 object"),
391+
] = None
392+
393+
model_config = ConfigDict(
394+
extra="forbid",
395+
json_schema_extra={
396+
"examples": [
397+
# ls no filter
398+
{
399+
"path": "f8da77a9-24b9-4eab-aee7-1f0608da1e3e",
400+
"display_path": "my amazing project",
401+
},
402+
# ls f8da77a9-24b9-4eab-aee7-1f0608da1e3e
403+
{
404+
"path": "f8da77a9-24b9-4eab-aee7-1f0608da1e3e/2f94f80f-633e-4dfa-a983-226b7babe3d7",
405+
"display_path": "my amazing project/awesome node",
406+
},
407+
# ls f8da77a9-24b9-4eab-aee7-1f0608da1e3e/2f94f80f-633e-4dfa-a983-226b7babe3d7
408+
{
409+
"path": "f8da77a9-24b9-4eab-aee7-1f0608da1e3e/2f94f80f-633e-4dfa-a983-226b7babe3d7/outputs",
410+
"display_path": "my amazing project/awesome node/outputs",
411+
},
412+
# ls f8da77a9-24b9-4eab-aee7-1f0608da1e3e/2f94f80f-633e-4dfa-a983-226b7babe3d7/outputs
413+
{
414+
"path": "f8da77a9-24b9-4eab-aee7-1f0608da1e3e/2f94f80f-633e-4dfa-a983-226b7babe3d7/outputs/output5",
415+
"display_path": "my amazing project/awesome node/outputs/output5",
416+
},
417+
# ls f8da77a9-24b9-4eab-aee7-1f0608da1e3e/2f94f80f-633e-4dfa-a983-226b7babe3d7/outputs/output_5
418+
{
419+
"path": f"f8da77a9-24b9-4eab-aee7-1f0608da1e3e/2f94f80f-633e-4dfa-a983-226b7babe3d7/outputs/output5/{FileMetaDataGet.model_config['json_schema_extra']['examples'][0]['file_name']}", # type: ignore[index, call-overload]
420+
"display_path": f"my amazing project/awesome node/outputs/output5/{FileMetaDataGet.model_config['json_schema_extra']['examples'][0]['file_name']}", # type: ignore[index, call-overload]
421+
"file_meta_data": FileMetaDataGet.model_config["json_schema_extra"][ # type: ignore[index]
422+
"examples"
423+
][
424+
0 # type: ignore[index]
425+
],
426+
},
427+
]
428+
},
429+
)

packages/models-library/src/models_library/api_schemas_webserver/storage.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from pathlib import Path
33
from typing import Any
44

5+
from pydantic import BaseModel
6+
57
from ..api_schemas_rpc_async_jobs.async_jobs import (
68
AsyncJobGet,
79
AsyncJobId,
@@ -11,10 +13,19 @@
1113
from ..api_schemas_storage.data_export_async_jobs import DataExportTaskStartInput
1214
from ..progress_bar import ProgressReport
1315
from ..projects_nodes_io import LocationID
16+
from ..rest_pagination import CursorQueryParameters
1417
from ..users import UserID
1518
from ._base import InputSchema, OutputSchema
1619

1720

21+
class StorageLocationPathParams(BaseModel):
22+
location_id: LocationID
23+
24+
25+
class ListPathsQueryParams(InputSchema, CursorQueryParameters):
26+
file_filter: Path | None = None
27+
28+
1829
class DataExportPost(InputSchema):
1930
paths: list[Path]
2031

packages/models-library/src/models_library/basic_regex.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
""" Regular expressions patterns to build pydantic contrained strings
1+
"""Regular expressions patterns to build pydantic contrained strings
22
3-
- Variants of the patterns with 'Named Groups' captured are suffixed with NG_RE
3+
- Variants of the patterns with 'Named Groups' captured are suffixed with NG_RE
44
5-
SEE tests_basic_regex.py for examples
5+
SEE tests_basic_regex.py for examples
66
"""
77
# TODO: for every pattern we should have a formatter function
88
# NOTE: some sites to manualy check ideas
@@ -56,6 +56,7 @@
5656
# Datcore file ID
5757
DATCORE_FILE_ID_RE = rf"^N:package:{UUID_RE_BASE}$"
5858
DATCORE_DATASET_NAME_RE = rf"^N:dataset:{UUID_RE_BASE}$"
59+
DATCORE_COLLECTION_NAME_RE = rf"^N:collection:{UUID_RE_BASE}$"
5960

6061

6162
TWILIO_ALPHANUMERIC_SENDER_ID_RE = r"(?!^\d+$)^[a-zA-Z0-9\s]{2,11}$"

packages/models-library/src/models_library/rest_pagination.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@
3131
).validate_python(20)
3232

3333

34+
class CursorQueryParameters(RequestParameters):
35+
"""Use as pagination options in query parameters"""
36+
37+
size: PageLimitInt = Field(
38+
default=TypeAdapter(PageLimitInt).validate_python(
39+
DEFAULT_NUMBER_OF_ITEMS_PER_PAGE
40+
),
41+
description="maximum number of items to return (pagination)",
42+
)
43+
cursor: Annotated[
44+
str | None,
45+
Field(
46+
description="unique identifier that represent the position in the dataset"
47+
),
48+
] = None
49+
50+
3451
class PageQueryParameters(RequestParameters):
3552
"""Use as pagination options in query parameters"""
3653

0 commit comments

Comments
 (0)