Swiftpack.co -  siemensikkema/Validations as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
siemensikkema/Validations
Validations framework for Swift
.package(url: "https://github.com/siemensikkema/Validations.git", from: "0.1.0")

Validations

A Swift framework designed to make validating Decodable input convenient, type safe, versitile, and efficient.

Most APIs and server-side rendered webpages deal with input from the outside world. Not all input is acceptable; some rules must be followed. And when they aren't we should be able to provide clear feedback on what rules were violated. When there is more than one thing wrong with the input we should report all violations instead of just halting at the first error we encounter.

This framework is inspired from working with Vapors Validations. It is an attempt to address some of its pain points, which include:

  • the use of strings to refer to keys in the payload
  • needing to use clunky workarounds to build validations that involve comparing values within the input
  • as well as for those that require asynchronous operations (eg. looking up an email address in the database to see if it is unique)

Note: this framework is at a very early stage and much of the API is subject to change

Goals

By striving to fulfill the goals below, this framework aims to make writing good validations as painless as possible.

  • minimally repetitive code
  • type safety
  • enable complex validations eg. comparing values within a payload
  • usable in an asynchronous context.
  • a single decoding step
  • i18n ready

Structure

It consists of 3 targets: Decoded, Checked, and Validations. These incrementally provide the full functionality of this framework. But each can of course be used on its own.

Decoded: Capture success and error states from decoding

Decoded provides a layer on top of Swift's Codable that allows for capturing and collecting error states.

Checked: Assert successful decoding and obtain a convenient view into the data

Checked provides convenient access to (a hierarchy of) Decoded values and enables guaranteeing successful decoding.

Validations Describe the conditions under which data is valid with

Validations aims to add a powerful domain specific language (DSL) to express what input we should consider valid.

GitHub

link
Stars: 0
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Basic principles
1 week ago

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