Definitions

class dsviper.Definitions

Bases: object

Registers concepts, clubs, enums, structs and attachments.

Each type gets a runtime_id computed from what it is, so the same declaration yields the same id in any Definitions, and a database keeps its documents under those ids. What goes into the computation differs by kind:

  • a primitive: its name.

  • a container, tuple, optional, map, variant or key: its kind and its element types. vector<string> is the same id in two models that share nothing, and a different one from set<string>. Nothing named enters it, so the shape alone identifies the type.

  • a concept, club, enumeration, structure or attachment: the namespace UUID and the name, together with what defines it - a concept’s parent, an enumeration’s or a structure’s fields, an attachment’s key and document types. Adding a field moves the id; renaming the namespace does not, the UUID being what is hashed. The kind does not enter it, and need not: one name names one type, and registering a second under a name already taken raises, whatever its kind.

A name is an identifier - a letter, then letters, digits and underscores - and not a keyword of C++, Python or TypeScript.

const() → DefinitionsConst

Return the read-only interface of these definitions.

It is a LIVE view, not a snapshot: a type created here afterwards shows through it. A DefinitionsConst read back from a store is a snapshot instead - same class, opposite liveness.

create_attachment(namespace: NameSpace, name: str, key_type: _AbstractionTypes, document_type: Type, *, documentation: str | None = None) → Attachment

Create an attachment in namespace and return it.

It is named name, keyed by key_type and holds a document of document_type. documentation is kept on the attachment and read back with documentation().

create_club(namespace: NameSpace, name: str, *, documentation: str | None = None) → TypeClub

Create a club named name in namespace, and return it.

documentation is kept on the club and read back with documentation().

create_concept(namespace: NameSpace, name: str, *, documentation: str | None = None, parent: TypeConcept | None = None) → TypeConcept

Create a concept named name in namespace, and return it.

parent makes it a specialisation of another concept; documentation is kept on the concept and read back with documentation().

create_enumeration(namespace: NameSpace, enumeration_descriptor: TypeEnumerationDescriptor) → TypeEnumeration

Create the enum enumeration_descriptor describes, in namespace, and return it.

create_membership(type_club: TypeClub, type_concept: TypeConcept) → None

Enrol type_concept into type_club.

create_structure(namespace: NameSpace, structure_descriptor: TypeStructureDescriptor) → TypeStructure

Create the struct structure_descriptor describes, in namespace, and return it.

static decode(blob: ValueBlob, *, stream_codec_instancing: StreamCodecInstancing | None = None) → Definitions

Return a Definitions by decoding the blob with Codec.STREAM_TOKEN_BINARY if not specified.

extend(definitions: DefinitionsConst) → DefinitionsExtendInfo

Extend the registered types with the types of definitions and return information about added definitions.

extend_concepts(definitions: DefinitionsConst) → set[ValueUUId]

Extend the registered concepts with the concepts of definitions, and return the set of uuid added.

static read(stream_reading: StreamReading) → Definitions

Read and return a Definitions.