SpruceKit
SpruceID
  • 🌲SpruceKit Introduction
    • Decentralized Identity Overview
    • Glossary
  • ⚡Quickstart
  • SpruceKit Mobile
    • SpruceKit Showcase App
      • Installation
      • Getting Started
      • Issue a Showcase Credential
      • Present a Showcase Credential
    • SpruceKit Mobile SDK
      • Introduction
      • Core Components
        • StorageManager
        • KeyManager
        • CredentialPack
        • Card
        • IsoMdlPresentation
        • mDocReader/IsomDLReader
        • Document Scanner
      • SpruceKit iOS SDK
        • Installation
        • Build a Wallet
          • Accept a W3C VC
          • Present a W3C VC
          • Present mDL in-person/offline
          • Present an mDL over the internet
        • Build a Verifier
          • Verify a W3C VC
          • Verify an mDL in-person/offline
          • Verify an mDL over the internet
      • SpruceKit Android SDK
        • Installation
        • Build a Wallet
          • Accept a W3C VC
          • Present a W3C VC
          • Present an mDL in-person/offline
          • Present an mDL over the internet
        • Build a Verifier
          • Verify a W3C VC
          • Verify an mDL in-person/offline
          • Verify an mDL over the internet
  • Verifiable Digital Credentials
    • ⚙️DIDKit
      • Installation
      • Core Concepts
      • DID Methods
      • Runtime Configuration
      • Specifications and Dependencies
      • Quickstart
      • DIDKit Packages
        • Command Line Interface
        • HTTP Server
        • Rust Crate
        • C Interface
        • Java and Android
        • Python
        • Javascript
      • DIDKit Examples
        • Core Functions (CLI)
        • Core Functions (HTTP)
        • did-web in minutes
        • Batch Generation & Verification
    • 🪪ISO mDL
      • Quickstart
      • Core Concepts
      • User Guide
  • Schema Definition Language
    • 🔗TreeLDR
      • TreeLDR Quickstart
        • First Schema
        • Compilation into JSON Schema
        • Compilation into JSON-LD Context
        • Writing a Layout
        • Simple Rust Integration
      • Types
        • Literal Types
      • Layouts
        • Primitive Layouts
        • Literal Layouts
        • Enumeration
        • Array Layout
        • References
      • Compiling
        • Schema Definition Formats
          • JSON Schema
          • JSON-LD Context
          • Resource Description Framework (RDF)
        • Programming Languages
          • Compiling to Rust
      • RDF Vocabulary
      • 💡TreeLDR Basics
        • Types and Layouts
        • Properties
        • Syntax
  • Witness for Credential Claims
    • 🔭Rebase
      • Core Library
      • Rust Client/Witness SDK
      • WASM Client SDK
      • Simple "Basic Post" Schema
      • DNS Witness Flow Schema
  • References
    • Contributing
    • Code of Conduct
Powered by GitBook
On this page
  • Definition
  • Type Expression

Was this helpful?

  1. Schema Definition Language
  2. TreeLDR

Types

PreviousSimple Rust IntegrationNextLiteral Types

Last updated 11 months ago

Was this helpful?

The following covers the definition of type and their composition and type expressions.

Definition

There are three different kinds of type definitions in TreeLDR:

Empty Type

The empty type is defined by simply declaring the name of the type directly followed by a semicolon.

// Empty type.
type MyType;

Normal Type

A normal type also declares properties that can be applied to the instances of this type. Properties are listed inside the definition between braces:

// Normal type.
type MyType {
	property1: Type1,
	// ...
	propertyN: TypeN
}

The type of each property is specified after a colon : using a . If a property listed in the definition is declared outside the type definition, it is not required to specify the type of the property again.

Type Alias

Lastly, it is possible to define type aliases. Such a type is defined using a type expression.

type MyType = TypeExpression;

Type Expression

A type expression is a composition of existing types by union, intersection and restriction.

Union

The union between two or more types is expressed using the | operator.

TypeA | ... | TypeN

An instance of this type is also an instance of at least one of the listed sub-types.

Intersection

The intersection between two or more types is expressed using the & operator.

TypeA & ... & TypeN

An instance of this type is also an instance of all the listed sub-types.

Range Restriction

Range restrictions are used to select a subset of a type by restricting the range of one of its properties. There are two kinds of range restrictions: universal and existential.

A universal range restriction is built using the all keyword:

all someProperty: RestrictedType

This denotes the type of all values such that all objects of someProperty are instances of RestrictedType.

Similarly, the existential range restriction is built using the any keyword:

any someProperty: RestrictionType

This denotes the type of all values such that at least one object of someProperty is an instance of RestrictedType.

Range restrictions are usually part of an intersection:

Type & all someProperty: RestrictionType
🔗
type expression