Skip to content

MAP Type System

Steve Melville edited this page Nov 19, 2024 · 7 revisions

MAP Type System Layers

The MAP platform is built around a structured and layered type system that supports self-describing, active holons. Each layer serves a specific purpose and role in the system, from foundational storage types to dynamic, agent-defined extensions.

Layer 1: BaseTypes (a.k.a. Storage Type)

BaseTypes are the foundational, portable types in the MAP system. The BaseType determines how a given value will actually be represented in different programming language environments. (i.e., TypeScript and JSON on the client and Rust on the server-side). The BaseTypes layer includes both scalar types (e.g., MapInteger, MapString) and compound types (e.g., MapBytes). It also includes types defined by the Holochain hdk (e.g., ActionHash, Record). The set of BaseTypes is fixed for any given version of the MAP. Changes or additions to any of these types requires a recompile of the MAP code and an evolution of the persistent data stored using a prior version of the MAP.

Key Characteristics

  1. Scalar Types: Simple, atomic values such as integers, strings, and booleans.
  2. Non-Scalar Types: Includes MapBytes, which is used to represent raw binary data, such as hash digests, commonly used as identifiers in the system.

BaseTypes Enum

#[derive(Clone, PartialEq, Eq, new)]
pub enum BaseType {
    String(MapString),       // Portable string type
    Integer(MapInteger),     // Portable integer type
    Boolean(MapBoolean),     // Portable boolean type
    Bytes(MapBytes),         // Portable binary type (e.g., hash digest)
    Enum(MapEnumValue),      // Portable enum value
}

Layer 2: CoreTypes

Definition

  • CoreTypes build upon BaseTypes to introduce semantically meaningful types required by the MAP core code. Examples, include PropertyName, RelationshipName, HolonId.

Characteristics

  • CoreTypes are defined in terms of BaseTypes to ensure portability and consistency.
  • Examples include identifiers, names, and other semantically enriched types.

Examples

  • PropertyName: Wraps MapString, representing a property name.
  • HolonId: Represents a unique identifier for a Holon.
  • RelationshipName: Wraps MapString, representing the name of a relationship.

CoreTypes are organized into the following groups via the CoreType enum. Numbers in parentheses indicate the current number of core types within that group:

  • DanceType (TBD)
  • EnumVariantType (16)
  • HolonType (24)
  • IndexedType (2)
  • PropertyType (24)
  • RelationshipType (27)
  • ValueType (8)

Layer 3: DescriptorTypes

Definition

  • DescriptorTypes define metadata and constraints for the values of a given type. Each BaseType has a corresponding DescriptorType. For example, IntegerDescriptorType defines the metadata about MapIntegers. This could include min and max allowable values for instances of that type, a human-readable name and description of the type and more.

Characteristics

  • Each BaseType has a corresponding DescriptorType.
  • DescriptorTypes can specify constraints like minimum/maximum values, length restrictions, or other rules.

Examples

  • IntegerDescriptorType: Specifies min/max constraints for MapInteger.
  • StringDescriptorType: Specifies length constraints for MapString.

Layer 4: CoreDescriptorTypes

Definition

  • CoreDescriptorTypes describe the types that the MAP core code depends on. are the reserved DescriptorTypes that the MAP core code depends on.

Characteristics

  • Each BaseType can be associated with one or more CoreDescriptorTypes.
  • CoreDescriptorTypes are critical to the functioning of the MAP and are not customizable by agents.

Example

pub enum CoreStringDescriptorType {
    #[default]
    MapStringType,
    PropertyNameType,
    RelationshipNameType,
    SemanticVersionType,
}

Layer 5: ExtensionDescriptorTypes

Overview

ExtensionDescriptorTypes allow agents (developers) to define custom types dynamically without requiring recompilation of the MAP core. These types provide a flexible way for agents to extend the MAP Type System for their own applications, tailoring it to specific use cases.


Key Characteristics

  1. Agent-Defined:

    • ExtensionDescriptorTypes are created and managed by agents to support application-specific needs.
    • They are not part of the MAP core and operate independently of core system upgrades.
  2. Dynamic:

    • Developers can add new types without recompiling the MAP core or migrating data structures.
  3. Flexibility:

    • These types allow agents to define rich metadata for custom types, including validation rules, relationships, and semantics.
  4. Reserved Names:

    • To avoid conflicts, agents cannot use reserved CoreDescriptorType names when defining their own types.
Clone this wiki locally