vcti-viewer-protocol 0.3.0__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.
Files changed (51) hide show
  1. vcti/viewer/protocol/__init__.py +258 -0
  2. vcti/viewer/protocol/array.py +132 -0
  3. vcti/viewer/protocol/base.py +28 -0
  4. vcti/viewer/protocol/bundle/__init__.py +24 -0
  5. vcti/viewer/protocol/bundle/__main__.py +7 -0
  6. vcti/viewer/protocol/bundle/build.py +405 -0
  7. vcti/viewer/protocol/bundle/cli.py +49 -0
  8. vcti/viewer/protocol/bundle/schema.py +87 -0
  9. vcti/viewer/protocol/error.py +27 -0
  10. vcti/viewer/protocol/mock/__init__.py +86 -0
  11. vcti/viewer/protocol/mock/__main__.py +7 -0
  12. vcti/viewer/protocol/mock/actions/__init__.py +3 -0
  13. vcti/viewer/protocol/mock/actions/reports.py +39 -0
  14. vcti/viewer/protocol/mock/actions/sessions.py +88 -0
  15. vcti/viewer/protocol/mock/actions/studies.py +58 -0
  16. vcti/viewer/protocol/mock/api/__init__.py +3 -0
  17. vcti/viewer/protocol/mock/api/v1/__init__.py +3 -0
  18. vcti/viewer/protocol/mock/api/v1/dependencies.py +30 -0
  19. vcti/viewer/protocol/mock/api/v1/endpoints/__init__.py +3 -0
  20. vcti/viewer/protocol/mock/api/v1/endpoints/reports.py +67 -0
  21. vcti/viewer/protocol/mock/api/v1/endpoints/sessions.py +149 -0
  22. vcti/viewer/protocol/mock/api/v1/endpoints/studies.py +108 -0
  23. vcti/viewer/protocol/mock/cli.py +55 -0
  24. vcti/viewer/protocol/mock/main.py +149 -0
  25. vcti/viewer/protocol/mock/services/__init__.py +3 -0
  26. vcti/viewer/protocol/mock/services/catalog.py +313 -0
  27. vcti/viewer/protocol/mock/services/reports.py +819 -0
  28. vcti/viewer/protocol/mock/services/selection.py +179 -0
  29. vcti/viewer/protocol/mock/services/stage/__init__.py +3 -0
  30. vcti/viewer/protocol/mock/services/stage/_stage.py +90 -0
  31. vcti/viewer/protocol/mock/services/stage/arrays.py +121 -0
  32. vcti/viewer/protocol/mock/services/stage/bindings.py +169 -0
  33. vcti/viewer/protocol/mock/services/stage/fingerprint.py +97 -0
  34. vcti/viewer/protocol/mock/services/stage/navigator.py +162 -0
  35. vcti/viewer/protocol/mock/services/stage/projection.py +407 -0
  36. vcti/viewer/protocol/mock/services/stage/served.py +127 -0
  37. vcti/viewer/protocol/model.py +630 -0
  38. vcti/viewer/protocol/navigator.py +94 -0
  39. vcti/viewer/protocol/primitives.py +80 -0
  40. vcti/viewer/protocol/py.typed +0 -0
  41. vcti/viewer/protocol/report.py +66 -0
  42. vcti/viewer/protocol/scene.py +135 -0
  43. vcti/viewer/protocol/session.py +96 -0
  44. vcti/viewer/protocol/step.py +396 -0
  45. vcti/viewer/protocol/study.py +103 -0
  46. vcti_viewer_protocol-0.3.0.dist-info/METADATA +160 -0
  47. vcti_viewer_protocol-0.3.0.dist-info/RECORD +51 -0
  48. vcti_viewer_protocol-0.3.0.dist-info/WHEEL +5 -0
  49. vcti_viewer_protocol-0.3.0.dist-info/entry_points.txt +3 -0
  50. vcti_viewer_protocol-0.3.0.dist-info/licenses/LICENSE +8 -0
  51. vcti_viewer_protocol-0.3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,258 @@
1
+ # Copyright Visual Collaboration Technologies Inc. All Rights Reserved.
2
+ # See LICENSE for details.
3
+ """vcti.viewer.protocol — the viewer's server–client protocol.
4
+
5
+ Pydantic contract models, a transport-neutral message catalog (JSON Schema)
6
+ with its protocol bindings, fixture scenarios, a mock server for client
7
+ testing, and the versioned protocol bundle the TypeScript client is built
8
+ from.
9
+ """
10
+
11
+ from importlib.metadata import version
12
+
13
+ from .array import (
14
+ ELEMENT_SIZES,
15
+ INTEGER_TYPES,
16
+ ArrayData,
17
+ ArrayDescriptor,
18
+ BufferArray,
19
+ ElementType,
20
+ InlineArray,
21
+ )
22
+ from .base import (
23
+ ProtocolModel,
24
+ )
25
+ from .error import (
26
+ ErrorBody,
27
+ )
28
+ from .model import (
29
+ Abscissa,
30
+ Assembly,
31
+ Component,
32
+ Death,
33
+ EdgesGeometry,
34
+ EntitySet,
35
+ Extent,
36
+ Fidelity,
37
+ FieldBinding,
38
+ FieldDefinition,
39
+ FieldFamily,
40
+ Frame,
41
+ FrameGroup,
42
+ GeometryBinding,
43
+ History,
44
+ Material,
45
+ MaterialProperty,
46
+ Membership,
47
+ Mesh,
48
+ MeshSequence,
49
+ ModelKind,
50
+ ModelStructure,
51
+ OutlineGeometry,
52
+ PointsGeometry,
53
+ Representation,
54
+ RepresentationKind,
55
+ Slab,
56
+ SourceAssociation,
57
+ SurfaceGeometry,
58
+ )
59
+ from .navigator import (
60
+ Entry,
61
+ EntryTree,
62
+ Model,
63
+ Navigator,
64
+ StudyModels,
65
+ )
66
+ from .primitives import (
67
+ PRIM_PATH_PATTERN,
68
+ RELATIVE_PATH_PATTERN,
69
+ Attributes,
70
+ AttributeValue,
71
+ EntryPath,
72
+ Matrix4,
73
+ ModelPath,
74
+ NonEmptyStr,
75
+ PrimPath,
76
+ Revision,
77
+ Vector3,
78
+ )
79
+ from .report import (
80
+ CreateReport,
81
+ Report,
82
+ ReportList,
83
+ ReportSummary,
84
+ )
85
+ from .scene import (
86
+ Flag,
87
+ Flags,
88
+ RecordedStep,
89
+ Resolved,
90
+ RowVisibility,
91
+ SceneDocument,
92
+ Visibility,
93
+ VisibilityState,
94
+ )
95
+ from .session import (
96
+ Evaluated,
97
+ EvaluateSelection,
98
+ OpenSession,
99
+ Recorded,
100
+ ReturnToRevision,
101
+ SendSteps,
102
+ Session,
103
+ )
104
+ from .step import (
105
+ IDENTIFIER_PATTERN,
106
+ Action,
107
+ AddSection,
108
+ AddSlide,
109
+ DuplicateSection,
110
+ DuplicateSlide,
111
+ FilterModels,
112
+ FilterParts,
113
+ FindModel,
114
+ FindPart,
115
+ Identifier,
116
+ ItemReference,
117
+ Match,
118
+ MoveSection,
119
+ MoveSlide,
120
+ RemoveSection,
121
+ RemoveSlide,
122
+ RenameSection,
123
+ RenameSlide,
124
+ Rule,
125
+ RuleValue,
126
+ Selection,
127
+ SetVisibility,
128
+ ShowSlide,
129
+ Step,
130
+ StepAdapter,
131
+ Title,
132
+ UpdateSlide,
133
+ Variable,
134
+ )
135
+ from .study import (
136
+ FilesStudy,
137
+ Source,
138
+ Study,
139
+ StudyDefinition,
140
+ StudyDefinitionAdapter,
141
+ StudyList,
142
+ StudySummary,
143
+ )
144
+
145
+ __version__ = version("vcti-viewer-protocol")
146
+
147
+ __all__ = [
148
+ "__version__",
149
+ "ELEMENT_SIZES",
150
+ "IDENTIFIER_PATTERN",
151
+ "INTEGER_TYPES",
152
+ "PRIM_PATH_PATTERN",
153
+ "RELATIVE_PATH_PATTERN",
154
+ "Abscissa",
155
+ "Action",
156
+ "AddSection",
157
+ "AddSlide",
158
+ "ArrayData",
159
+ "ArrayDescriptor",
160
+ "Assembly",
161
+ "AttributeValue",
162
+ "Attributes",
163
+ "BufferArray",
164
+ "Component",
165
+ "CreateReport",
166
+ "Death",
167
+ "DuplicateSection",
168
+ "DuplicateSlide",
169
+ "EdgesGeometry",
170
+ "ElementType",
171
+ "EntitySet",
172
+ "Entry",
173
+ "EntryPath",
174
+ "EntryTree",
175
+ "ErrorBody",
176
+ "EvaluateSelection",
177
+ "Evaluated",
178
+ "Extent",
179
+ "Fidelity",
180
+ "FieldBinding",
181
+ "FieldDefinition",
182
+ "FieldFamily",
183
+ "FilesStudy",
184
+ "FilterModels",
185
+ "FilterParts",
186
+ "FindModel",
187
+ "FindPart",
188
+ "Flag",
189
+ "Flags",
190
+ "Frame",
191
+ "FrameGroup",
192
+ "GeometryBinding",
193
+ "History",
194
+ "Identifier",
195
+ "InlineArray",
196
+ "ItemReference",
197
+ "Match",
198
+ "Material",
199
+ "MaterialProperty",
200
+ "Matrix4",
201
+ "Membership",
202
+ "Mesh",
203
+ "MeshSequence",
204
+ "Model",
205
+ "ModelKind",
206
+ "ModelPath",
207
+ "ModelStructure",
208
+ "MoveSection",
209
+ "MoveSlide",
210
+ "Navigator",
211
+ "NonEmptyStr",
212
+ "OpenSession",
213
+ "OutlineGeometry",
214
+ "PointsGeometry",
215
+ "PrimPath",
216
+ "ProtocolModel",
217
+ "Recorded",
218
+ "RecordedStep",
219
+ "RemoveSection",
220
+ "RemoveSlide",
221
+ "RenameSection",
222
+ "RenameSlide",
223
+ "Report",
224
+ "ReportList",
225
+ "ReportSummary",
226
+ "Representation",
227
+ "RepresentationKind",
228
+ "Resolved",
229
+ "ReturnToRevision",
230
+ "Revision",
231
+ "RowVisibility",
232
+ "Rule",
233
+ "RuleValue",
234
+ "SceneDocument",
235
+ "Selection",
236
+ "SendSteps",
237
+ "Session",
238
+ "SetVisibility",
239
+ "ShowSlide",
240
+ "Slab",
241
+ "Source",
242
+ "SourceAssociation",
243
+ "Step",
244
+ "StepAdapter",
245
+ "Study",
246
+ "StudyDefinition",
247
+ "StudyDefinitionAdapter",
248
+ "StudyList",
249
+ "StudyModels",
250
+ "StudySummary",
251
+ "SurfaceGeometry",
252
+ "Title",
253
+ "UpdateSlide",
254
+ "Variable",
255
+ "Vector3",
256
+ "Visibility",
257
+ "VisibilityState",
258
+ ]
@@ -0,0 +1,132 @@
1
+ # Copyright Visual Collaboration Technologies Inc. All Rights Reserved.
2
+ # See LICENSE for details.
3
+ """Descriptors of the binary buffers that carry bulk data."""
4
+
5
+ from types import MappingProxyType
6
+ from typing import Annotated, Literal, Self
7
+
8
+ from pydantic import Field, model_validator
9
+ from vcti.enum import EnumValueLowerCase, auto_enum_value, setup_enum_for_pydantic
10
+
11
+ from .base import ProtocolModel
12
+ from .primitives import ModelPath
13
+
14
+
15
+ class ElementType(EnumValueLowerCase):
16
+ """The element type of a buffer, as sent to the client."""
17
+
18
+ UINT8 = auto_enum_value()
19
+ UINT16 = auto_enum_value()
20
+ UINT32 = auto_enum_value()
21
+ INT32 = auto_enum_value()
22
+ FLOAT32 = auto_enum_value()
23
+ FLOAT64 = auto_enum_value()
24
+
25
+ @property
26
+ def size(self) -> int:
27
+ """The size of one element in bytes."""
28
+ return ELEMENT_SIZES[self]
29
+
30
+
31
+ ELEMENT_SIZES: MappingProxyType[ElementType, int] = MappingProxyType(
32
+ {
33
+ ElementType.UINT8: 1,
34
+ ElementType.UINT16: 2,
35
+ ElementType.UINT32: 4,
36
+ ElementType.INT32: 4,
37
+ ElementType.FLOAT32: 4,
38
+ ElementType.FLOAT64: 8,
39
+ }
40
+ )
41
+ """The size in bytes of one element of each type."""
42
+
43
+ setup_enum_for_pydantic(ElementType)
44
+
45
+
46
+ class ArrayDescriptor(ProtocolModel):
47
+ """What a client needs to know about an array before fetching its buffer.
48
+
49
+ A buffer holds ``count`` tuples of ``width`` components each,
50
+ little-endian, with the components of a tuple side by side. A buffer
51
+ that extends another names it as ``base``: its effective tuples are the
52
+ base's effective tuples followed by its own, and ``count`` is only the
53
+ tuples it adds.
54
+ """
55
+
56
+ path: ModelPath
57
+ """The array's prim path, by which it is fetched."""
58
+
59
+ element_type: ElementType.FIELD
60
+ """The type of each component, as sent."""
61
+
62
+ width: Annotated[int, Field(ge=1)]
63
+ """The number of components in each tuple."""
64
+
65
+ count: Annotated[int, Field(ge=0)]
66
+ """The number of tuples this buffer holds, not counting its base's."""
67
+
68
+ base: ModelPath | None = None
69
+ """The array this one extends, if any."""
70
+
71
+ @property
72
+ def byte_length(self) -> int:
73
+ """The length of this buffer's bytes, not counting its base's."""
74
+ return self.count * self.width * ELEMENT_SIZES[self.element_type]
75
+
76
+
77
+ INTEGER_TYPES: frozenset[ElementType] = frozenset(
78
+ {ElementType.UINT8, ElementType.UINT16, ElementType.UINT32, ElementType.INT32}
79
+ )
80
+ """The element types whose values are integers."""
81
+
82
+
83
+ class InlineArray(ProtocolModel):
84
+ """A small array carried in the JSON itself.
85
+
86
+ ``values`` holds the tuples flattened, components side by side, so its
87
+ length is a multiple of ``width``.
88
+ """
89
+
90
+ type: Literal["inline"]
91
+ """The variant's tag."""
92
+
93
+ element_type: ElementType.FIELD
94
+ """The type of each component."""
95
+
96
+ width: Annotated[int, Field(ge=1)]
97
+ """The number of components in each tuple."""
98
+
99
+ values: list[int] | list[float]
100
+ """The tuples, flattened."""
101
+
102
+ @model_validator(mode="after")
103
+ def _check_values(self) -> Self:
104
+ if len(self.values) % self.width:
105
+ raise ValueError(
106
+ f"{len(self.values)} values do not make whole tuples of width {self.width}"
107
+ )
108
+ if self.element_type in INTEGER_TYPES and not all(
109
+ isinstance(value, int) for value in self.values
110
+ ):
111
+ raise ValueError(f"an {self.element_type.value} array holds integers only")
112
+ return self
113
+
114
+ @property
115
+ def count(self) -> int:
116
+ """The number of tuples."""
117
+ return len(self.values) // self.width
118
+
119
+
120
+ class BufferArray(ProtocolModel):
121
+ """An array carried in a binary buffer, fetched by its prim path."""
122
+
123
+ type: Literal["buffer"]
124
+ """The variant's tag."""
125
+
126
+ descriptor: ArrayDescriptor
127
+ """The buffer that holds the array."""
128
+
129
+
130
+ ArrayData = Annotated[InlineArray | BufferArray, Field(discriminator="type")]
131
+ """An array sent either inline in the JSON or as a buffer, as the server
132
+ chooses for its size."""
@@ -0,0 +1,28 @@
1
+ # Copyright Visual Collaboration Technologies Inc. All Rights Reserved.
2
+ # See LICENSE for details.
3
+ """The base model every protocol message derives from."""
4
+
5
+ from pydantic import BaseModel, ConfigDict, SerializerFunctionWrapHandler, model_serializer
6
+
7
+
8
+ class ProtocolModel(BaseModel):
9
+ """Base of every protocol model.
10
+
11
+ Sets the rules every message follows: a field the model does not define
12
+ is rejected, so a typo fails validation instead of being ignored, and
13
+ validation is strict, so a value of the wrong type is rejected instead
14
+ of converted. Field names are the models' own snake_case names, in
15
+ Python and on the wire. A field's docstring becomes its description in
16
+ the JSON Schema. A field with no value is left out when the model is
17
+ serialized, never written as null.
18
+ """
19
+
20
+ model_config = ConfigDict(extra="forbid", strict=True, use_attribute_docstrings=True)
21
+
22
+ # The return type is deliberately unannotated: Pydantic builds the
23
+ # serialization schema from it, and any annotation here would replace
24
+ # the model's own schema with that type's.
25
+ @model_serializer(mode="wrap")
26
+ def _omit_none(self, handler: SerializerFunctionWrapHandler): # type: ignore[no-untyped-def]
27
+ """Serialize the model, leaving out every field whose value is None."""
28
+ return {key: value for key, value in handler(self).items() if value is not None}
@@ -0,0 +1,24 @@
1
+ # Copyright Visual Collaboration Technologies Inc. All Rights Reserved.
2
+ # See LICENSE for details.
3
+ """vcti.viewer.protocol.bundle — the protocol bundle the TypeScript client is built from.
4
+
5
+ Builds the npm package ``@vcollab/viewer-protocol-bundle``: the REST
6
+ binding's OpenAPI document, every message as JSON Schema, and the mock
7
+ server's responses for the delivery fixtures, recorded. Run it with
8
+ ``vcti-viewer-bundle``. Needs the ``mock`` extra, since the OpenAPI document
9
+ and the fixtures come from the mock server.
10
+ """
11
+
12
+ from .build import FIXED_TIME, PACKAGE_NAME, BundleError, build_bundle, tarball_name
13
+ from .schema import MESSAGES, SchemaConflictError, message_schema
14
+
15
+ __all__ = [
16
+ "FIXED_TIME",
17
+ "MESSAGES",
18
+ "PACKAGE_NAME",
19
+ "BundleError",
20
+ "SchemaConflictError",
21
+ "build_bundle",
22
+ "message_schema",
23
+ "tarball_name",
24
+ ]
@@ -0,0 +1,7 @@
1
+ # Copyright Visual Collaboration Technologies Inc. All Rights Reserved.
2
+ # See LICENSE for details.
3
+ """``python -m vcti.viewer.protocol.bundle``: build the protocol bundle."""
4
+
5
+ from .cli import main
6
+
7
+ main()