Swiftpack.co - Apodini/ApodiniTypeInformation as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Apodini.
Apodini/ApodiniTypeInformation 0.3.7
Reflective Runtime TypeInformation framework.
⭐️ 1
🕓 1 year ago
macOS
.package(url: "https://github.com/Apodini/ApodiniTypeInformation.git", from: "0.3.7")

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.

GitHub

link
Stars: 1
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.3.7
1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/Apodini/ApodiniTypeInformation/compare/0.3.6...0.3.7

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics