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 cases or a structure’s fields, an attachment’s key and document types. A club’s members do not enter its id. 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: among concepts, clubs, enumerations and structures one name names one type, and registering a second under a name already taken raises, whatever its kind. An attachment’s name is unique over one key concept of its namespace only: it may repeat over another concept, and may be a type’s name.

A name is an ASCII letter, then letters, digits and underscores, and not a word of the definitions’ text form (struct, concept, namespace…); a type’s name is not that of a built-in type (int64, uuid, any…). What a target language reserves is for the code generator to handle.

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 those of definitions.

Return information about added definitions. A type registered under the same name, or an attachment under the same name and key, with another runtime id raises ViperError, and nothing is added: every check runs before the first insertion. A club already registered gains the members it lacked.

extend_concepts(definitions: DefinitionsConst) → ValueSet[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.