Skip to content

Reflective Runtime TypeInformation framework.

Notifications You must be signed in to change notification settings

Apodini/ApodiniTypeInformation

Repository files navigation

ApodiniTypeInformation

Build codecov

This package contains the implementation of a recurisive enum-based TypeInformation:

public enum TypeInformation {
    /// A scalar type
    case scalar(PrimitiveType)
    /// A repeated type (set or array), with `TypeInformation` elements
    indirect case repeated(element: TypeInformation)
    /// A dictionary with primitive keys and `TypeInformation` values
    indirect case dictionary(key: PrimitiveType, value: TypeInformation)
    /// An optional type with `TypeInformation` wrapped values
    indirect case optional(wrappedValue: TypeInformation)
    /// An enum type with `String` cases.
    indirect case `enum`(name: TypeName, rawValueType: TypeInformation?, cases: [EnumCase], context: Context = .init())
    /// An object type with properties containing a `TypeInformation` and a name.
    case object(name: TypeName, properties: [TypeProperty], context: Context = .init())
    /// A reference to a type information instance
    case reference(ReferenceKey)
}

The enum already conforms to Codable and Hashable and provides several other convenience methods that can be found in TypeInformation+Convenience.swift. Currently, it supports the initialization out of an Any type via init(type:) throws and out of any instance init(value:) throws using Runtime for the names of the properties of the objects. Furthermore, a TypeInformation instance can be initialized via static func of<B: TypeInformationBuilder>(_ type: Any.Type, with builderType: B.Type) throws -> TypeInformation where currently the RuntimeBuilder.self is the only one supported, e.g. try TypeInformation.of(User.self, with: RuntimeBuilder.self)

When constructing the TypeInformation out of a type, the created instance recursively contains all the types of the properties. Additionally, a TypesStore can be used to reference a TypeInformation instance via store(_ type: TypeInformation) -> TypeInformation, which returns a .reference if the passed type contains an enum or an object. The same instance can be reconstructed from the same TypesStore via construct(from reference: TypeInformation) -> TypeInformation.

Setup

The ApodiniTypeInformation library uses the Swift Package Manager for dependency management.

Add it to your project's list of dependencies and to the list of dependencies of your target:

dependencies: [
    .package(url: "https://github.com/Apodini/ApodiniTypeInformation.git", from: "X.X.X")
],

targets: [
    .target(
        name: "Your Target",
        dependencies: [
            .product(name: "ApodiniTypeInformation", "ApodiniTypeInformation")
        ]
    )
]

Contributing

Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.

License

This project is licensed under the MIT License. See Licenses for more information.

About

Reflective Runtime TypeInformation framework.

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages