nrp_cmd.types
Types used inside the nrp client.
1"""Types used inside the nrp client.""" 2 3from .base import Model 4from .info import ( 5 ModelInfo, 6 ModelInfoContentType, 7 ModelInfoLinks, 8 RepositoryInfo, 9 RepositoryInfoLinks, 10) 11from .records import ( 12 FilesEnabled, 13 ParentRecord, 14 Record, 15 RecordId, 16 RecordLinks, 17 RecordList, 18) 19 20__all__ = ( 21 "Model", "RepositoryInfo", "RepositoryInfoLinks", "ModelInfo", "ModelInfoContentType", "ModelInfoLinks", 22 "Record", "RecordLinks", "FilesEnabled", "ParentRecord", "RecordList", "RecordId" 23)
16class Model: 17 """Base model, which allows getting extra fields via normal dot operator.""" 18 19 _extra_data: dict[str, Any] 20 21 def __getattr__(self, item: str) -> Any: # noqa: ANN401 22 """Get extra fields from the model_extra attribute.""" 23 if "_extra_data" not in self.__dict__: 24 self._extra_data: dict[str, Any] = {} 25 26 if item in self._extra_data: 27 return self._extra_data[item] 28 dash_item = item.replace("_", "-") 29 if dash_item in self._extra_data: 30 return self._extra_data[dash_item] 31 32 raise AttributeError(f"{self.__class__.__name__} has no attribute {item}")
Base model, which allows getting extra fields via normal dot operator.
118@extend_serialization(allow_extra_data=True) 119@define(kw_only=True) 120class RepositoryInfo(Model): 121 """Extra info downloaded from nrp-compatible invenio repository.""" 122 schema: str 123 """Version of this configuration schema""" 124 125 name: str 126 """The name of the repository""" 127 128 description: str 129 """The description of the repository""" 130 131 version: str 132 """The version of the repository""" 133 134 invenio_version: str 135 """The version of invenio the repository is based on""" 136 137 links: RepositoryInfoLinks 138 """Links to the repository""" 139 140 transfers: list[str] = field(factory=list) 141 """List of supported file transfer protocols""" 142 143 models: dict[str, ModelInfo] = field(factory=dict) 144 """Information about the models in the repository""" 145 146 default_model: str | None = field(default=None) 147 """The default model for the repository. 148 If set, it is used whenever the model is not specified."""
Extra info downloaded from nrp-compatible invenio repository.
2def __init__(self, *, schema, name, description, version, invenio_version, links, transfers=NOTHING, models=NOTHING, default_model=attr_dict['default_model'].default): 3 self.schema = schema 4 self.name = name 5 self.description = description 6 self.version = version 7 self.invenio_version = invenio_version 8 self.links = links 9 if transfers is not NOTHING: 10 self.transfers = transfers 11 else: 12 self.transfers = __attr_factory_transfers() 13 if models is not NOTHING: 14 self.models = models 15 else: 16 self.models = __attr_factory_models() 17 self.default_model = default_model
Method generated by attrs for class RepositoryInfo.
20@extend_serialization(Rename("self", "self_"), allow_extra_data=True) 21@define(kw_only=True) 22class RepositoryInfoLinks(Model): 23 """Links within the repository info endpoint.""" 24 25 self_: URL 26 """Link to the repository itself""" 27 28 records: URL 29 """Link to the global search endpoint""" 30 31 drafts: URL 32 """Link to the user's records""" 33 34 models: Optional[URL] 35 """Link to the models in the repository""" 36 37 requests: URL 38 """Link to the requests in the repository"""
Links within the repository info endpoint.
2def __init__(self, *, self_, records, drafts, models, requests): 3 self.self_ = self_ 4 self.records = records 5 self.drafts = drafts 6 self.models = models 7 self.requests = requests
Method generated by attrs for class RepositoryInfoLinks.
86@extend_serialization(allow_extra_data=True) 87@define(kw_only=True) 88class ModelInfo(Model): 89 """Information about metadata model within invenio server.""" 90 type: str 91 """The type of the model""" 92 93 schema: str 94 """The json schema of the model""" 95 96 name: str 97 """The name of the model""" 98 99 description: str 100 """The description of the model""" 101 102 version: str 103 """The version of the model""" 104 105 features: list[str] 106 """List of features supported by the model""" 107 108 links: ModelInfoLinks 109 """Links to the model""" 110 111 content_types: list[ModelInfoContentType] = field(factory=list) 112 """List of supported content-types for API serialization""" 113 114 metadata: bool = field(default=True) 115 """Whether the model contains metadata inside the metadata element."""
Information about metadata model within invenio server.
2def __init__(self, *, type, schema, name, description, version, features, links, content_types=NOTHING, metadata=attr_dict['metadata'].default): 3 self.type = type 4 self.schema = schema 5 self.name = name 6 self.description = description 7 self.version = version 8 self.features = features 9 self.links = links 10 if content_types is not NOTHING: 11 self.content_types = content_types 12 else: 13 self.content_types = __attr_factory_content_types() 14 self.metadata = metadata
Method generated by attrs for class ModelInfo.
62@extend_serialization(allow_extra_data=True) 63@define(kw_only=True) 64class ModelInfoContentType(Model): 65 """Acceptable content-types for the model.""" 66 67 content_type: str 68 """The content-type accepted by the model""" 69 70 name: str | None = None 71 """The name of the content-type""" 72 73 description: str | None = None 74 """The description of the content-type""" 75 76 schema: URL | None = None 77 """Machine parseable schema for the content-type""" 78 79 can_export: bool = False 80 """Whether the content-type can be used for exporting records (via Accept header)""" 81 82 can_deposit: bool = False 83 """Whether the content-type can be used for importing records (via Content-Type header)"""
Acceptable content-types for the model.
2def __init__(self, *, content_type, name=attr_dict['name'].default, description=attr_dict['description'].default, schema=attr_dict['schema'].default, can_export=attr_dict['can_export'].default, can_deposit=attr_dict['can_deposit'].default): 3 self.content_type = content_type 4 self.name = name 5 self.description = description 6 self.schema = schema 7 self.can_export = can_export 8 self.can_deposit = can_deposit
Method generated by attrs for class ModelInfoContentType.
41@extend_serialization(allow_extra_data=True) 42@define(kw_only=True) 43class ModelInfoLinks(Model): 44 """Links within the model info endpoint.""" 45 46 records: URL 47 """Link to the published records""" 48 49 html: URL | None = field(default=None) 50 """Link to the model records' HTML listing page""" 51 52 drafts: Optional[URL] = field(default=None) 53 """Link to the user's draft records""" 54 55 deposit: Optional[URL] = field(default=None) 56 """Deposition link for the model""" 57 58 model: URL | None = field(default=None) 59 """Link to the model definition"""
Links within the model info endpoint.
2def __init__(self, *, records, html=attr_dict['html'].default, drafts=attr_dict['drafts'].default, deposit=attr_dict['deposit'].default, model=attr_dict['model'].default): 3 self.records = records 4 self.html = html 5 self.drafts = drafts 6 self.deposit = deposit 7 self.model = model
Method generated by attrs for class ModelInfoLinks.
55@extend_serialization(Rename("files", "files_"), 56 Omit("_etag", from_unstructure=True), 57 allow_extra_data=True) 58@define(kw_only=True) 59class Record(BaseRecord): 60 """Record in the repository.""" 61 62 links: RecordLinks = field() 63 """Links of the record.""" 64 65 files_: Optional[FilesEnabled] = None 66 """Files enabled marker.""" 67 68 parent: Optional[ParentRecord] = None 69 70 @property 71 def metadata(self) -> dict: 72 """Return the metadata of the record.""" 73 if 'metadata' in self._extra_data: 74 return self._extra_data['metadata'] 75 return self._extra_data
Record in the repository.
2def __init__(self, *, id, created, updated, revision_id=attr_dict['revision_id'].default, links, files_=attr_dict['files_'].default, parent=attr_dict['parent'].default): 3 self._etag = attr_dict['_etag'].default 4 self.id = id 5 self.created = created 6 self.updated = updated 7 self.revision_id = revision_id 8 self.links = links 9 self.files_ = files_ 10 self.parent = parent
Method generated by attrs for class Record.
28@define(kw_only=True) 29class RecordLinks(RESTObjectLinks): 30 """Links of a record.""" 31 32 # TODO: add rest of the links here so that code editors can autocomplete 33 pass
Links of a record.
36@define(kw_only=True) 37class FilesEnabled(Model): 38 """Files enabled marker.""" 39 40 enabled: bool
Files enabled marker.
43@define(kw_only=True) 44class ParentRecord(Model): 45 """Parent record of the record.""" 46 47 communities: dict[str, str] 48 """Communities of the record.""" 49 50 workflow: str 51 """Workflow of the record."""
Parent record of the record.
78@extend_serialization(Omit("_etag", from_unstructure=True), allow_extra_data=True) 79@define(kw_only=True) 80class RecordList(RESTList[Record]): 81 """List of records.""" 82 83 sortBy: Optional[str] = None 84 """Sort by field.""" 85 aggregations: Optional[Any] = None 86 """Aggregations."""
List of records.
2def __init__(self, *, links, hits, sortBy=attr_dict['sortBy'].default, aggregations=attr_dict['aggregations'].default): 3 self._etag = attr_dict['_etag'].default 4 self.links = links 5 self.hits = hits 6 self.sortBy = sortBy 7 self.aggregations = aggregations
Method generated by attrs for class RecordList.